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(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(1, 10), + random.NextDouble()); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResult, assembly); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + 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( + 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 AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_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(), + 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 AssembleTailorMadeAssessmentWithProbabilityAndDetailedCalculationResult_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(), + 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 AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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( + (TailorMadeAssessmentProbabilityCalculationResultType) 99, + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double probability = 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.AssembleTailorMadeAssessment(tailorMadeAssessmentResult, probability, assemblyCategoriesInput); + + // Assert + EAssessmentResultTypeT3 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3(tailorMadeAssessmentResult); + Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeT3Input); + Assert.AreEqual(probability, kernel.FailureProbabilityInput); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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.AssembleTailorMadeAssessment(TailorMadeAssessmentProbabilityCalculationResultType.Probability, + double.NaN, + assemblyCategoriesInput); + + // Assert + Assert.AreEqual(EAssessmentResultTypeT3.Gr, kernel.AssessmentResultTypeT3Input); + Assert.IsNaN(kernel.FailureProbabilityInput); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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.AssembleTailorMadeAssessment( + random.NextEnumValue(), + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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.AssembleTailorMadeAssessment( + random.NextEnumValue(), + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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(), + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithProbabilityCalculationResult_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(), + 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 AssembleTailorMadeAssessmentWithLengthEffect_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( + (TailorMadeAssessmentProbabilityCalculationResultType) 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 AssembleTailorMadeAssessmentWithLengthEffect_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var tailorMadeAssessmentResult = random.NextEnumValue(); + double probability = random.NextDouble(); + 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.AssembleTailorMadeAssessment(tailorMadeAssessmentResult, probability, n, assemblyCategoriesInput); + + // Assert + EAssessmentResultTypeT3 expectedResultType = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3(tailorMadeAssessmentResult); + Assert.AreEqual(expectedResultType, kernel.AssessmentResultTypeT3Input); + Assert.AreEqual(probability, kernel.FailureProbabilityInput); + Assert.AreEqual(n, kernel.LengthEffectFactorInput); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithLengthEffect_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.AssembleTailorMadeAssessment(TailorMadeAssessmentProbabilityCalculationResultType.Probability, + double.NaN, + n, + assemblyCategoriesInput); + + // Assert + Assert.AreEqual(EAssessmentResultTypeT3.Gr, kernel.AssessmentResultTypeT3Input); + Assert.IsNaN(kernel.FailureProbabilityInput); + Assert.AreEqual(n, kernel.LengthEffectFactorInput); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithLengthEffect_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.AssembleTailorMadeAssessment( + random.NextEnumValue(), + random.NextDouble(), + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithLengthEffect_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.AssembleTailorMadeAssessment( + 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 AssembleTailorMadeAssessmentWithLengthEffect_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(), + random.NextDouble(), + random.NextDouble(), + CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithLengthEffect_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(), + 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 AssembleTailorMadeAssessmentWithCategoryResult_WithInvalidAssessmentResultTypeEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + var calculator = new FailureMechanismSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleTailorMadeAssessment((TailorMadeAssessmentCategoryGroupResultType) 99); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithCategoryResult_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var categoryGroupResult = 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(categoryGroupResult); + + // Assert + Tuple expectedInput = + FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3WithCategoryGroupResult(categoryGroupResult); + + Assert.AreEqual(expectedInput.Item1, kernel.AssessmentResultTypeT3Input); + Assert.AreEqual(expectedInput.Item2, kernel.SectionCategoryInput); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithCategoryResult_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 AssembleTailorMadeAssessmentWithCategoryResult_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + 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( + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleTailorMadeAssessmentWithCategoryResult_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 AssembleTailorMadeAssessmentWithCategoryResult_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); + } + } + + #endregion + + #region Combined Assembly + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), (FailureMechanismSectionAssemblyCategoryGroup) 99)); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var simpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), 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.AssembleCombined(simpleAssembly); + + // Assert + AssertAssembly(simpleAssembly, kernel.SimpleAssessmentResultInputWithProbability); + Assert.IsNull(kernel.DetailedAssessmentResultInputWithProbability); + Assert.IsNull(kernel.TailorMadeAssessmentResultInputWithProbability); + } + } + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilitiesAndSimpleAssemblyOnly_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), 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 AssembleCombinedWithProbabilities_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), (FailureMechanismSectionAssemblyCategoryGroup) 99), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilities_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var simpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var detailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var tailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), 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.AssembleCombined(simpleAssembly, detailedAssembly, tailorMadeAssembly); + + // Assert + AssertAssembly(simpleAssembly, kernel.SimpleAssessmentResultInputWithProbability); + AssertAssembly(detailedAssembly, kernel.DetailedAssessmentResultInputWithProbability); + AssertAssembly(tailorMadeAssembly, kernel.TailorMadeAssessmentResultInputWithProbability); + } + } + + [Test] + public void AssembleCombinedWithProbabilities_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleCombinedWithProbabilities_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilities_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue())); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithProbabilities_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.AssembleCombined( + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()), + new FailureMechanismSectionAssembly(random.NextDouble(), 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 AssembleCombinedWithSimpleAssemblyOnly_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + var calculator = new FailureMechanismSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleCombined((FailureMechanismSectionAssemblyCategoryGroup) 99); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAssemblyOnly_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var simpleAssembly = 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.AssembleCombined(simpleAssembly); + + // Assert + Assert.AreEqual(simpleAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.SimpleAssessmentResultInput.Result)); + Assert.IsNull(kernel.DetailedAssessmentResultInput); + Assert.IsNull(kernel.TailorMadeAssessmentResultInput); + } + } + + [Test] + public void AssembleCombinedWithSimpleAssemblyOnly_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 group = calculator.AssembleCombined( + random.NextEnumValue()); + + // Assert + FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup( + kernel.FailureMechanismSectionDirectResult.Result); + Assert.AreEqual(expectedResult, group); + } + } + + [Test] + public void AssembleCombinedWithSimpleAssemblyOnly_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + + 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.AssembleCombined( + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAssemblyOnly_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.AssembleCombined( + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAssemblyOnly_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.AssembleCombined( + 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 AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_WithInvalidEnumInput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(21); + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + var calculator = new FailureMechanismSectionAssemblyCalculator(factory); + + // Call + TestDelegate test = () => calculator.AssembleCombined((FailureMechanismSectionAssemblyCategoryGroup) 99, + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var simpleAssembly = random.NextEnumValue(); + var tailorMadeAssembly = 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.AssembleCombined(simpleAssembly, tailorMadeAssembly); + + // Assert + Assert.AreEqual(simpleAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.SimpleAssessmentResultInput.Result)); + Assert.IsNull(kernel.DetailedAssessmentResultInput); + Assert.AreEqual(tailorMadeAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.TailorMadeAssessmentResultInput.Result)); + } + } + + [Test] + public void AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_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 group = calculator.AssembleCombined( + random.NextEnumValue(), + random.NextEnumValue()); + + // Assert + FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup( + kernel.FailureMechanismSectionDirectResult.Result); + Assert.AreEqual(expectedResult, group); + } + } + + [Test] + public void AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + + 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.AssembleCombined( + random.NextEnumValue(), + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_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.AssembleCombined( + random.NextEnumValue(), + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombinedWithSimpleAndTailorMadeAssemblyOnly_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.AssembleCombined( + 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); + } + } + + [Test] + public void AssembleCombined_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.AssembleCombined((FailureMechanismSectionAssemblyCategoryGroup) 99, + random.NextEnumValue(), + random.NextEnumValue()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleCombined_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + var simpleAssembly = random.NextEnumValue(); + var detailedAssembly = random.NextEnumValue(); + var tailorMadeAssembly = 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.AssembleCombined(simpleAssembly, detailedAssembly, tailorMadeAssembly); + + // Assert + Assert.AreEqual(simpleAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.SimpleAssessmentResultInput.Result)); + Assert.AreEqual(detailedAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.DetailedAssessmentResultInput.Result)); + Assert.AreEqual(tailorMadeAssembly, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernel.TailorMadeAssessmentResultInput.Result)); + } + } + + [Test] + public void AssembleCombined_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 group = calculator.AssembleCombined( + random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue()); + + // Assert + FailureMechanismSectionAssemblyCategoryGroup expectedResult = AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup( + kernel.FailureMechanismSectionDirectResult.Result); + Assert.AreEqual(expectedResult, group); + } + } + + [Test] + public void AssembleCombined_KernelWithInvalidOutput_ThrowFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + + 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.AssembleCombined( + 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 AssembleCombined_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.AssembleCombined( + 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 AssembleCombined_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.AssembleCombined( + 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 void AssertAssembly(FailureMechanismSectionAssembly assembly, FmSectionAssemblyDirectResult kernelAssemblyResult) + { + Assert.AreEqual(assembly.Group, AssemblyCategoryAssert.GetFailureMechanismSectionCategoryGroup(kernelAssemblyResult.Result)); + + var kernelAssemblyResultWithProbability = kernelAssemblyResult as FmSectionAssemblyDirectResultWithProbability; + Assert.IsNotNull(kernelAssemblyResultWithProbability); + Assert.AreEqual(assembly.Probability, kernelAssemblyResultWithProbability.FailureProbability); + } + + #endregion + + #region Manual Assembly + + [Test] + public void AssembleManualWithProbability_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + double probability = 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.AssembleManual(probability, assemblyCategoriesInput); + + // Assert + Assert.AreEqual(probability, kernel.FailureProbabilityInput); + Assert.AreEqual(EAssessmentResultTypeG2.ResultSpecified, kernel.AssessmentResultTypeG2Input); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleManualWithProbability_WithNaNValue_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.AssembleManual(double.NaN, assemblyCategoriesInput); + + // Assert + Assert.IsNaN(kernel.FailureProbabilityInput); + Assert.AreEqual(EAssessmentResultTypeG2.Gr, kernel.AssessmentResultTypeG2Input); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleManualWithProbability_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.AssembleManual(random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleManualWithProbability_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.AssembleManual(random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleManualWithProbability_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.AssembleManual(random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleManualWithProbability_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.AssembleManual(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 AssembleManualWithLengthEffect_WithValidInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(39); + double probability = random.NextDouble(); + 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.AssembleManual( + probability, + n, + assemblyCategoriesInput); + + // Assert + Assert.AreEqual(probability, kernel.FailureProbabilityInput); + Assert.AreEqual(n, kernel.LengthEffectFactorInput); + Assert.AreEqual(EAssessmentResultTypeG2.ResultSpecified, kernel.AssessmentResultTypeG2Input); + AssertAssemblyCategoriesInput(assemblyCategoriesInput, + categoriesKernel, + kernel); + } + } + + [Test] + public void AssembleManualWithLengthEffect_WithNaNValue_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.AssembleManual(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 AssembleManualWithLengthEffect_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.AssembleManual(random.NextDouble(), random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + AssertCalculatorOutput(kernel.FailureMechanismSectionDirectResultWithProbability, assembly); + } + } + + [Test] + public void AssembleManualWithLengthEffect_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.AssembleManual(random.NextDouble(), random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleManualWithLengthEffect_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.AssembleManual(random.NextDouble(), random.NextDouble(), CreateAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void AssembleManualWithLengthEffect_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.AssembleManual(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); + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,141 @@ +// 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 NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators +{ + [TestFixture] + public class AssemblyToolCalculatorFactoryTest + { + [Test] + public void Instance_Always_ReturnsAnInstance() + { + // Call + IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; + + // Assert + Assert.IsInstanceOf(factory); + } + + [Test] + public void Instance_WhenSetToNull_ReturnsNewInstance() + { + // Setup + IAssemblyToolCalculatorFactory firstFactory = AssemblyToolCalculatorFactory.Instance; + AssemblyToolCalculatorFactory.Instance = null; + + // Call + IAssemblyToolCalculatorFactory secondFactory = AssemblyToolCalculatorFactory.Instance; + + // Assert + Assert.AreNotSame(firstFactory, secondFactory); + } + + [Test] + public void Instance_WhenSetToInstance_ReturnsThatInstance() + { + // Setup + var firstFactory = new TestAssemblyToolCalculatorFactory(); + AssemblyToolCalculatorFactory.Instance = firstFactory; + + // Call + IAssemblyToolCalculatorFactory secondFactory = AssemblyToolCalculatorFactory.Instance; + + // Assert + Assert.AreSame(firstFactory, secondFactory); + } + + [Test] + public void CreateAssemblyCategoriesCalculator_WithKernelFactory_ReturnsAssemblyCategoriesCalculator() + { + // Setup + IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; + + using (new AssemblyToolKernelFactoryConfig()) + { + // Call + IAssemblyCategoriesCalculator calculator = factory.CreateAssemblyCategoriesCalculator( + AssemblyToolKernelFactory.Instance); + + // Assert + Assert.IsInstanceOf(calculator); + } + } + + [Test] + public void CreateFailureMechanismSectionAssemblyCalculator_WithKernelFactory_ReturnsFailureMechanismSectionAssemblyCalculator() + { + // Setup + IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; + + using (new AssemblyToolKernelFactoryConfig()) + { + // Call + IFailureMechanismSectionAssemblyCalculator calculator = + factory.CreateFailureMechanismSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + // Assert + Assert.IsInstanceOf(calculator); + } + } + + [Test] + public void CreateFailureMechanismAssemblyCalculator_WithKernelFactory_ReturnsFailureMechanismAssemblyCalculator() + { + // Setup + IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; + + using (new AssemblyToolKernelFactoryConfig()) + { + // Call + IFailureMechanismAssemblyCalculator calculator = + factory.CreateFailureMechanismAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + // Assert + Assert.IsInstanceOf(calculator); + } + } + + [Test] + public void CreateAssessmentSectionAssemblyCalculator_WithKernelFactory_ReturnsAssessmentSectionAssemblyCalculator() + { + // Setup + IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; + + using (new AssemblyToolKernelFactoryConfig()) + { + // Call + IAssessmentSectionAssemblyCalculator calculator = + factory.CreateAssessmentSectionAssemblyCalculator(AssemblyToolKernelFactory.Instance); + + // Assert + Assert.IsInstanceOf(calculator); + } + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorExceptionTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorExceptionTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorExceptionTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,31 @@ +// 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.Categories; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Categories +{ + [TestFixture] + public class AssemblyCategoriesCalculatorExceptionTest : CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,487 @@ +// 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 Assembly.Kernel.Exceptions; +using Assembly.Kernel.Model.CategoryLimits; +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.Categories; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.Creators; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Categories +{ + [TestFixture] + public class AssemblyCategoriesCalculatorTest + { + [Test] + public void Constructor_FactoryNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new AssemblyCategoriesCalculator(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("factory", exception.ParamName); + } + + [Test] + public void Constructor_ValidParameters_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var factory = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var calculator = new AssemblyCategoriesCalculator(factory); + + // Assert + Assert.IsInstanceOf(calculator); + mocks.VerifyAll(); + } + + [Test] + public void CalculateAssessmentSectionCategories_WithInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(11); + double lowerLimitNorm = random.NextDouble(0.5, 1.0); + double signalingNorm = random.NextDouble(0.0, 0.5); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.AssessmentSectionCategoriesOutput = CategoriesListTestFactory.CreateAssessmentSectionCategories(); + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + calculator.CalculateAssessmentSectionCategories(signalingNorm, lowerLimitNorm); + + // Assert + Assert.AreEqual(lowerLimitNorm, kernel.LowerLimitNorm); + Assert.AreEqual(signalingNorm, kernel.SignalingNorm); + } + } + + [Test] + public void CalculateAssessmentSectionCategories_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() + { + // Setup + var random = new Random(11); + double lowerLimitNorm = random.NextDouble(0.5, 1.0); + double signalingNorm = random.NextDouble(0.0, 0.5); + CategoriesList output = CategoriesListTestFactory.CreateAssessmentSectionCategories(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.AssessmentSectionCategoriesOutput = output; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + IEnumerable result = calculator.CalculateAssessmentSectionCategories(signalingNorm, lowerLimitNorm); + + // Assert + AssemblyCategoryAssert.AssertAssessmentSectionAssemblyCategories(output, result); + } + } + + [Test] + public void CalculateAssessmentSectionCategories_KernelThrowsException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + var random = new Random(11); + double lowerLimitNorm = random.NextDouble(0.5, 1.0); + double signalingNorm = random.NextDouble(0.0, 0.5); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateAssessmentSectionCategories(signalingNorm, lowerLimitNorm); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void CalculateAssessmentSectionCategories_KernelThrowsAssemblyException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + var random = new Random(11); + double lowerLimitNorm = random.NextDouble(0.5, 1.0); + double signalingNorm = random.NextDouble(0.0, 0.5); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowAssemblyExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateAssessmentSectionCategories(signalingNorm, lowerLimitNorm); + + // 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 CalculateFailureMechanismCategories_WithInput_InputCorrectlySetToKernel() + { + // Setup + AssemblyCategoriesInput assemblyCategoriesInput = CreateRandomAssemblyCategoriesInput(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismCategories(); + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + calculator.CalculateFailureMechanismCategories(assemblyCategoriesInput); + + // Assert + Assert.AreEqual(assemblyCategoriesInput.LowerLimitNorm, kernel.LowerLimitNorm); + Assert.AreEqual(assemblyCategoriesInput.SignalingNorm, kernel.SignalingNorm); + Assert.AreEqual(assemblyCategoriesInput.FailureMechanismContribution, kernel.FailureMechanismContribution); + Assert.AreEqual(assemblyCategoriesInput.N, kernel.N); + } + } + + [Test] + public void CalculateFailureMechanismCategories_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() + { + // Setup + CategoriesList output = CategoriesListTestFactory.CreateFailureMechanismCategories(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismCategoriesOutput = output; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + IEnumerable result = calculator.CalculateFailureMechanismCategories( + CreateRandomAssemblyCategoriesInput()); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismAssemblyCategories(output, result); + } + } + + [Test] + public void CalculateFailureMechanismCategories_KernelThrowsException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateFailureMechanismCategories( + CreateRandomAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void CalculateFailureMechanismCategories_KernelThrowsAssemblyException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowAssemblyExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateFailureMechanismCategories( + CreateRandomAssemblyCategoriesInput()); + + // 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 CalculateFailureMechanismSectionCategories_WithInput_InputCorrectlySetToKernel() + { + // Setup + AssemblyCategoriesInput assemblyCategoriesInput = CreateRandomAssemblyCategoriesInput(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories(); + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + calculator.CalculateFailureMechanismSectionCategories(assemblyCategoriesInput); + + // Assert + Assert.AreEqual(assemblyCategoriesInput.LowerLimitNorm, kernel.LowerLimitNorm); + Assert.AreEqual(assemblyCategoriesInput.SignalingNorm, kernel.SignalingNorm); + Assert.AreEqual(assemblyCategoriesInput.FailureMechanismContribution, kernel.FailureMechanismContribution); + Assert.AreEqual(assemblyCategoriesInput.N, kernel.N); + } + } + + [Test] + public void CalculateFailureMechanismSectionCategories_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() + { + // Setup + CategoriesList output = CategoriesListTestFactory.CreateFailureMechanismSectionCategories(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = output; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + IEnumerable result = calculator.CalculateFailureMechanismSectionCategories( + CreateRandomAssemblyCategoriesInput()); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismSectionAssemblyCategories(output, result); + } + } + + [Test] + public void CalculateFailureMechanismSectionCategories_KernelThrowsException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateFailureMechanismSectionCategories( + CreateRandomAssemblyCategoriesInput()); + + // Assert + var exception = Assert.Throws(test); + Assert.IsNotNull(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void CalculateFailureMechanismSectionCategories_KernelThrowsAssemblyException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowAssemblyExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateFailureMechanismSectionCategories( + CreateRandomAssemblyCategoriesInput()); + + // 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 CalculateGeotechnicalFailureMechanismSectionCategories_WithInput_InputCorrectlySetToKernel() + { + // Setup + var random = new Random(21); + double normativeNorm = random.NextDouble(); + double failureMechanismN = random.NextDouble(1, 10); + double failureMechanismContribution = random.NextDouble(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = CategoriesListTestFactory.CreateFailureMechanismSectionCategories(); + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + calculator.CalculateGeotechnicalFailureMechanismSectionCategories(normativeNorm, + failureMechanismN, + failureMechanismContribution); + + // Assert + Assert.AreEqual(normativeNorm, kernel.AssessmentSectionNorm); + Assert.AreEqual(failureMechanismContribution, kernel.FailureMechanismContribution); + Assert.AreEqual(failureMechanismN, kernel.N); + } + } + + [Test] + public void CalculateGeotechnicalFailureMechanismSectionCategories_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() + { + // Setup + var random = new Random(21); + CategoriesList output = CategoriesListTestFactory.CreateFailureMechanismSectionCategories(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = output; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + IEnumerable result = calculator.CalculateGeotechnicalFailureMechanismSectionCategories( + random.NextDouble(), + random.NextDouble(1, 10), + random.NextDouble()); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismSectionAssemblyCategories(output, result); + } + } + + [Test] + public void CalculateGeotechnicalFailureMechanismSectionCategories_KernelThrowsException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + var random = new Random(21); + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateGeotechnicalFailureMechanismSectionCategories( + 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 CalculateGeotechnicalFailureMechanismSectionCategories_KernelThrowsAssemblyException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + var random = new Random(21); + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowAssemblyExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateGeotechnicalFailureMechanismSectionCategories( + 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); + } + } + + private static AssemblyCategoriesInput CreateRandomAssemblyCategoriesInput() + { + var random = new Random(11); + return new AssemblyCategoriesInput(random.NextDouble(1, 5), + 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/Creators/AssemblyCalculatorInputCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCalculatorInputCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCalculatorInputCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,68 @@ +// 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.ComponentModel; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssemblyCalculatorInputCreatorTest + { + [Test] + public void CreateFailureMechanismSectionCategory_WithInvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssemblyCalculatorInputCreator.CreateFailureMechanismSectionCategory( + (FailureMechanismSectionAssemblyCategoryGroup) 99); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyCategoryGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.NotApplicable, EFmSectionCategory.NotApplicable)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.None, EFmSectionCategory.Gr)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Iv, EFmSectionCategory.Iv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIv, EFmSectionCategory.IIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIIv, EFmSectionCategory.IIIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IVv, EFmSectionCategory.IVv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Vv, EFmSectionCategory.Vv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIv, EFmSectionCategory.VIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIIv, EFmSectionCategory.VIIv)] + public void CreateFailureMechanismSectionCategory_WithValidGroup_ReturnEFmSectionCategory( + FailureMechanismSectionAssemblyCategoryGroup originalGroup, + EFmSectionCategory expectedGroup) + { + // Call + EFmSectionCategory actualGroup = AssemblyCalculatorInputCreator.CreateFailureMechanismSectionCategory( + originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, actualGroup); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyCategoryCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,284 @@ +// 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.Model; +using Assembly.Kernel.Model.CategoryLimits; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssemblyCategoryCreatorTest + { + [Test] + public void CreateAssessmentSectionAssemblyCategories_CategoriesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("categories", exception.ParamName); + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_WithAssessmentSectionCategories_ReturnAssessmentSectionAssemblyCategories() + { + // Setup + var random = new Random(11); + + var categories = new CategoriesList(new[] + { + new AssessmentSectionCategory(random.NextEnumValue(), 0, 0.25), + new AssessmentSectionCategory(random.NextEnumValue(), 0.25, 0.5), + new AssessmentSectionCategory(random.NextEnumValue(), 0.5, 0.75), + new AssessmentSectionCategory(random.NextEnumValue(), 0.75, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(categories); + + // Assert + AssemblyCategoryAssert.AssertAssessmentSectionAssemblyCategories(categories, result); + } + + [Test] + public void CreateAssessmentSectionAssemblyCategories_CategoryWithInvalidAssessmentGrade_ThrowsInvalidEnumArgumentException() + { + // Setup + var categories = new CategoriesList(new[] + { + new AssessmentSectionCategory((EAssessmentGrade) 99, 0, 1) + }); + + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(categories); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EAssessmentGrade'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCaseSource(typeof(AssessmentGradeConversionTestHelper), nameof(AssessmentGradeConversionTestHelper.AsssementGradeConversionCases))] + public void CreateAssessmentSectionAssemblyCategories_CategoryWithValidAssessmentGrade_ExpectedAssessmentSectionAssemblyCategoryResultType( + EAssessmentGrade categoryGroup, + AssessmentSectionAssemblyCategoryGroup expectedCategoryGroup) + { + // Setup + var categories = new CategoriesList(new[] + { + new AssessmentSectionCategory(categoryGroup, 0, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategories(categories); + + // Assert + Assert.AreEqual(expectedCategoryGroup, result.Single().Group); + } + + [Test] + public void CreateAssessmentSectionAssemblyCategoryGroup_WithInvalidAssessmentGrade_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory((EAssessmentGrade) 99); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EAssessmentGrade'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCaseSource(typeof(AssessmentGradeConversionTestHelper), nameof(AssessmentGradeConversionTestHelper.AsssementGradeConversionCases))] + public void CreateAssessmentSectionAssemblyCategory_WithValidAssessmentGrade_ExpectedAssessmentSectionAssemblyCategoryResultType( + EAssessmentGrade categoryGroup, + AssessmentSectionAssemblyCategoryGroup expectedCategoryGroup) + { + // Call + AssessmentSectionAssemblyCategoryGroup categoryResult = AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory(categoryGroup); + + // Assert + Assert.AreEqual(expectedCategoryGroup, categoryResult); + } + + [Test] + public void CreateFailureMechanismAssemblyCategories_CategoriesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryCreator.CreateFailureMechanismAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("categories", exception.ParamName); + } + + [Test] + public void CreateFailureMechanismAssemblyCategories_WithCategories_ReturnFailureMechanismAssemblyCategoryResult() + { + // Setup + var random = new Random(11); + + var categories = new CategoriesList(new[] + { + new FailureMechanismCategory(random.NextEnumValue(), 0, 0.25), + new FailureMechanismCategory(random.NextEnumValue(), 0.25, 0.5), + new FailureMechanismCategory(random.NextEnumValue(), 0.5, 0.75), + new FailureMechanismCategory(random.NextEnumValue(), 0.75, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateFailureMechanismAssemblyCategories(categories); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismAssemblyCategories(categories, result); + } + + [Test] + public void CreateFailureMechanismAssemblyCategories_CategoryWithInvalidFailureMechanismCategory_ThrowsInvalidEnumArgumentException() + { + // Setup + var categories = new CategoriesList(new[] + { + new FailureMechanismCategory((EFailureMechanismCategory) 99, 0, 1) + }); + + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateFailureMechanismAssemblyCategories(categories); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EFailureMechanismCategory'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCase(EFailureMechanismCategory.It, FailureMechanismAssemblyCategoryGroup.It)] + [TestCase(EFailureMechanismCategory.IIt, FailureMechanismAssemblyCategoryGroup.IIt)] + [TestCase(EFailureMechanismCategory.IIIt, FailureMechanismAssemblyCategoryGroup.IIIt)] + [TestCase(EFailureMechanismCategory.IVt, FailureMechanismAssemblyCategoryGroup.IVt)] + [TestCase(EFailureMechanismCategory.Vt, FailureMechanismAssemblyCategoryGroup.Vt)] + [TestCase(EFailureMechanismCategory.VIt, FailureMechanismAssemblyCategoryGroup.VIt)] + [TestCase(EFailureMechanismCategory.VIIt, FailureMechanismAssemblyCategoryGroup.VIIt)] + [TestCase(EFailureMechanismCategory.Nvt, FailureMechanismAssemblyCategoryGroup.NotApplicable)] + [TestCase(EFailureMechanismCategory.Gr, FailureMechanismAssemblyCategoryGroup.None)] + public void CreateFailureMechanismAssemblyCategories_CategoryWithValidFailureMechanismCategory_ExpectedFailureMechanismAssemblyCategoryResultType( + EFailureMechanismCategory categoryGroup, + FailureMechanismAssemblyCategoryGroup expectedCategoryGroup) + { + // Setup + var categories = new CategoriesList(new[] + { + new FailureMechanismCategory(categoryGroup, 0, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateFailureMechanismAssemblyCategories(categories); + + // Assert + Assert.AreEqual(expectedCategoryGroup, result.Single().Group); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyCategories_CategoriesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyCategoryCreator.CreateFailureMechanismSectionAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("categories", exception.ParamName); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyCategories_WithCategories_ReturnFailureMechanismSectionAssemblyCategoryResult() + { + // Setup + var random = new Random(11); + + var categories = new CategoriesList(new[] + { + new FmSectionCategory(random.NextEnumValue(), 0, 0.25), + new FmSectionCategory(random.NextEnumValue(), 0.25, 0.5), + new FmSectionCategory(random.NextEnumValue(), 0.5, 0.75), + new FmSectionCategory(random.NextEnumValue(), 0.75, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateFailureMechanismSectionAssemblyCategories(categories); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismSectionAssemblyCategories(categories, result); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyCategories_CategoryWithInvalidFailureMechanismSectionCategory_ThrowsInvalidEnumArgumentException() + { + // Setup + var categories = new CategoriesList(new[] + { + new FmSectionCategory((EFmSectionCategory) 99, 0, 1) + }); + + // Call + TestDelegate test = () => AssemblyCategoryCreator.CreateFailureMechanismSectionAssemblyCategories(categories); + + // Assert + const string exceptionMessage = "The value of argument 'category' (99) is invalid for Enum type 'EFmSectionCategory'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + + [Test] + [TestCase(EFmSectionCategory.Iv, FailureMechanismSectionAssemblyCategoryGroup.Iv)] + [TestCase(EFmSectionCategory.IIv, FailureMechanismSectionAssemblyCategoryGroup.IIv)] + [TestCase(EFmSectionCategory.IIIv, FailureMechanismSectionAssemblyCategoryGroup.IIIv)] + [TestCase(EFmSectionCategory.IVv, FailureMechanismSectionAssemblyCategoryGroup.IVv)] + [TestCase(EFmSectionCategory.Vv, FailureMechanismSectionAssemblyCategoryGroup.Vv)] + [TestCase(EFmSectionCategory.VIv, FailureMechanismSectionAssemblyCategoryGroup.VIv)] + [TestCase(EFmSectionCategory.VIIv, FailureMechanismSectionAssemblyCategoryGroup.VIIv)] + [TestCase(EFmSectionCategory.NotApplicable, FailureMechanismSectionAssemblyCategoryGroup.NotApplicable)] + [TestCase(EFmSectionCategory.Gr, FailureMechanismSectionAssemblyCategoryGroup.None)] + public void CreateFailureMechanismSectionAssemblyCategories_CategoryWithValidFailureMechanismSectionCategory_ExpectedFailureMechanismSectionAssemblyCategoryResultType( + EFmSectionCategory categoryGroup, + FailureMechanismSectionAssemblyCategoryGroup expectedCategoryGroup) + { + // Setup + var categories = new CategoriesList(new[] + { + new FmSectionCategory(categoryGroup, 0, 1) + }); + + // Call + IEnumerable result = AssemblyCategoryCreator.CreateFailureMechanismSectionAssemblyCategories(categories); + + // Assert + Assert.AreEqual(expectedCategoryGroup, result.Single().Group); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyErrorMessageCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyErrorMessageCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyErrorMessageCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,133 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssemblyErrorMessageCreatorTest + { + [Test] + public void CreateErrorMessage_ErrorMessagesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => AssemblyErrorMessageCreator.CreateErrorMessage(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("errorMessages", exception.ParamName); + } + + [Test] + public void CreateErrorMessage_InvalidAssemblyError_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssemblyErrorMessageCreator.CreateErrorMessage(new[] + { + new AssemblyErrorMessage(string.Empty, (EAssemblyErrors) 9999) + }); + + // Assert + string expectedMessage = $"The value of argument 'assemblyError' (9999) is invalid for Enum type '{nameof(EAssemblyErrors)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(EAssemblyErrors.SignallingLimitOutOfRange, "Signaleringskans moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.LowerLimitOutOfRange, "Ondergrens moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.FailurePropbabilityMarginOutOfRange, "Faalkansruimte moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.LengthEffectFactorOutOfRange, "Lengte-effect factor moet minimaal 1 zijn.")] + [TestCase(EAssemblyErrors.SectionLengthOutOfRange, "De trajectlengte moet groter zijn dan 0 [m].")] + [TestCase(EAssemblyErrors.SignallingLimitAboveLowerLimit, "De signaleringskans moet kleiner zijn dan de ondergrens.")] + [TestCase(EAssemblyErrors.PsigDsnAbovePsig, "Berekende signaleringskans per doorsnede is groter dan de signaleringskans van het traject.")] + [TestCase(EAssemblyErrors.PlowDsnAbovePlow, "Berekende ondergrens per doorsnede is groter dan de ondergrens van het traject.")] + [TestCase(EAssemblyErrors.LowerLimitIsAboveUpperLimit, "De categoriebovengrens moet boven de categorieondergrens liggen.")] + [TestCase(EAssemblyErrors.CategoryLowerLimitOutOfRange, "Categoriebovengrens moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.CategoryUpperLimitOutOfRange, "Categorieondergrens moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.TranslateAssessmentInvalidInput, "Er is een ongeldig resultaat gespecificeerd voor de gebruikte methode.")] + [TestCase(EAssemblyErrors.ValueMayNotBeNull, "Er is ongeldige invoer gedefinieerd voor de gebruikte methode.")] + [TestCase(EAssemblyErrors.CategoryNotAllowed, "Het specificeren van een toetsoordeel voor deze categorie is niet mogelijk.")] + [TestCase(EAssemblyErrors.DoesNotComplyAfterComply, "Een lagere categorie moet als voldoende worden aangemerkt indien het vak aan een hogere categorie voldoet.")] + [TestCase(EAssemblyErrors.FmSectionLengthInvalid, "Gezamenlijke lengte van alle deelvakken moet gelijk zijn aan de trajectlengte.")] + [TestCase(EAssemblyErrors.FmSectionSectionStartEndInvalid, "De lengte van een berekende deelvak kon niet goed worden bepaald.")] + [TestCase(EAssemblyErrors.FailureProbabilityOutOfRange, "De gespecificeerde kans moet in het bereik [0,1] liggen.")] + [TestCase(EAssemblyErrors.InputNotTheSameType, "De resultaten voor alle vakken moeten allen wel of geen kansspecificatie bevatten.")] + [TestCase(EAssemblyErrors.FailureMechanismAssemblerInputInvalid, "Er moet een vakindeling zijn geïmporteerd.")] + [TestCase(EAssemblyErrors.CommonFailureMechanismSectionsInvalid, "Ieder relevant toetsspoor moet een vakindeling geïmporteerd hebben.")] + [TestCase(EAssemblyErrors.CommonFailureMechanismSectionsNotConsecutive, "Alle (deel)vakken moeten minimaal een lengte hebben van 0.01 [m].")] + [TestCase(EAssemblyErrors.RequestedPointOutOfRange, "De gespecificeerde resultaten voor een of meerdere toetssporen dekken niet de volledige lengte van het traject.")] + [TestCase(EAssemblyErrors.SectionsWithoutCategory, "Er zijn een of meerdere vakindelingen gevonden die geen categorie hebben.")] + [TestCase(EAssemblyErrors.InvalidCategoryLimits, "De categoriegrenzen zijn niet aaneengesloten en spannen niet de volldige faalskansruimte.")] + public void CreateErrorMessage_SingleAssemblyError_ReturnsExpectedErrorMessage(EAssemblyErrors assemblyError, string expectedErrorMessage) + { + // Call + string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(new[] + { + new AssemblyErrorMessage(string.Empty, assemblyError) + }); + + // Assert + Assert.AreEqual(expectedErrorMessage, errorMessage); + } + + [Test] + public void CreateErrorMessage_MultipleAssemblyErrors_ReturnsExpectedErrorMessage() + { + // Call + string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(new[] + { + new AssemblyErrorMessage(string.Empty, EAssemblyErrors.CategoryNotAllowed), + new AssemblyErrorMessage(string.Empty, EAssemblyErrors.FailureProbabilityOutOfRange) + }); + + // Assert + Assert.AreEqual("- Het specificeren van een toetsoordeel voor deze categorie is niet mogelijk.\n" + + "- De gespecificeerde kans moet in het bereik [0,1] liggen.\n", errorMessage); + } + + [Test] + public void CreateErrorMessage_NoAssemblyErrors_ReturnsEmptyErrorMessage() + { + // Call + string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(Enumerable.Empty()); + + // Assert + Assert.IsEmpty(errorMessage); + } + + [Test] + public void CreateGenericErrorMessage_Always_ReturnsExpectedErrorMessage() + { + // Call + string errorMessage = AssemblyErrorMessageCreator.CreateGenericErrorMessage(); + + // Assert + Assert.AreEqual("Er is een onverwachte fout opgetreden tijdens het assembleren.", errorMessage); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssessmentSectionAssemblyInputCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,146 @@ +// 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.Model; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssessmentSectionAssemblyInputCreatorTest + { + private static IEnumerable GetFailureMechanismAssemblyCategoryGroupConversions + { + get + { + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.NotApplicable, EFailureMechanismCategory.Nvt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.None, EFailureMechanismCategory.Gr); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.It, EFailureMechanismCategory.It); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.IIt, EFailureMechanismCategory.IIt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.IIIt, EFailureMechanismCategory.IIIt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.IVt, EFailureMechanismCategory.IVt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.Vt, EFailureMechanismCategory.Vt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.VIt, EFailureMechanismCategory.VIt); + yield return new TestCaseData(FailureMechanismAssemblyCategoryGroup.VIIt, EFailureMechanismCategory.VIIt); + } + } + + [Test] + public void CreateFailureMechanismAssemblyResult_FailureMechanismAssemblyNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("input", exception.ParamName); + } + + [Test] + public void CreateFailureMechanismAssemblyResult_WithFailureMechanismAssemblyAndInvalidEnumInput_ThrowsInvalidEnumArgumentException() + { + // Setup + var random = new Random(21); + var failureMechanismAssembly = new FailureMechanismAssembly(random.NextDouble(), + (FailureMechanismAssemblyCategoryGroup) 99); + + // Call + TestDelegate test = () => AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(failureMechanismAssembly); + + // Assert + const string expectedMessage = "The value of argument 'input' (99) is invalid for Enum type 'FailureMechanismAssemblyCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetFailureMechanismAssemblyCategoryGroupConversions))] + public void CreateFailureMechanismAssemblyResult_WithValidFailureMechanismAssembly_ReturnsFailureMechanismAssemblyResult( + FailureMechanismAssemblyCategoryGroup originalGroup, + EFailureMechanismCategory expectedGroup) + { + // Setup + var random = new Random(21); + var failureMechanismAssembly = new FailureMechanismAssembly(random.NextDouble(), originalGroup); + + // Call + FailureMechanismAssemblyResult result = AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(failureMechanismAssembly); + + // Assert + Assert.AreEqual(expectedGroup, result.Category); + Assert.AreEqual(failureMechanismAssembly.Probability, result.FailureProbability); + } + + [Test] + public void CreateFailureMechanismAssemblyResult_WithInvalidEnumInput_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult((FailureMechanismAssemblyCategoryGroup) 99); + + // Assert + const string expectedMessage = "The value of argument 'input' (99) is invalid for Enum type 'FailureMechanismAssemblyCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetFailureMechanismAssemblyCategoryGroupConversions))] + public void CreateFailureMechanismAssemblyResult_WithValidEnumInput_ReturnsFailureMechanismAssemblyResult( + FailureMechanismAssemblyCategoryGroup originalGroup, + EFailureMechanismCategory expectedGroup) + { + // Call + FailureMechanismAssemblyResult result = AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult(originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, result.Category); + Assert.IsNaN(result.FailureProbability); + } + + [Test] + public void CreateFailureMechanismCategory_WithInvalidEnumInput_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => AssessmentSectionAssemblyInputCreator.CreateFailureMechanismCategory((FailureMechanismAssemblyCategoryGroup) 99); + + // Assert + const string expectedMessage = "The value of argument 'input' (99) is invalid for Enum type 'FailureMechanismAssemblyCategoryGroup'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetFailureMechanismAssemblyCategoryGroupConversions))] + public void CreateFailureMechanismCategory_WithValidEnumInput_ReturnsFailureMechanismAssemblyResult( + FailureMechanismAssemblyCategoryGroup originalGroup, + EFailureMechanismCategory expectedGroup) + { + // Call + EFailureMechanismCategory result = AssessmentSectionAssemblyInputCreator.CreateFailureMechanismCategory(originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, result); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,98 @@ +// 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 Assembly.Kernel.Model; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class CombinedFailureMechanismSectionAssemblyCreatorTest + { + [Test] + public void Create_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => CombinedFailureMechanismSectionAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithResult_ReturnCombinedFailureMechanismSectionAssemblies() + { + // Setup + var random = new Random(21); + + var sections = new[] + { + new Tuple(0, 2), + new Tuple(2, 5), + new Tuple(5, random.NextDouble(5, 6)) + }; + + var failureMechanismResults = new[] + { + new FailureMechanismSectionList(string.Empty, new[] + { + CreateCategory(sections[0], random), + CreateCategory(sections[1], random), + CreateCategory(sections[2], random) + }), + new FailureMechanismSectionList(string.Empty, new[] + { + CreateCategory(sections[0], random), + CreateCategory(sections[1], random), + CreateCategory(sections[2], random) + }) + }; + + FmSectionWithDirectCategory[] combinedResults = + { + CreateCategory(sections[0], random), + CreateCategory(sections[1], random), + CreateCategory(sections[2], random) + }; + + var assembly = new AssemblyResult(failureMechanismResults, combinedResults); + + // Call + IEnumerable results = CombinedFailureMechanismSectionAssemblyCreator.Create(assembly); + + // Assert + CombinedFailureMechanismSectionAssemblyAssert.AssertAssembly(assembly, results); + } + + private static FmSectionWithDirectCategory CreateCategory(Tuple section, Random random) + { + return new FmSectionWithDirectCategory(section.Item1, section.Item2, random.NextEnumValue()); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismAssemblyCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,117 @@ +// 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.Model; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class FailureMechanismAssemblyCreatorTest + { + [Test] + public void Create_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FailureMechanismAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Setup + var result = new FailureMechanismAssemblyResult((EFailureMechanismCategory) 99, new Random(39).NextDouble()); + + // Call + TestDelegate test = () => FailureMechanismAssemblyCreator.Create(result); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(EFailureMechanismCategory)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(FailureMechanismAssemblyCategoryGroupCases))] + public void Create_ValidResult_ReturnFailureMechanismAssembly(EFailureMechanismCategory originalGroup, + FailureMechanismAssemblyCategoryGroup expectedGroup) + { + // Setup + var random = new Random(39); + double probability = random.NextDouble(); + + var result = new FailureMechanismAssemblyResult(originalGroup, probability); + + // Call + FailureMechanismAssembly assembly = FailureMechanismAssemblyCreator.Create(result); + + // Assert + Assert.AreEqual(expectedGroup, assembly.Group); + Assert.AreEqual(probability, assembly.Probability); + } + + [Test] + public void CreateFailureMechanismAssemblyCategoryGroup_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup((EFailureMechanismCategory) 99); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(EFailureMechanismCategory)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(FailureMechanismAssemblyCategoryGroupCases))] + public void CreateFailureMechanismAssemblyCategoryGroup_ValidGroup_ReturnFailureMechanismAssemblyCategoryGroup( + EFailureMechanismCategory originalGroup, + FailureMechanismAssemblyCategoryGroup expectedGroup) + { + // Call + FailureMechanismAssemblyCategoryGroup actualGroup = FailureMechanismAssemblyCreator.CreateFailureMechanismAssemblyCategoryGroup(originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, actualGroup); + } + + private static IEnumerable FailureMechanismAssemblyCategoryGroupCases() + { + yield return new TestCaseData(EFailureMechanismCategory.Gr, FailureMechanismAssemblyCategoryGroup.None); + yield return new TestCaseData(EFailureMechanismCategory.Nvt, FailureMechanismAssemblyCategoryGroup.NotApplicable); + yield return new TestCaseData(EFailureMechanismCategory.It, FailureMechanismAssemblyCategoryGroup.It); + yield return new TestCaseData(EFailureMechanismCategory.IIt, FailureMechanismAssemblyCategoryGroup.IIt); + yield return new TestCaseData(EFailureMechanismCategory.IIIt, FailureMechanismAssemblyCategoryGroup.IIIt); + yield return new TestCaseData(EFailureMechanismCategory.IVt, FailureMechanismAssemblyCategoryGroup.IVt); + yield return new TestCaseData(EFailureMechanismCategory.Vt, FailureMechanismAssemblyCategoryGroup.Vt); + yield return new TestCaseData(EFailureMechanismCategory.VIt, FailureMechanismAssemblyCategoryGroup.VIt); + yield return new TestCaseData(EFailureMechanismCategory.VIIt, FailureMechanismAssemblyCategoryGroup.VIIt); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCalculatorInputCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCalculatorInputCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCalculatorInputCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,468 @@ +// 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.Model; +using Assembly.Kernel.Model.AssessmentResultTypes; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Primitives; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class FailureMechanismSectionAssemblyCalculatorInputCreatorTest + { + #region Simple Assessment + + [Test] + public void CreateAssessmentResultTypeE1_WithInvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE1((SimpleAssessmentResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'input' (99) is invalid for Enum type '{nameof(SimpleAssessmentResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(SimpleAssessmentResultType.None, EAssessmentResultTypeE1.Gr)] + [TestCase(SimpleAssessmentResultType.NotApplicable, EAssessmentResultTypeE1.Nvt)] + [TestCase(SimpleAssessmentResultType.ProbabilityNegligible, EAssessmentResultTypeE1.Fv)] + [TestCase(SimpleAssessmentResultType.AssessFurther, EAssessmentResultTypeE1.Vb)] + public void CreateAssessmentResultTypeE1_ValidData_ReturnsAssessmentResultTypeE1(SimpleAssessmentResultType originalResult, + EAssessmentResultTypeE1 expectedResult) + { + // Call + EAssessmentResultTypeE1 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE1(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CreateAssessmentResultTypeE2_WithInvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE2((SimpleAssessmentValidityOnlyResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'input' (99) is invalid for Enum type '{nameof(SimpleAssessmentValidityOnlyResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(SimpleAssessmentValidityOnlyResultType.None, EAssessmentResultTypeE2.Gr)] + [TestCase(SimpleAssessmentValidityOnlyResultType.NotApplicable, EAssessmentResultTypeE2.Nvt)] + [TestCase(SimpleAssessmentValidityOnlyResultType.Applicable, EAssessmentResultTypeE2.Wvt)] + public void CreateAssessmentResultTypeE2_ValidData_ReturnsAssessmentResultTypeE2( + SimpleAssessmentValidityOnlyResultType originalResult, + EAssessmentResultTypeE2 expectedResult) + { + // Call + EAssessmentResultTypeE2 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeE2(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + #endregion + + #region Detailed Assessment + + [Test] + [TestCaseSource(nameof(InvalidDetailedAssessmentCategoryResults))] + public void CreateCategoryCompliancyResults_InvalidEnumInput_ThrowInvalidEnumArgumentException( + DetailedAssessmentResultType detailedAssessmentResultForFactorizedSignalingNorm, + DetailedAssessmentResultType detailedAssessmentResultForSignalingNorm, + DetailedAssessmentResultType detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + DetailedAssessmentResultType detailedAssessmentResultForLowerLimitNorm, + DetailedAssessmentResultType detailedAssessmentResultForFactorizedLowerLimitNorm) + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateCategoryCompliancyResults( + detailedAssessmentResultForFactorizedSignalingNorm, + detailedAssessmentResultForSignalingNorm, + detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + detailedAssessmentResultForLowerLimitNorm, + detailedAssessmentResultForFactorizedLowerLimitNorm); + + // Assert + string expectedMessage = $"The value of argument 'detailedAssessmentResult' (99) is invalid for Enum type '{nameof(DetailedAssessmentResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void CreateCategoryCompliancyResults_ValidInput_ReturnsFmSectionCategoryCompliancyResults() + { + // 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(); + + // Call + FmSectionCategoryCompliancyResults result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateCategoryCompliancyResults( + detailedAssessmentResultForFactorizedSignalingNorm, + detailedAssessmentResultForSignalingNorm, + detailedAssessmentResultForMechanismSpecificLowerLimitNorm, + detailedAssessmentResultForLowerLimitNorm, + detailedAssessmentResultForFactorizedLowerLimitNorm); + + // Assert + Dictionary results = result.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 CreateAssessmentResultTypeG1_InvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG1((DetailedAssessmentResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'detailedAssessmentResult' (99) is invalid for Enum type '{nameof(DetailedAssessmentResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(DetailedAssessmentResultType.None, EAssessmentResultTypeG1.Gr)] + [TestCase(DetailedAssessmentResultType.Insufficient, EAssessmentResultTypeG1.Vn)] + [TestCase(DetailedAssessmentResultType.Sufficient, EAssessmentResultTypeG1.V)] + [TestCase(DetailedAssessmentResultType.NotAssessed, EAssessmentResultTypeG1.Ngo)] + public void CreateAssessmentResultTypeG1_ValidInput_ReturnsAssessmentResultTypeG1(DetailedAssessmentResultType originalResult, + EAssessmentResultTypeG1 expectedResult) + { + // Call + EAssessmentResultTypeG1 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG1(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CreateAssessmentResultTypeG2_InvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG2( + (DetailedAssessmentProbabilityOnlyResultType) 99); + + // Assert + string expectedMessage = "The value of argument 'detailedAssessmentResult' (99) is invalid for Enum type " + + $"'{nameof(DetailedAssessmentProbabilityOnlyResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(DetailedAssessmentProbabilityOnlyResultType.Probability, EAssessmentResultTypeG2.ResultSpecified)] + [TestCase(DetailedAssessmentProbabilityOnlyResultType.NotAssessed, EAssessmentResultTypeG2.Ngo)] + public void CreateAssessmentResultTypeG2_ValidInput_ReturnsAssessmentResultTypeG2( + DetailedAssessmentProbabilityOnlyResultType originalResult, + EAssessmentResultTypeG2 expectedResult) + { + // Call + EAssessmentResultTypeG2 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeG2(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + 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(); + } + } + + private static IEnumerable InvalidDetailedAssessmentCategoryResults + { + get + { + var random = new Random(39); + yield return new TestCaseData((DetailedAssessmentResultType) 99, + random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue()) + .SetName($"DetailedAssessmentResultForFactorizedSignalingNorm invalid {nameof(DetailedAssessmentResultType)}"); + yield return new TestCaseData(random.NextEnumValue(), + (DetailedAssessmentResultType) 99, + random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue()) + .SetName($"DetailedAssessmentResultForSignalingNorm invalid {nameof(DetailedAssessmentResultType)}"); + yield return new TestCaseData(random.NextEnumValue(), + random.NextEnumValue(), + (DetailedAssessmentResultType) 99, + random.NextEnumValue(), + random.NextEnumValue()) + .SetName($"DetailedAssessmentResultForMechanismSpecificLowerLimitNorm invalid {nameof(DetailedAssessmentResultType)}"); + yield return new TestCaseData(random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue(), + (DetailedAssessmentResultType) 99, + random.NextEnumValue()) + .SetName($"DetailedAssessmentResultForLowerLimitNorm invalid {nameof(DetailedAssessmentResultType)}"); + yield return new TestCaseData(random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue(), + random.NextEnumValue(), + (DetailedAssessmentResultType) 99) + .SetName($"DetailedAssessmentResultForFactorizedLowerLimitNorm invalid {nameof(DetailedAssessmentResultType)}"); + } + } + + #endregion + + #region Failure Mechanism Section Assembly + + [Test] + public void CreateFailureMechanismSectionAssemblyDirectResult_AssemblyNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateFailureMechanismSectionAssemblyDirectResult(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assembly", exception.ParamName); + } + + [Test] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.NotApplicable, EFmSectionCategory.NotApplicable)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.None, EFmSectionCategory.Gr)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Iv, EFmSectionCategory.Iv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIv, EFmSectionCategory.IIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIIv, EFmSectionCategory.IIIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IVv, EFmSectionCategory.IVv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Vv, EFmSectionCategory.Vv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIv, EFmSectionCategory.VIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIIv, EFmSectionCategory.VIIv)] + public void CreateFailureMechanismSectionAssemblyDirectResult_WithAssembly_ReturnFmSectionAssemblyDirectResult( + FailureMechanismSectionAssemblyCategoryGroup originalGroup, + EFmSectionCategory expectedGroup) + { + // Setup + var random = new Random(11); + var assembly = new FailureMechanismSectionAssembly(random.NextDouble(), originalGroup); + + // Call + FmSectionAssemblyDirectResultWithProbability input = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateFailureMechanismSectionAssemblyDirectResult( + assembly); + + // Assert + Assert.AreEqual(assembly.Probability, input.FailureProbability); + Assert.AreEqual(expectedGroup, input.Result); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyDirectResult_WithInvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateFailureMechanismSectionAssemblyDirectResult( + new FailureMechanismSectionAssembly(0, (FailureMechanismSectionAssemblyCategoryGroup) 99)); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyCategoryGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.NotApplicable, EFmSectionCategory.NotApplicable)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.None, EFmSectionCategory.Gr)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Iv, EFmSectionCategory.Iv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIv, EFmSectionCategory.IIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIIv, EFmSectionCategory.IIIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IVv, EFmSectionCategory.IVv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Vv, EFmSectionCategory.Vv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIv, EFmSectionCategory.VIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIIv, EFmSectionCategory.VIIv)] + public void CreateFailureMechanismSectionAssemblyDirectResult_WithValidGroup_ReturnFmSectionAssemblyDirectResult( + FailureMechanismSectionAssemblyCategoryGroup originalGroup, + EFmSectionCategory expectedGroup) + { + // Call + FmSectionAssemblyDirectResult actualResult = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateFailureMechanismSectionAssemblyDirectResult( + originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, actualResult.Result); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyDirectResult_WithInvalidGroup_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateFailureMechanismSectionAssemblyDirectResult( + (FailureMechanismSectionAssemblyCategoryGroup) 99); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyCategoryGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + #endregion + + #region Tailor Made Assessment + + [Test] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.None, EAssessmentResultTypeT3.Gr, null)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.Iv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.Iv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.IIv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.IIv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.IIIv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.IIIv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.IVv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.IVv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.Vv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.Vv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.VIv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.VIv)] + [TestCase(TailorMadeAssessmentCategoryGroupResultType.VIIv, EAssessmentResultTypeT3.ResultSpecified, EFmSectionCategory.VIIv)] + public void CreateAssessmentResultTypeT3WithCategoryGroupResult_ValidGroup_ReturnsExpectedItems( + TailorMadeAssessmentCategoryGroupResultType originalGroup, + EAssessmentResultTypeT3 expectedResult, + EFmSectionCategory? expectedGroup) + { + // Call + Tuple actualGroup = + FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3WithCategoryGroupResult(originalGroup); + + // Assert + Assert.AreEqual(expectedResult, actualGroup.Item1); + Assert.AreEqual(expectedGroup, actualGroup.Item2); + } + + [Test] + public void CreateAssessmentResultTypeT3WithCategoryGroupResult_InvalidGroup_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3WithCategoryGroupResult( + (TailorMadeAssessmentCategoryGroupResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'tailorMadeAssessmentResult' (99) is invalid for Enum type '{nameof(TailorMadeAssessmentCategoryGroupResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void CreateAssessmentResultTypeT1_InvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT1((TailorMadeAssessmentResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'tailorMadeAssessmentResult' (99) is invalid for Enum type '{nameof(TailorMadeAssessmentResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(TailorMadeAssessmentResultType.None, EAssessmentResultTypeT1.Gr)] + [TestCase(TailorMadeAssessmentResultType.ProbabilityNegligible, EAssessmentResultTypeT1.Fv)] + [TestCase(TailorMadeAssessmentResultType.Insufficient, EAssessmentResultTypeT1.Vn)] + [TestCase(TailorMadeAssessmentResultType.Sufficient, EAssessmentResultTypeT1.V)] + [TestCase(TailorMadeAssessmentResultType.NotAssessed, EAssessmentResultTypeT1.Ngo)] + public void CreateAssessmentResultTypeT1_ValidInput_ReturnsAssessmentResultTypeT1( + TailorMadeAssessmentResultType originalResult, + EAssessmentResultTypeT1 expectedResult) + { + // Call + EAssessmentResultTypeT1 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT1(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CreateAssessmentResultTypeT3_InvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3((TailorMadeAssessmentProbabilityCalculationResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'tailorMadeAssessmentResult' (99) is invalid for Enum type '{nameof(TailorMadeAssessmentProbabilityCalculationResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.None, EAssessmentResultTypeT3.Gr)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.ProbabilityNegligible, EAssessmentResultTypeT3.Fv)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.Probability, EAssessmentResultTypeT3.ResultSpecified)] + [TestCase(TailorMadeAssessmentProbabilityCalculationResultType.NotAssessed, EAssessmentResultTypeT3.Ngo)] + public void CreateAssessmentResultTypeT3_ValidInput_ReturnsAssessmentResultTypeT3( + TailorMadeAssessmentProbabilityCalculationResultType originalResult, + EAssessmentResultTypeT3 expectedResult) + { + // Call + EAssessmentResultTypeT3 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT3(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + [Test] + public void CreateAssessmentResultTypeT4_InvalidEnumInput_ThrowInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT4((TailorMadeAssessmentProbabilityAndDetailedCalculationResultType) 99); + + // Assert + string expectedMessage = $"The value of argument 'tailorMadeAssessmentResult' (99) is invalid for Enum type '{nameof(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.None, EAssessmentResultTypeT4.Gr)] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.ProbabilityNegligible, EAssessmentResultTypeT4.Fv)] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.Probability, EAssessmentResultTypeT4.ResultSpecified)] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.Sufficient, EAssessmentResultTypeT4.V)] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.Insufficient, EAssessmentResultTypeT4.Vn)] + [TestCase(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.NotAssessed, EAssessmentResultTypeT4.Ngo)] + public void CreateAssessmentResultTypeT4_ValidInput_ReturnsAssessmentResultTypeT4( + TailorMadeAssessmentProbabilityAndDetailedCalculationResultType originalResult, + EAssessmentResultTypeT4 expectedResult) + { + // Call + EAssessmentResultTypeT4 result = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateAssessmentResultTypeT4(originalResult); + + // Assert + Assert.AreEqual(expectedResult, result); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionAssemblyCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,168 @@ +// 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 Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class FailureMechanismSectionAssemblyCreatorTest + { + [Test] + public void Create_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FailureMechanismSectionAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Setup + var result = new FmSectionAssemblyDirectResult((EFmSectionCategory) 99); + + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCreator.Create(result); + + // Assert + const string expectedMessage = "The value of argument 'category' (99) is invalid for Enum type 'EFmSectionCategory'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(EFmSectionCategory.Gr, FailureMechanismSectionAssemblyCategoryGroup.None)] + [TestCase(EFmSectionCategory.NotApplicable, FailureMechanismSectionAssemblyCategoryGroup.NotApplicable)] + [TestCase(EFmSectionCategory.Iv, FailureMechanismSectionAssemblyCategoryGroup.Iv)] + [TestCase(EFmSectionCategory.IIv, FailureMechanismSectionAssemblyCategoryGroup.IIv)] + [TestCase(EFmSectionCategory.IIIv, FailureMechanismSectionAssemblyCategoryGroup.IIIv)] + [TestCase(EFmSectionCategory.IVv, FailureMechanismSectionAssemblyCategoryGroup.IVv)] + [TestCase(EFmSectionCategory.Vv, FailureMechanismSectionAssemblyCategoryGroup.Vv)] + [TestCase(EFmSectionCategory.VIv, FailureMechanismSectionAssemblyCategoryGroup.VIv)] + [TestCase(EFmSectionCategory.VIIv, FailureMechanismSectionAssemblyCategoryGroup.VIIv)] + public void Create_ValidResult_ReturnExpectedFailureMechanismSectionAssembly( + EFmSectionCategory originalGroup, + FailureMechanismSectionAssemblyCategoryGroup expectedGroup) + { + // Call + FailureMechanismSectionAssembly assembly = FailureMechanismSectionAssemblyCreator.Create( + new FmSectionAssemblyDirectResult(originalGroup)); + + // Assert + Assert.AreEqual(expectedGroup, assembly.Group); + Assert.IsNaN(assembly.Probability); + } + + [Test] + public void CreateWithFmSectionAssemblyDirectResultWithProbability_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FailureMechanismSectionAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void CreateWithFmSectionAssemblyDirectResultWithProbability_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Setup + var result = new FmSectionAssemblyDirectResultWithProbability((EFmSectionCategory) 99, new Random(39).NextDouble()); + + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCreator.Create(result); + + // Assert + const string expectedMessage = "The value of argument 'category' (99) is invalid for Enum type 'EFmSectionCategory'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(EFmSectionCategory.Gr, FailureMechanismSectionAssemblyCategoryGroup.None)] + [TestCase(EFmSectionCategory.NotApplicable, FailureMechanismSectionAssemblyCategoryGroup.NotApplicable)] + [TestCase(EFmSectionCategory.Iv, FailureMechanismSectionAssemblyCategoryGroup.Iv)] + [TestCase(EFmSectionCategory.IIv, FailureMechanismSectionAssemblyCategoryGroup.IIv)] + [TestCase(EFmSectionCategory.IIIv, FailureMechanismSectionAssemblyCategoryGroup.IIIv)] + [TestCase(EFmSectionCategory.IVv, FailureMechanismSectionAssemblyCategoryGroup.IVv)] + [TestCase(EFmSectionCategory.Vv, FailureMechanismSectionAssemblyCategoryGroup.Vv)] + [TestCase(EFmSectionCategory.VIv, FailureMechanismSectionAssemblyCategoryGroup.VIv)] + [TestCase(EFmSectionCategory.VIIv, FailureMechanismSectionAssemblyCategoryGroup.VIIv)] + public void CreateWithFmSectionAssemblyDirectResultWithProbability_ValidResult_ReturnFailureMechanismSectionAssembly( + EFmSectionCategory originalGroup, + FailureMechanismSectionAssemblyCategoryGroup expectedGroup) + { + // Setup + var random = new Random(39); + double probability = random.NextDouble(); + + var result = new FmSectionAssemblyDirectResultWithProbability(originalGroup, probability); + + // Call + FailureMechanismSectionAssembly assembly = FailureMechanismSectionAssemblyCreator.Create(result); + + // Assert + Assert.AreEqual(expectedGroup, assembly.Group); + Assert.AreEqual(probability, assembly.Probability); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyCategoryGroup_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup((EFmSectionCategory) 99); + + // Assert + const string expectedMessage = "The value of argument 'category' (99) is invalid for Enum type 'EFmSectionCategory'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(EFmSectionCategory.Gr, FailureMechanismSectionAssemblyCategoryGroup.None)] + [TestCase(EFmSectionCategory.NotApplicable, FailureMechanismSectionAssemblyCategoryGroup.NotApplicable)] + [TestCase(EFmSectionCategory.Iv, FailureMechanismSectionAssemblyCategoryGroup.Iv)] + [TestCase(EFmSectionCategory.IIv, FailureMechanismSectionAssemblyCategoryGroup.IIv)] + [TestCase(EFmSectionCategory.IIIv, FailureMechanismSectionAssemblyCategoryGroup.IIIv)] + [TestCase(EFmSectionCategory.IVv, FailureMechanismSectionAssemblyCategoryGroup.IVv)] + [TestCase(EFmSectionCategory.Vv, FailureMechanismSectionAssemblyCategoryGroup.Vv)] + [TestCase(EFmSectionCategory.VIv, FailureMechanismSectionAssemblyCategoryGroup.VIv)] + [TestCase(EFmSectionCategory.VIIv, FailureMechanismSectionAssemblyCategoryGroup.VIIv)] + public void CreateFailureMechanismSectionAssemblyCategoryGroup_ValidGroup_ReturnFailureMechanismSectionAssemblyCategoryGroup( + EFmSectionCategory originalGroup, + FailureMechanismSectionAssemblyCategoryGroup expectedGroup) + { + // Call + FailureMechanismSectionAssemblyCategoryGroup actualGroup = FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup(originalGroup); + + // Assert + Assert.AreEqual(expectedGroup, actualGroup); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionListCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionListCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/FailureMechanismSectionListCreatorTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,113 @@ +// 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.Model; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class FailureMechanismSectionListCreatorTest + { + [Test] + public void Create_FailureMechanismSectionsCollectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => FailureMechanismSectionListCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanismSectionsCollection", exception.ParamName); + } + + [Test] + public void Create_WithFailureMechanism_ReturnFailureMechanismSectionLists() + { + // Setup + var random = new Random(21); + var combinedAssemblyFailureMechanismInputs = new[] + { + new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue()), + new CombinedAssemblyFailureMechanismSection(1, 2, random.NextEnumValue()) + } + }; + + // Call + IEnumerable failureMechanismSectionLists = FailureMechanismSectionListCreator.Create(combinedAssemblyFailureMechanismInputs); + + // Assert + CombinedFailureMechanismSectionsInputAssert.AssertCombinedFailureMechanismInput(combinedAssemblyFailureMechanismInputs, failureMechanismSectionLists); + } + + [Test] + public void Create_InvalidGroup_ThrowsInvalidEnumArgumentException() + { + // Call + TestDelegate test = () => FailureMechanismSectionListCreator.Create(new[] + { + new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, (FailureMechanismSectionAssemblyCategoryGroup) 99) + } + }); + + // Assert + string expectedMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(FailureMechanismSectionAssemblyCategoryGroup)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.None, EFmSectionCategory.Gr)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.NotApplicable, EFmSectionCategory.NotApplicable)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Iv, EFmSectionCategory.Iv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIv, EFmSectionCategory.IIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IIIv, EFmSectionCategory.IIIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.IVv, EFmSectionCategory.IVv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.Vv, EFmSectionCategory.Vv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIv, EFmSectionCategory.VIv)] + [TestCase(FailureMechanismSectionAssemblyCategoryGroup.VIIv, EFmSectionCategory.VIIv)] + public void Create_ValidGroup_ReturnEFmSectionCategory(FailureMechanismSectionAssemblyCategoryGroup originalGroup, EFmSectionCategory expectedGroup) + { + // Call + IEnumerable output = FailureMechanismSectionListCreator.Create(new[] + { + new[] + { + new CombinedAssemblyFailureMechanismSection(0, 1, originalGroup) + } + }); + + // Assert + Assert.AreEqual(expectedGroup, ((FmSectionWithDirectCategory) output.Single().Sections.Single()).Category); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Kernels/AssemblyToolKernelFactoryTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Kernels/AssemblyToolKernelFactoryTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Kernels/AssemblyToolKernelFactoryTest.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,136 @@ +// 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 Assembly.Kernel.Implementations; +using Assembly.Kernel.Interfaces; +using NUnit.Framework; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Kernels; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Kernels +{ + [TestFixture] + public class AssemblyToolKernelFactoryTest + { + [Test] + public void Instance_Always_ReturnsAnInstance() + { + // Call + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Assert + Assert.IsInstanceOf(factory); + } + + [Test] + public void Instance_WhenSetToNull_ReturnsNewInstance() + { + // Setup + IAssemblyToolKernelFactory firstFactory = AssemblyToolKernelFactory.Instance; + AssemblyToolKernelFactory.Instance = null; + + // Call + IAssemblyToolKernelFactory secondFactory = AssemblyToolKernelFactory.Instance; + + // Assert + Assert.AreNotSame(firstFactory, secondFactory); + } + + [Test] + public void Instance_WhenSetToInstance_ReturnsThatInstance() + { + // Setup + var firstFactory = new TestAssemblyToolKernelFactory(); + AssemblyToolKernelFactory.Instance = firstFactory; + + // Call + IAssemblyToolKernelFactory secondFactory = AssemblyToolKernelFactory.Instance; + + // Assert + Assert.AreSame(firstFactory, secondFactory); + } + + [Test] + public void CreateAssemblyCategoriesKernel_Always_ReturnsKernelCategoryLimitsCalculator() + { + // Setup + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Call + ICategoryLimitsCalculator assemblyCategoriesKernel = factory.CreateAssemblyCategoriesKernel(); + + // Assert + Assert.IsInstanceOf(assemblyCategoriesKernel); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyKernel_Always_ReturnsKernelAssessmentResultsTranslator() + { + // Setup + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Call + IAssessmentResultsTranslator kernel = factory.CreateFailureMechanismSectionAssemblyKernel(); + + // Assert + Assert.IsInstanceOf(kernel); + } + + [Test] + public void CreateFailureMechanismAssemblyKernel_Always_ReturnsKernelFailureMechanismResultAssembler() + { + // Setup + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Call + IFailureMechanismResultAssembler kernel = factory.CreateFailureMechanismAssemblyKernel(); + + // Assert + Assert.IsInstanceOf(kernel); + } + + [Test] + public void CreateAssessmentSectionAssemblyKernel_Always_ReturnsKernelAssessmentGradeAssembler() + { + // Setup + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Call + IAssessmentGradeAssembler kernel = factory.CreateAssessmentSectionAssemblyKernel(); + + // Assert + Assert.IsInstanceOf(kernel); + } + + [Test] + public void CreateCombinedFailureMechanismSectionAssemblyKernel_Always_ReturnsKernelCommonFailureMechanismSectionAssembler() + { + // Setup + IAssemblyToolKernelFactory factory = AssemblyToolKernelFactory.Instance; + + // Call + ICommonFailureMechanismSectionAssembler kernel = factory.CreateCombinedFailureMechanismSectionAssemblyKernel(); + + // Assert + Assert.IsInstanceOf(kernel); + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Properties/AssemblyInfo.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Properties/AssemblyInfo.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Properties/AssemblyInfo.cs (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,25 @@ +// 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.Reflection; + +[assembly: AssemblyTitle("Riskeer.AssemblyTool.KernelWrapper.Test")] +[assembly: AssemblyProduct("Riskeer.AssemblyTool.KernelWrapper.Test")] \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Riskeer.AssemblyTool.KernelWrapper.Test.csproj =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Riskeer.AssemblyTool.KernelWrapper.Test.csproj (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Riskeer.AssemblyTool.KernelWrapper.Test.csproj (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,72 @@ + + + + {41A89DD5-0F97-4B9F-9C17-7960600C2738} + Riskeer.AssemblyTool.KernelWrapper.Test + Riskeer.AssemblyTool.KernelWrapper.Test + + + + + ..\..\..\..\lib\Plugins\AssemblyTool\Assembly.Kernel.dll + + + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Copying.licenseheader + + + + + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + + + {78AA56F5-431D-465C-AC50-3173D7E90AC1} + Ringtoets.Common.Primitives + + + {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} + Riskeer.AssemblyTool.Data + + + {358B6DA2-A1DF-477F-B6AC-C30204265CB0} + Riskeer.AssemblyTool.KernelWrapper + + + {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38} + Ringtoets.AssemblyTool.KernelWrapper.TestUtil + + + \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/packages.config =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/packages.config (revision 0) +++ Ringtoets/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/packages.config (revision a56e082357533e893e2a2c49d99e2a92eea956d1) @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file