// Copyright (C) Stichting Deltares 2017. 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.Linq; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.Common.Data.AssemblyTool; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Primitives; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.AssemblyFactories; using Ringtoets.Integration.Data.StandAlone.SectionResults; namespace Ringtoets.Integration.Data.Test.StandAlone.AssemblyFactories { [TestFixture] public class MacroStabilityOutwardsFailureMechanismAssemblyFactoryTest { private static void AssertAssemblyCategoriesInput(IAssessmentSection assessmentSection, MacroStabilityOutwardsFailureMechanism failureMechanism, AssemblyCategoriesInput assemblyCategoriesInput) { Assert.AreEqual(assessmentSection.FailureMechanismContribution.SignalingNorm, assemblyCategoriesInput.SignalingNorm); Assert.AreEqual(assessmentSection.FailureMechanismContribution.LowerLimitNorm, assemblyCategoriesInput.LowerLimitNorm); Assert.AreEqual(failureMechanism.Contribution, assemblyCategoriesInput.FailureMechanismContribution); Assert.AreEqual(failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.GetN( failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.SectionLength), assemblyCategoriesInput.N); } #region Simple Assembly [Test] public void AssembleSimpleAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); } [Test] public void AssembleSimpleAssessment_WithSectionResult_SetsInputOnCalculator() { // Setup var random = new Random(21); FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(failureMechanismSection) { SimpleAssessmentResult = random.NextEnumValue() }; using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(sectionResult); // Assert Assert.AreEqual(sectionResult.SimpleAssessmentResult, calculator.SimpleAssessmentInput); } } [Test] public void AssembleSimpleAssessment_AssemblyRan_ReturnsOutput() { // Setup FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(failureMechanismSection); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call FailureMechanismSectionAssemblyCategoryGroup actualOutput = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(sectionResult); // Assert FailureMechanismSectionAssembly calculatorOutput = calculator.SimpleAssessmentAssemblyOutput; Assert.AreEqual(calculatorOutput.Group, actualOutput); } } [Test] public void AssembleSimpleAssessment_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(failureMechanismSection); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculate = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(sectionResult); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); } } #endregion #region Detailed Assembly [Test] public void AssembleDetailedAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( null, new MacroStabilityOutwardsFailureMechanism(), assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleDetailedAssessment_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleDetailedAssessment_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), new MacroStabilityOutwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void AssembleDetailedAssessment_WithInput_SetsInputOnCalculator() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( sectionResult, failureMechanism, assessmentSection); // Assert Assert.AreEqual(sectionResult.DetailedAssessmentResult, calculator.DetailedAssessmentProbabilityOnlyResultInput); Assert.AreEqual(sectionResult.DetailedAssessmentProbability, calculator.DetailedAssessmentProbabilityInput); AssertAssemblyCategoriesInput(assessmentSection, failureMechanism, calculator.AssemblyCategoriesInput); mocks.VerifyAll(); } } [Test] public void AssembleDetailedAssessment_AssemblyRan_ReturnsOutput() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call FailureMechanismSectionAssemblyCategoryGroup actualOutput = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssembly calculatorOutput = calculator.DetailedAssessmentAssemblyOutput; Assert.AreEqual(calculatorOutput.Group, actualOutput); mocks.VerifyAll(); } } [Test] public void AssembleDetailedAssessment_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculate = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( sectionResult, failureMechanism, assessmentSection); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); mocks.VerifyAll(); } } #endregion #region Tailor Made Assembly [Test] public void AssembleTailorMadeAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( null, new MacroStabilityOutwardsFailureMechanism(), assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleTailorMadeAssessment_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleTailorMadeAssessment_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), new MacroStabilityOutwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void AssembleTailorMadeAssessment_WithInput_SetsInputOnCalculator() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( sectionResult, failureMechanism, assessmentSection); // Assert Assert.AreEqual(sectionResult.TailorMadeAssessmentProbability, calculator.TailorMadeAssessmentProbabilityInput); Assert.AreEqual(sectionResult.TailorMadeAssessmentResult, calculator.TailorMadeAssessmentProbabilityAndDetailedCalculationResultInput); AssertAssemblyCategoriesInput(assessmentSection, failureMechanism, calculator.AssemblyCategoriesInput); mocks.VerifyAll(); } } [Test] public void AssembleTailorMadeAssessment_AssemblyRan_ReturnsOutput() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call FailureMechanismSectionAssemblyCategoryGroup actualOutput = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssembly calculatorOutput = calculator.TailorMadeAssessmentAssemblyOutput; Assert.AreEqual(calculatorOutput.Group, actualOutput); mocks.VerifyAll(); } } [Test] public void AssembleTailorMadeAssessment_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculate = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( sectionResult, failureMechanism, assessmentSection); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); mocks.VerifyAll(); } } #endregion #region Combined Assembly [Test] public void AssembleCombinedAssessment_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( null, new MacroStabilityOutwardsFailureMechanism(), assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleCombinedAssessment_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleCombinedAssessment_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), new MacroStabilityOutwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] [TestCase(SimpleAssessmentResultType.None)] [TestCase(SimpleAssessmentResultType.AssessFurther)] public void AssembleCombinedAssessment_WithVariousSimpleAssessmentInputAssemblesWithAllInformation_SetsInputOnCalculator( SimpleAssessmentResultType simpleAssessmentResult) { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { SimpleAssessmentResult = simpleAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(sectionResult); FailureMechanismSectionAssemblyCategoryGroup expectedDetailedAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment(sectionResult, failureMechanism, assessmentSection); FailureMechanismSectionAssemblyCategoryGroup expectedTailorMadeAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(sectionResult, failureMechanism, assessmentSection); Assert.AreEqual(expectedSimpleAssembly, calculator.CombinedSimpleAssemblyGroupInput); Assert.AreEqual(expectedDetailedAssembly, calculator.CombinedDetailedAssemblyGroupInput); Assert.AreEqual(expectedTailorMadeAssembly, calculator.CombinedTailorMadeAssemblyGroupInput); mocks.VerifyAll(); } } [Test] [TestCase(SimpleAssessmentResultType.NotApplicable)] [TestCase(SimpleAssessmentResultType.ProbabilityNegligible)] public void AssembleCombinedAssessment_WithVariousSimpleAssessmentInputAssemblesWithOnlySimpleAssessmentInput_SetsInputOnCalculator( SimpleAssessmentResultType simpleAssessmentResult) { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { SimpleAssessmentResult = simpleAssessmentResult }; using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(sectionResult); Assert.AreEqual(expectedSimpleAssembly, calculator.CombinedSimpleAssemblyGroupInput); Assert.AreEqual((FailureMechanismSectionAssemblyCategoryGroup) 0, calculator.CombinedDetailedAssemblyGroupInput); Assert.AreEqual((FailureMechanismSectionAssemblyCategoryGroup) 0, calculator.CombinedTailorMadeAssemblyGroupInput); mocks.VerifyAll(); } } [Test] public void AssembleCombinedAssessment_AssemblyRan_ReturnsOutput() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call FailureMechanismSectionAssemblyCategoryGroup actualOutput = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup? calculatorOutput = calculator.CombinedAssemblyCategoryOutput; Assert.AreEqual(calculatorOutput, actualOutput); mocks.VerifyAll(); } } [Test] public void AssembleCombinedAssessment_CalculatorThrowsExceptions_ThrowsAssemblyException() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculateCombinedAssembly = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( sectionResult, failureMechanism, assessmentSection); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); mocks.VerifyAll(); } } #endregion #region GetSectionAssemblyCategoryGroup [Test] public void GetSectionAssemblyCategoryGroup_FailureMechanismSectionResultNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( null, new MacroStabilityOutwardsFailureMechanism(), assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismSectionResult", exception.ParamName); mocks.VerifyAll(); } [Test] public void GetSectionAssemblyCategoryGroup_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void GetSectionAssemblyCategoryGroup_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()), new MacroStabilityOutwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void GetSectionAssemblyCategoryGroup_WithoutManualInput_SetsInputOnCalculator() { // Setup var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup expectedSimpleAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment( sectionResult); FailureMechanismSectionAssemblyCategoryGroup expectedDetailedAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment( sectionResult, failureMechanism, assessmentSection); FailureMechanismSectionAssemblyCategoryGroup expectedTailorMadeAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment( sectionResult, failureMechanism, assessmentSection); Assert.AreEqual(expectedSimpleAssembly, calculator.CombinedSimpleAssemblyGroupInput); Assert.AreEqual(expectedDetailedAssembly, calculator.CombinedDetailedAssemblyGroupInput); Assert.AreEqual(expectedTailorMadeAssembly, calculator.CombinedTailorMadeAssemblyGroupInput); mocks.VerifyAll(); } } [Test] public void GetSectionAssemblyCategoryGroup_WithoutManualInput_ReturnsOutput() { // Setup var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { // Call FailureMechanismSectionAssemblyCategoryGroup categoryGroup = MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( sectionResult, failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup expectedAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( sectionResult, failureMechanism, assessmentSection); Assert.AreEqual(categoryGroup, expectedAssembly); mocks.VerifyAll(); } } [Test] public void GetSectionAssemblyCategoryGroup_WithManualInput_ReturnsOutput() { // Setup var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { UseManualAssemblyCategoryGroup = true, ManualAssemblyCategoryGroup = new Random(39).NextEnumValue() }; var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); // Call FailureMechanismSectionAssemblyCategoryGroup categoryGroup = MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( sectionResult, failureMechanism, assessmentSection); // Assert Assert.AreEqual(categoryGroup, sectionResult.ManualAssemblyCategoryGroup); mocks.VerifyAll(); } [Test] public void GetSectionAssemblyCategoryGroup_WithoutManualInputAndCalculatorThrowsException_ThrowsAssemblyException() { // Setup var sectionResult = new MacroStabilityOutwardsFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismSectionAssemblyCalculator; calculator.ThrowExceptionOnCalculateCombinedAssembly = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup( sectionResult, failureMechanism, assessmentSection); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); mocks.VerifyAll(); } } #endregion #region Failure Mechanism Assembly [Test] public void AssembleFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void AssembleFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( new MacroStabilityOutwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void AssembleFailureMechanism_FailureMechanismIsNotRelevant_ReturnsNotApplicableCategory() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism { IsRelevant = false }; var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); // Call FailureMechanismAssemblyCategoryGroup category = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection); // Assert Assert.AreEqual(FailureMechanismAssemblyResultFactory.CreateNotApplicableCategory(), category); mocks.VerifyAll(); } [Test] public void AssembleFailureMechanism_WithoutManualInput_SetsInputOnCalculator() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( failureMechanism, assessmentSection); // Assert FailureMechanismSectionAssemblyCategoryGroup assemblyCategory = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment( failureMechanism.SectionResults.Single(), failureMechanism, assessmentSection); Assert.AreEqual(assemblyCategory, calculator.FailureMechanismSectionCategories.Single()); mocks.VerifyAll(); } } [Test] public void AssembleFailureMechanism_WithManualInput_SetsInputOnCalculator() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); MacroStabilityOutwardsFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults.Single(); sectionResult.UseManualAssemblyCategoryGroup = true; sectionResult.ManualAssemblyCategoryGroup = new Random(39).NextEnumValue(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator; // Call MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( failureMechanism, assessmentSection); // Assert Assert.AreEqual(sectionResult.ManualAssemblyCategoryGroup, calculator.FailureMechanismSectionCategories.Single()); mocks.VerifyAll(); } } [Test] public void AssembleFailureMechanism_AssemblyRan_ReturnsOutput() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismAssemblyCalculator; // Call FailureMechanismAssemblyCategoryGroup actualOutput = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( failureMechanism, assessmentSection); // Assert Assert.AreEqual(calculator.FailureMechanismAssemblyCategoryGroupOutput, actualOutput); mocks.VerifyAll(); } } [Test] public void AssembleFailureMechanism_FailureMechanismCalculatorThrowsException_ThrowsAssemblyException() { // Setup var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator; calculator.ThrowExceptionOnCalculate = true; // Call TestDelegate call = () => MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism( failureMechanism, assessmentSection); // Assert var exception = Assert.Throws(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf(innerException); Assert.AreEqual(innerException.Message, exception.Message); mocks.VerifyAll(); } } #endregion } }