Index: Ringtoets.sln
===================================================================
diff -u -r36c991661009852eb8eed4aeb118ffc8b1c2a1f9 -ra56e082357533e893e2a2c49d99e2a92eea956d1
--- Ringtoets.sln (.../Ringtoets.sln) (revision 36c991661009852eb8eed4aeb118ffc8b1c2a1f9)
+++ Ringtoets.sln (.../Ringtoets.sln) (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -1775,7 +1775,7 @@
{C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC}
EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.AssemblyTool.KernelWrapper.Test", "Ringtoets\AssemblyTool\test\Ringtoets.AssemblyTool.KernelWrapper.Test\Riskeer.AssemblyTool.KernelWrapper.Test.csproj", "{41A89DD5-0F97-4B9F-9C17-7960600C2738}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.AssemblyTool.KernelWrapper.Test", "Ringtoets\AssemblyTool\test\Riskeer.AssemblyTool.KernelWrapper.Test\Riskeer.AssemblyTool.KernelWrapper.Test.csproj", "{41A89DD5-0F97-4B9F-9C17-7960600C2738}"
ProjectSection(ProjectDependencies) = postProject
{C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC}
EndProjectSection
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorExceptionTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorExceptionTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorExceptionTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorExceptionTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCalculatorInputCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssemblyErrorMessageCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismAssemblyCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCalculatorInputCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionListCreatorTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Kernels/AssemblyToolKernelFactoryTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Properties/AssemblyInfo.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Riskeer.AssemblyTool.KernelWrapper.Test.csproj'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag a56e082357533e893e2a2c49d99e2a92eea956d1 refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/packages.config'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorExceptionTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorExceptionTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,32 @@
+// 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 Core.Common.TestUtil;
+using NUnit.Framework;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class AssessmentSectionAssemblyCalculatorExceptionTest :
+ CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/AssessmentSectionAssemblyCalculatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,817 @@
+// 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.ComponentModel;
+using System.Linq;
+using Assembly.Kernel.Exceptions;
+using Assembly.Kernel.Model;
+using Assembly.Kernel.Model.FmSectionTypes;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Assembly;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Categories;
+using Riskeer.AssemblyTool.Data;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Riskeer.AssemblyTool.KernelWrapper.Creators;
+using Riskeer.AssemblyTool.KernelWrapper.Kernels;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class AssessmentSectionAssemblyCalculatorTest
+ {
+ [Test]
+ public void Constructor_WithFactory_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var kernelFactory = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var calculator = new AssessmentSectionAssemblyCalculator(kernelFactory);
+
+ // Assert
+ Assert.IsInstanceOf(calculator);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_FactoryNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new AssessmentSectionAssemblyCalculator(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("factory", exception.ParamName);
+ }
+
+ [Test]
+ public void AssemblyFailureMechanismsWithProbability_WithInvalidEnumInput_ThrowAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ var failureMechanismAssembly = new FailureMechanismAssembly(random.NextDouble(), (FailureMechanismAssemblyCategoryGroup) 99);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(new[]
+ {
+ failureMechanismAssembly
+ }, signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ var failureMechanismAssembly = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismCategories();
+
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleFailureMechanisms(new[]
+ {
+ failureMechanismAssembly
+ }, signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ Assert.IsFalse(kernel.PartialAssembly);
+ Assert.AreEqual(signalingNorm, categoriesKernel.SignalingNorm);
+ Assert.AreEqual(lowerLimitNorm, categoriesKernel.LowerLimitNorm);
+ Assert.AreEqual(1, categoriesKernel.N);
+ Assert.AreEqual(failureProbabilityMarginFactor, categoriesKernel.FailureMechanismContribution);
+
+ FailureMechanismAssemblyResult actualFailureMechanismAssemblyInput = kernel.FailureMechanismAssemblyResults.Single();
+ Assert.AreEqual(GetGroup(failureMechanismAssembly.Group), actualFailureMechanismAssemblyInput.Category);
+ Assert.AreEqual(failureMechanismAssembly.Probability, actualFailureMechanismAssemblyInput.FailureProbability);
+ Assert.AreSame(categoriesKernel.FailureMechanismCategoriesOutput, kernel.FailureMechanismCategories);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismWithProbability_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismAssembly assembly = calculator.AssembleFailureMechanisms(Enumerable.Empty(),
+ signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ FailureMechanismAssemblyResult expectedResult = kernel.FailureMechanismAssemblyResult;
+ FailureMechanismAssemblyCategoryGroup expectedGroup =
+ FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup(expectedResult.Category);
+ Assert.AreEqual(expectedResult.FailureProbability, assembly.Probability);
+ Assert.AreEqual(expectedGroup, assembly.Group);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismWithProbability_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult((EFailureMechanismCategory) 99,
+ random.NextDouble());
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty(),
+ signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty(),
+ signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithProbability_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ double signalingNorm = random.NextDouble(0, 0.5);
+ double lowerLimitNorm = random.NextDouble(0.5, 1);
+ double failureProbabilityMarginFactor = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty(),
+ signalingNorm, lowerLimitNorm, failureProbabilityMarginFactor);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithoutProbability_WithInvalidEnumInput_ThrowAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(new[]
+ {
+ (FailureMechanismAssemblyCategoryGroup) 99
+ });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithoutProbability_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var failureMechanismAssemblyCategoryGroup = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = new Random(39).NextEnumValue();
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleFailureMechanisms(new[]
+ {
+ failureMechanismAssemblyCategoryGroup
+ });
+
+ // Assert
+ Assert.IsFalse(kernel.PartialAssembly);
+
+ FailureMechanismAssemblyResult actualFailureMechanismAssemblyInput = kernel.FailureMechanismAssemblyResults.Single();
+ Assert.AreEqual(GetGroup(failureMechanismAssemblyCategoryGroup), actualFailureMechanismAssemblyInput.Category);
+ Assert.IsNaN(actualFailureMechanismAssemblyInput.FailureProbability);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismWithoutProbability_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = random.NextEnumValue();
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismAssemblyCategoryGroup assembly = calculator.AssembleFailureMechanisms(Enumerable.Empty());
+
+ // Assert
+ FailureMechanismAssemblyCategoryGroup expectedAssembly = FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup(kernel.FailureMechanismCategoryResult);
+ Assert.AreEqual(expectedAssembly, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismWithoutProbability_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = (EFailureMechanismCategory) 99;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithoutProbability_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleFailureMechanismsWithoutProbability_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleFailureMechanisms(Enumerable.Empty());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ [TestCase(FailureMechanismAssemblyCategoryGroup.None, (FailureMechanismAssemblyCategoryGroup) 99, TestName = "Invalid Input Failure Mechanisms With Probability")]
+ [TestCase((FailureMechanismAssemblyCategoryGroup) 99, FailureMechanismAssemblyCategoryGroup.None, TestName = "Invalid Input Failure Mechanisms Without Probability")]
+ public void AssembleAssessmentSection_WithInvalidInput_ThrowsAssessmentSectionAssemblyCalculatorException(
+ FailureMechanismAssemblyCategoryGroup categoryGroupInputFailureMechanismWithProbability,
+ FailureMechanismAssemblyCategoryGroup categoryGroupInputFailureMechanismWithoutProbability)
+ {
+ // Setup
+ var random = new Random(39);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ categoryGroupInputFailureMechanismWithProbability);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleAssessmentSection(categoryGroupInputFailureMechanismWithoutProbability, failureMechanismsWithProbability);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleAssessmentSection_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+ var failureMechanismsWithoutProbability = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.AssessmentSectionAssemblyResult = random.NextEnumValue();
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleAssessmentSection(failureMechanismsWithoutProbability, failureMechanismsWithProbability);
+
+ // Assert
+ FailureMechanismAssemblyResult expectedKernelInputFailureWithoutProbability =
+ AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(failureMechanismsWithoutProbability);
+ Assert.AreEqual(expectedKernelInputFailureWithoutProbability.Category, kernel.AssemblyResultNoFailureProbability);
+
+ FailureMechanismAssemblyResult actualKernelInputFailureProbability = kernel.AssemblyResultWithFailureProbability;
+ FailureMechanismAssemblyResult expectedKernelInputFailureProbability =
+ AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(failureMechanismsWithProbability);
+ Assert.AreEqual(expectedKernelInputFailureProbability.Category,
+ actualKernelInputFailureProbability.Category);
+ Assert.AreEqual(expectedKernelInputFailureProbability.FailureProbability,
+ actualKernelInputFailureProbability.FailureProbability);
+ }
+ }
+
+ [Test]
+ public void AssembleAssessmentSection_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(21);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+ var failureMechanismsWithoutProbability = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.AssessmentSectionAssemblyResult = random.NextEnumValue();
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ AssessmentSectionAssemblyCategoryGroup assembly = calculator.AssembleAssessmentSection(failureMechanismsWithoutProbability,
+ failureMechanismsWithProbability);
+
+ // Assert
+ AssessmentSectionAssemblyCategoryGroup expectedAssembly = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory(kernel.AssessmentSectionAssemblyResult);
+ Assert.AreEqual(expectedAssembly, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleAssessmentSection_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+ var failureMechanismsWithoutProbability = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.AssessmentSectionAssemblyResult = (EAssessmentGrade) 99;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleAssessmentSection(failureMechanismsWithoutProbability,
+ failureMechanismsWithProbability);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleAssessmentSection_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+ var failureMechanismsWithoutProbability = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleAssessmentSection(failureMechanismsWithoutProbability,
+ failureMechanismsWithProbability);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleAssessmentSection_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ var failureMechanismsWithProbability = new FailureMechanismAssembly(random.NextDouble(),
+ random.NextEnumValue());
+ var failureMechanismsWithoutProbability = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleAssessmentSection(failureMechanismsWithoutProbability,
+ failureMechanismsWithProbability);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_WithInvalidInput_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, (FailureMechanismSectionAssemblyCategoryGroup) 99)
+ }
+ }, random.Next());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var input = new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue())
+ }
+ };
+ double assessmentSectionLength = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
+ kernel.AssemblyResult = new AssemblyResult(new[]
+ {
+ new FailureMechanismSectionList(string.Empty, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, random.NextEnumValue())
+ })
+ }, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, random.NextEnumValue())
+ });
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleCombinedFailureMechanismSections(input, assessmentSectionLength);
+
+ // Assert
+ Assert.AreEqual(assessmentSectionLength, kernel.AssessmentSectionLengthInput.Value);
+ CombinedFailureMechanismSectionsInputAssert.AssertCombinedFailureMechanismInput(input, kernel.FailureMechanismSectionListsInput);
+ Assert.IsFalse(kernel.PartialAssembly);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
+ kernel.AssemblyResult = new AssemblyResult(new[]
+ {
+ new FailureMechanismSectionList(string.Empty, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, random.NextEnumValue())
+ })
+ }, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, random.NextEnumValue())
+ });
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ CombinedFailureMechanismSectionAssembly[] output = calculator.AssembleCombinedFailureMechanismSections(new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue())
+ }
+ }, random.NextDouble()).ToArray();
+
+ // Assert
+ CombinedFailureMechanismSectionAssemblyAssert.AssertAssembly(kernel.AssemblyResult, output);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
+ kernel.AssemblyResult = new AssemblyResult(new[]
+ {
+ new FailureMechanismSectionList(string.Empty, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, (EFmSectionCategory) 99)
+ })
+ }, new[]
+ {
+ new FmSectionWithDirectCategory(0, 1, random.NextEnumValue())
+ });
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue())
+ }
+ }, random.NextDouble()).ToArray();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue())
+ }
+ }, random.NextDouble()).ToArray();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleCombinedFailureMechanismSections_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new AssessmentSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleCombinedFailureMechanismSections(new[]
+ {
+ new[]
+ {
+ new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue())
+ }
+ }, random.NextDouble()).ToArray();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ private static EFailureMechanismCategory GetGroup(FailureMechanismAssemblyCategoryGroup originalGroup)
+ {
+ switch (originalGroup)
+ {
+ case FailureMechanismAssemblyCategoryGroup.None:
+ return EFailureMechanismCategory.Gr;
+ case FailureMechanismAssemblyCategoryGroup.NotApplicable:
+ return EFailureMechanismCategory.Nvt;
+ case FailureMechanismAssemblyCategoryGroup.It:
+ return EFailureMechanismCategory.It;
+ case FailureMechanismAssemblyCategoryGroup.IIt:
+ return EFailureMechanismCategory.IIt;
+ case FailureMechanismAssemblyCategoryGroup.IIIt:
+ return EFailureMechanismCategory.IIIt;
+ case FailureMechanismAssemblyCategoryGroup.IVt:
+ return EFailureMechanismCategory.IVt;
+ case FailureMechanismAssemblyCategoryGroup.Vt:
+ return EFailureMechanismCategory.Vt;
+ case FailureMechanismAssemblyCategoryGroup.VIt:
+ return EFailureMechanismCategory.VIt;
+ case FailureMechanismAssemblyCategoryGroup.VIIt:
+ return EFailureMechanismCategory.VIIt;
+ default:
+ throw new NotSupportedException();
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorExceptionTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorExceptionTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,32 @@
+// 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 Core.Common.TestUtil;
+using NUnit.Framework;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class FailureMechanismAssemblyCalculatorExceptionTest
+ : CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismAssemblyCalculatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,395 @@
+// 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 System.ComponentModel;
+using System.Linq;
+using Assembly.Kernel.Exceptions;
+using Assembly.Kernel.Model;
+using Assembly.Kernel.Model.FmSectionTypes;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Assembly;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Categories;
+using Riskeer.AssemblyTool.Data;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Riskeer.AssemblyTool.KernelWrapper.Creators;
+using Riskeer.AssemblyTool.KernelWrapper.Kernels;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class FailureMechanismAssemblyCalculatorTest
+ {
+ [Test]
+ public void Constructor_WithKernelFactory_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var kernelFactory = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var calculator = new FailureMechanismAssemblyCalculator(kernelFactory);
+
+ // Assert
+ Assert.IsInstanceOf(calculator);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_FactoryNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new FailureMechanismAssemblyCalculator(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("factory", exception.ParamName);
+ }
+
+ [Test]
+ public void Assemble_WithInvalidEnumInput_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(new[]
+ {
+ (FailureMechanismSectionAssemblyCategoryGroup) 99
+ });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void Assemble_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var categoryGroups = new[]
+ {
+ random.NextEnumValue()
+ };
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = new Random(39).NextEnumValue();
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ calculator.Assemble(categoryGroups);
+
+ // Assert
+ FailureMechanismSectionAssemblyCategoryGroup actualCategoryGroup =
+ FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup(kernel.FmSectionAssemblyResultsInput.Single().Result);
+ Assert.AreEqual(categoryGroups.Single(), actualCategoryGroup);
+ Assert.IsFalse(kernel.PartialAssembly);
+ }
+ }
+
+ [Test]
+ public void Assemble_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = new Random(39).NextEnumValue();
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismAssemblyCategoryGroup category = calculator.Assemble(
+ new List());
+
+ // Assert
+ FailureMechanismAssemblyCategoryGroup expectedCategory = FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup(kernel.FailureMechanismCategoryResult);
+ Assert.AreEqual(expectedCategory, category);
+ }
+ }
+
+ [Test]
+ public void Assemble_KernelWithInvalidOutput_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismCategoryResult = (EFailureMechanismCategory) 99;
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(new List());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void Assemble_KernelThrowsException_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(new List());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void Assemble_KernelThrowsAssemblyException_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(new List());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_WithInvalidEnumInput_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(new[]
+ {
+ new FailureMechanismSectionAssembly(new Random(39).NextDouble(), (FailureMechanismSectionAssemblyCategoryGroup) 99)
+ }, CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var expectedResults = new[]
+ {
+ new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())
+ };
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismCategories();
+
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult(random.NextEnumValue(),
+ random.NextDouble());
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ calculator.Assemble(expectedResults, assemblyCategoriesInput);
+
+ // Assert
+ AssertFailureMechanismSectionAssembly(expectedResults.Single(), kernel.FmSectionAssemblyResultsWithProbabilityInput.Single());
+
+ Assert.IsFalse(kernel.PartialAssembly);
+
+ double expectedN = assemblyCategoriesInput.N;
+ double expectedFailureMechanismContribution = assemblyCategoriesInput.FailureMechanismContribution;
+ Assert.AreEqual(expectedN, kernel.FailureMechanismInput.LengthEffectFactor);
+ Assert.AreEqual(expectedFailureMechanismContribution, kernel.FailureMechanismInput.FailureProbabilityMarginFactor);
+
+ Assert.AreSame(categoriesKernel.FailureMechanismCategoriesOutput, kernel.Categories);
+ Assert.AreEqual(assemblyCategoriesInput.LowerLimitNorm, categoriesKernel.LowerLimitNorm);
+ Assert.AreEqual(assemblyCategoriesInput.SignalingNorm, categoriesKernel.SignalingNorm);
+ Assert.AreEqual(expectedN, categoriesKernel.N);
+ Assert.AreEqual(expectedFailureMechanismContribution, categoriesKernel.FailureMechanismContribution);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismAssembly assembly = calculator.Assemble(Enumerable.Empty(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ FailureMechanismAssemblyCategoryGroup expectedGroup = FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup(kernel.FailureMechanismAssemblyResult.Category);
+ Assert.AreEqual(expectedGroup, assembly.Group);
+ Assert.AreEqual(kernel.FailureMechanismAssemblyResult.FailureProbability, assembly.Probability);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_KernelWithInvalidOutput_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.FailureMechanismAssemblyResult = new FailureMechanismAssemblyResult((EFailureMechanismCategory) 99,
+ new Random(39).NextDouble());
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(Enumerable.Empty(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_KernelThrowsException_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(Enumerable.Empty(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleWithProbabilities_KernelThrowsAssemblyException_ThrowFailureMechanismAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.Assemble(Enumerable.Empty(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ private static void AssertFailureMechanismSectionAssembly(FailureMechanismSectionAssembly expectedSectionAssembly,
+ FmSectionAssemblyDirectResultWithProbability actualResult)
+ {
+ FailureMechanismSectionAssemblyCategoryGroup actualGroup =
+ FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup(actualResult.Result);
+ Assert.AreEqual(expectedSectionAssembly.Group, actualGroup);
+ Assert.AreEqual(expectedSectionAssembly.Probability, actualResult.FailureProbability);
+ }
+
+ private static AssemblyCategoriesInput CreateAssemblyCategoriesInput()
+ {
+ var random = new Random(39);
+ return new AssemblyCategoriesInput(random.NextDouble(1.0, 5.0),
+ random.NextDouble(),
+ random.NextDouble(0.0, 0.5),
+ random.NextDouble(0.5, 1.0));
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorExceptionTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorExceptionTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,32 @@
+// 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 Core.Common.TestUtil;
+using NUnit.Framework;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class FailureMechanismSectionAssemblyCalculatorExceptionTest
+ : CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorTest.cs
===================================================================
diff -u
--- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorTest.cs (revision 0)
+++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1)
@@ -0,0 +1,3402 @@
+// 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 System.ComponentModel;
+using Assembly.Kernel.Exceptions;
+using Assembly.Kernel.Model;
+using Assembly.Kernel.Model.AssessmentResultTypes;
+using Assembly.Kernel.Model.FmSectionTypes;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Assembly;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels.Categories;
+using Ringtoets.Common.Primitives;
+using Riskeer.AssemblyTool.Data;
+using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly;
+using Riskeer.AssemblyTool.KernelWrapper.Creators;
+using Riskeer.AssemblyTool.KernelWrapper.Kernels;
+
+namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Assembly
+{
+ [TestFixture]
+ public class FailureMechanismSectionAssemblyCalculatorTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var kernelFactory = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var calculator = new FailureMechanismSectionAssemblyCalculator(kernelFactory);
+
+ // Assert
+ Assert.IsInstanceOf(calculator);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Constructor_FactoryNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new FailureMechanismSectionAssemblyCalculator(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("factory", exception.ParamName);
+ }
+
+ private static void AssertCalculatorOutput(FmSectionAssemblyDirectResult original, FailureMechanismSectionAssembly actual)
+ {
+ Assert.IsNaN(actual.Probability);
+ Assert.AreEqual(AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(original.Result), actual.Group);
+ }
+
+ private static void AssertCalculatorOutput(FmSectionAssemblyDirectResultWithProbability original, FailureMechanismSectionAssembly actual)
+ {
+ Assert.AreEqual(original.FailureProbability, actual.Probability);
+ Assert.AreEqual(AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(original.Result), actual.Group);
+ }
+
+ private static void AssertAssemblyCategoriesInput(AssemblyCategoriesInput assemblyCategoriesInput,
+ AssemblyCategoriesKernelStub categoriesKernel,
+ FailureMechanismSectionAssemblyKernelStub kernel)
+ {
+ Assert.AreEqual(assemblyCategoriesInput.SignalingNorm, categoriesKernel.SignalingNorm);
+ Assert.AreEqual(assemblyCategoriesInput.LowerLimitNorm, categoriesKernel.LowerLimitNorm);
+ Assert.AreEqual(assemblyCategoriesInput.N, categoriesKernel.N);
+ Assert.AreEqual(assemblyCategoriesInput.FailureMechanismContribution, categoriesKernel.FailureMechanismContribution);
+
+ Assert.AreSame(categoriesKernel.FailureMechanismSectionCategoriesOutput, kernel.FailureMechanismSectionCategories);
+ }
+
+ private static void AssertAssemblyCategoriesInput(double normativeNorm,
+ double n, double failureMechanismContribution,
+ AssemblyCategoriesKernelStub categoriesKernel,
+ FailureMechanismSectionAssemblyKernelStub kernel)
+ {
+ Assert.AreEqual(normativeNorm, categoriesKernel.AssessmentSectionNorm);
+ Assert.AreEqual(n, categoriesKernel.N);
+ Assert.AreEqual(failureMechanismContribution, categoriesKernel.FailureMechanismContribution);
+ Assert.AreSame(categoriesKernel.FailureMechanismCategoriesOutput, kernel.FailureMechanismSectionCategories);
+ }
+
+ private static AssemblyCategoriesInput CreateAssemblyCategoriesInput()
+ {
+ var random = new Random(39);
+ return new AssemblyCategoriesInput(random.NextDouble(1.0, 5.0),
+ random.NextDouble(),
+ random.NextDouble(0.0, 0.5),
+ random.NextDouble(0.5, 1.0));
+ }
+
+ #region Simple Assessment
+
+ [Test]
+ public void AssembleSimpleAssessment_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment((SimpleAssessmentResultType) 99);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessment_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var assessmentResult = random.NextEnumValue();
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleSimpleAssessment(assessmentResult);
+
+ // Assert
+ EAssessmentResultTypeE1 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE1(assessmentResult);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeE1Input);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessment_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessment_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99,
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessment_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessment_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment((SimpleAssessmentValidityOnlyResultType) 99);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var assessmentResult = random.NextEnumValue();
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleSimpleAssessment(assessmentResult);
+
+ // Assert
+ EAssessmentResultTypeE2 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE2(assessmentResult);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeE2Input);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99,
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleSimpleAssessmentValidityOnly_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleSimpleAssessment(random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ #endregion
+
+ #region Detailed Assessment
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment((DetailedAssessmentResultType) 99);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var detailedAssessmentResult = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(detailedAssessmentResult);
+
+ // Assert
+ EAssessmentResultTypeG1 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG1(detailedAssessmentResult);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeG1Input);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ var detailedAssessmentResult = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult((EFmSectionCategory) 99);
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(detailedAssessmentResult);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssemblyCategoryGroup assembly = calculator.AssembleDetailedAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(
+ kernel.FailureMechanismSectionDirectResult.Result);
+ Assert.AreEqual(expectedResult, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithResult_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_WithInvalidEnumInput_ThrowInvalidEnumArgumentException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ (DetailedAssessmentProbabilityOnlyResultType) 99,
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double probability = random.NextDouble();
+ var detailedAssessment = random.NextEnumValue();
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ detailedAssessment,
+ probability,
+ assemblyCategoriesInput);
+
+ // Assert
+ EAssessmentResultTypeG2 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG2(detailedAssessment);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeG2Input);
+ Assert.AreEqual(probability, kernel.FailureProbabilityInput);
+
+ AssertAssemblyCategoriesInput(assemblyCategoriesInput,
+ categoriesKernel,
+ kernel);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_WithProbabilityResultAndNaNValue_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ DetailedAssessmentProbabilityOnlyResultType.Probability,
+ double.NaN,
+ assemblyCategoriesInput);
+
+ // Assert
+ Assert.IsNaN(kernel.FailureProbabilityInput);
+ Assert.AreEqual(EAssessmentResultTypeG2.Gr, kernel.AssessmentResultTypeG2Input);
+
+ AssertAssemblyCategoriesInput(assemblyCategoriesInput,
+ categoriesKernel,
+ kernel);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99,
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithProbability_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_WithInvalidEnumInput_ThrowInvalidEnumArgumentException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ (DetailedAssessmentProbabilityOnlyResultType) 99,
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double probability = random.NextDouble();
+ double normativeNorm = random.NextDouble();
+ double n = random.NextDouble(1, 10);
+ double failureMechanismContribution = random.NextDouble();
+ var detailedAssessment = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ detailedAssessment,
+ probability,
+ normativeNorm,
+ n,
+ failureMechanismContribution);
+
+ // Assert
+ AssertAssemblyCategoriesInput(normativeNorm, n, failureMechanismContribution, categoriesKernel, kernel);
+
+ EAssessmentResultTypeG2 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG2(detailedAssessment);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeG2Input);
+ Assert.AreEqual(probability, kernel.FailureProbabilityInput);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_WithProbabilityResultAndNaNValue_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double normativeNorm = random.NextDouble();
+ double n = random.NextDouble(1, 10);
+ double failureMechanismContribution = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ DetailedAssessmentProbabilityOnlyResultType.Probability,
+ double.NaN,
+ normativeNorm,
+ n,
+ failureMechanismContribution);
+
+ // Assert
+ AssertAssemblyCategoriesInput(normativeNorm, n, failureMechanismContribution, categoriesKernel, kernel);
+
+ Assert.IsNaN(kernel.FailureProbabilityInput);
+ Assert.AreEqual(EAssessmentResultTypeG2.Gr, kernel.AssessmentResultTypeG2Input);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99,
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithNormativeNorm_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_WithInvalidEnumInput_ThrowInvalidEnumArgumentException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ (DetailedAssessmentProbabilityOnlyResultType) 99,
+ random.NextDouble(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double probability = random.NextDouble();
+ double n = random.NextDouble();
+ var detailedAssessment = random.NextEnumValue();
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ detailedAssessment,
+ probability,
+ n,
+ assemblyCategoriesInput);
+
+ // Assert
+ Assert.AreEqual(probability, kernel.FailureProbabilityInput);
+ Assert.AreEqual(n, kernel.LengthEffectFactorInput);
+ EAssessmentResultTypeG2 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG2(detailedAssessment);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeG2Input);
+ AssertAssemblyCategoriesInput(assemblyCategoriesInput,
+ categoriesKernel,
+ kernel);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_WithProbabilityResultAndNaNValue_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double n = random.NextDouble();
+ AssemblyCategoriesInput assemblyCategoriesInput = CreateAssemblyCategoriesInput();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ categoriesKernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(
+ DetailedAssessmentProbabilityOnlyResultType.Probability,
+ double.NaN,
+ n,
+ assemblyCategoriesInput);
+
+ // Assert
+ Assert.IsNaN(kernel.FailureProbabilityInput);
+ Assert.AreEqual(n, kernel.LengthEffectFactorInput);
+ Assert.AreEqual(EAssessmentResultTypeG2.Gr, kernel.AssessmentResultTypeG2Input);
+ AssertAssemblyCategoriesInput(assemblyCategoriesInput,
+ categoriesKernel,
+ kernel);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability(random.NextEnumValue(),
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResultWithProbability = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99,
+ random.NextDouble());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithLengthEffect_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextDouble(),
+ random.NextDouble(),
+ CreateAssemblyCategoriesInput());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ (DetailedAssessmentResultType) 99,
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue();
+ var detailedAssessmentResultForSignalingNorm = random.NextEnumValue();
+ var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue();
+ var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue();
+ var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleDetailedAssessment(detailedAssessmentResultForFactorizedSignalingNorm,
+ detailedAssessmentResultForSignalingNorm,
+ detailedAssessmentResultForMechanismSpecificLowerLimitNorm,
+ detailedAssessmentResultForLowerLimitNorm,
+ detailedAssessmentResultForFactorizedLowerLimitNorm);
+
+ // Assert
+ Dictionary results = kernel.CategoryCompliancyResultsInput.GetCompliancyResults();
+ Assert.AreEqual(GetCategoryCompliance(detailedAssessmentResultForFactorizedSignalingNorm), results[EFmSectionCategory.Iv]);
+ Assert.AreEqual(GetCategoryCompliance(detailedAssessmentResultForSignalingNorm), results[EFmSectionCategory.IIv]);
+ Assert.AreEqual(GetCategoryCompliance(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), results[EFmSectionCategory.IIIv]);
+ Assert.AreEqual(GetCategoryCompliance(detailedAssessmentResultForLowerLimitNorm), results[EFmSectionCategory.IVv]);
+ Assert.AreEqual(GetCategoryCompliance(detailedAssessmentResultForFactorizedLowerLimitNorm), results[EFmSectionCategory.Vv]);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ var detailedAssessmentResultForFactorizedSignalingNorm = random.NextEnumValue();
+ var detailedAssessmentResultForSignalingNorm = random.NextEnumValue();
+ var detailedAssessmentResultForMechanismSpecificLowerLimitNorm = random.NextEnumValue();
+ var detailedAssessmentResultForLowerLimitNorm = random.NextEnumValue();
+ var detailedAssessmentResultForFactorizedLowerLimitNorm = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult((EFmSectionCategory) 99);
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ detailedAssessmentResultForFactorizedSignalingNorm,
+ detailedAssessmentResultForSignalingNorm,
+ detailedAssessmentResultForMechanismSpecificLowerLimitNorm,
+ detailedAssessmentResultForLowerLimitNorm,
+ detailedAssessmentResultForFactorizedLowerLimitNorm);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssemblyCategoryGroup assembly = calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue());
+
+ // Assert
+ FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(
+ kernel.FailureMechanismSectionDirectResult.Result);
+ Assert.AreEqual(expectedResult, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleDetailedAssessmentWithCategoryResults_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleDetailedAssessment(
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue(),
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ private static ECategoryCompliancy GetCategoryCompliance(DetailedAssessmentResultType detailedAssessmentResult)
+ {
+ switch (detailedAssessmentResult)
+ {
+ case DetailedAssessmentResultType.None:
+ return ECategoryCompliancy.NoResult;
+ case DetailedAssessmentResultType.Sufficient:
+ return ECategoryCompliancy.Complies;
+ case DetailedAssessmentResultType.Insufficient:
+ return ECategoryCompliancy.DoesNotComply;
+ case DetailedAssessmentResultType.NotAssessed:
+ return ECategoryCompliancy.Ngo;
+ default:
+ throw new NotSupportedException();
+ }
+ }
+
+ #endregion
+
+ #region Tailor Made Assessment
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleTailorMadeAssessment((TailorMadeAssessmentResultType) 99);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var tailorMadeAssessmentResult = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleTailorMadeAssessment(tailorMadeAssessmentResult);
+
+ // Assert
+ EAssessmentResultTypeT1 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT1(tailorMadeAssessmentResult);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeT1Input);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ var tailorMadeAssessmentResult = random.NextEnumValue();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult((EFmSectionCategory) 99);
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleTailorMadeAssessment(tailorMadeAssessmentResult);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssemblyCategoryGroup assembly = calculator.AssembleTailorMadeAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(
+ kernel.FailureMechanismSectionDirectResult.Result);
+ Assert.AreEqual(expectedResult, assembly);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_KernelThrowsException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleTailorMadeAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithResult_KernelThrowsAssemblyException_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.ThrowAssemblyExceptionOnCalculate = true;
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleTailorMadeAssessment(
+ random.NextEnumValue());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
+ {
+ new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryLowerLimitOutOfRange)
+ }), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ TestDelegate test = () => calculator.AssembleTailorMadeAssessment(
+ (TailorMadeAssessmentProbabilityAndDetailedCalculationResultType) 99,
+ random.NextDouble(),
+ random.NextDouble(),
+ random.NextDouble(1, 10),
+ random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_WithValidInput_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ var tailorMadeAssessmentResult = random.NextEnumValue();
+ double probability = random.NextDouble();
+ double normativeNorm = random.NextDouble();
+ double n = random.NextDouble(1, 10);
+ double failureMechanismContribution = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleTailorMadeAssessment(tailorMadeAssessmentResult, probability, normativeNorm, n, failureMechanismContribution);
+
+ // Assert
+ AssertAssemblyCategoriesInput(normativeNorm, n, failureMechanismContribution, categoriesKernel, kernel);
+
+ EAssessmentResultTypeT4 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT4(tailorMadeAssessmentResult);
+ Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeT4Input);
+ Assert.AreEqual(probability, kernel.FailureProbabilityInput);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_WithProbabilityResultAndNaNValue_InputCorrectlySetToKernel()
+ {
+ // Setup
+ var random = new Random(39);
+ double normativeNorm = random.NextDouble();
+ double n = random.NextDouble(1, 10);
+ double failureMechanismContribution = random.NextDouble();
+
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ AssemblyCategoriesKernelStub categoriesKernel = factory.LastCreatedAssemblyCategoriesKernel;
+ CategoriesListTestFactory.CreateFailureMechanismSectionCategories();
+
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ calculator.AssembleTailorMadeAssessment(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.Probability,
+ double.NaN,
+ normativeNorm,
+ n,
+ failureMechanismContribution);
+
+ // Assert
+ AssertAssemblyCategoriesInput(normativeNorm, n, failureMechanismContribution, categoriesKernel, kernel);
+
+ Assert.AreEqual(EAssessmentResultTypeT4.Gr, kernel.AssessmentResultTypeT4Input);
+ Assert.IsNaN(kernel.FailureProbabilityInput);
+ }
+ }
+
+ [Test]
+ public void AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
+ {
+ // Setup
+ var random = new Random(39);
+ using (new AssemblyToolKernelFactoryConfig())
+ {
+ var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance;
+ FailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
+ kernel.FailureMechanismSectionDirectResult = new FmSectionAssemblyDirectResult(random.NextEnumValue());
+
+ var calculator = new FailureMechanismSectionAssemblyCalculator(factory);
+
+ // Call
+ FailureMechanismSectionAssembly assembly = calculator.AssembleTailorMadeAssessment(
+ random.NextEnumValue