// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using Core.Common.TestUtil;
using Core.Components.Gis.Features;
using NUnit.Framework;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Forms.TestUtil;
using Ringtoets.Integration.Forms.Factories;
using Riskeer.AssemblyTool.Data;
using Riskeer.AssemblyTool.KernelWrapper.Calculators;
using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators;
using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly;
using Riskeer.Integration.Data.StandAlone;
namespace Ringtoets.Integration.Forms.Test.Factories
{
[TestFixture]
public class MicrostabilityAssemblyMapDataFeaturesFactoryTest
{
[Test]
public void CreateSimpleAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MicrostabilityAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(null);
// Assert
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("failureMechanism", paramName);
}
[Test]
public void CreateSimpleAssemblyFeatures_WithValidData_ReturnsFeaturesCollection()
{
// Setup
var random = new Random(39);
var failureMechanism = new MicrostabilityFailureMechanism();
FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10));
using (new AssemblyToolCalculatorFactoryConfig())
{
var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
calculator.SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(random.NextDouble(),
random.NextEnumValue());
// Call
IEnumerable features = MicrostabilityAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(failureMechanism);
// Assert
MapFeaturesTestHelper.AssertAssemblyCategoryGroupMapFeatures(calculator.SimpleAssessmentAssemblyOutput.Group, failureMechanism, features);
}
}
[Test]
public void CreateDetailedAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MicrostabilityAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(null);
// Assert
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("failureMechanism", paramName);
}
[Test]
public void CreateDetailedAssemblyFeatures_WithValidData_ReturnsFeaturesCollection()
{
// Setup
var random = new Random(39);
var failureMechanism = new MicrostabilityFailureMechanism();
FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10));
using (new AssemblyToolCalculatorFactoryConfig())
{
var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
calculator.DetailedAssessmentAssemblyGroupOutput = random.NextEnumValue();
// Call
IEnumerable features = MicrostabilityAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(failureMechanism);
// Assert
MapFeaturesTestHelper.AssertAssemblyCategoryGroupMapFeatures(calculator.DetailedAssessmentAssemblyGroupOutput.Value, failureMechanism, features);
}
}
[Test]
public void CreateTailorMadeAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MicrostabilityAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(null);
// Assert
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("failureMechanism", paramName);
}
[Test]
public void CreateTailorMadeAssemblyFeatures_WithValidData_ReturnsFeaturesCollection()
{
// Setup
var random = new Random(39);
var failureMechanism = new MicrostabilityFailureMechanism();
FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10));
using (new AssemblyToolCalculatorFactoryConfig())
{
var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
calculator.TailorMadeAssemblyCategoryOutput = random.NextEnumValue();
// Call
IEnumerable features = MicrostabilityAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(failureMechanism);
// Assert
MapFeaturesTestHelper.AssertAssemblyCategoryGroupMapFeatures(calculator.TailorMadeAssemblyCategoryOutput.Value, failureMechanism, features);
}
}
[Test]
public void CreateCombinedAssemblyFeatures_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => MicrostabilityAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(null);
// Assert
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("failureMechanism", paramName);
}
[Test]
public void CreateCombinedAssemblyFeatures_WithValidData_ReturnsFeaturesCollection()
{
// Setup
var random = new Random(39);
var failureMechanism = new MicrostabilityFailureMechanism();
FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(0, 10));
using (new AssemblyToolCalculatorFactoryConfig())
{
var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
calculator.CombinedAssemblyCategoryOutput = random.NextEnumValue();
// Call
IEnumerable features = MicrostabilityAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(failureMechanism);
// Assert
MapFeaturesTestHelper.AssertAssemblyCategoryGroupMapFeatures(calculator.CombinedAssemblyCategoryOutput.Value, failureMechanism, features);
}
}
}
}