Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj =================================================================== diff -u -r92acb4483676af5adad598c2ea8ca46f9b8379c1 -r47a932015ac8c889b4efadeded6d0acfc533e6c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 47a932015ac8c889b4efadeded6d0acfc533e6c8) @@ -142,6 +142,10 @@ {4843d6e5-066f-4795-94f5-1d53932dd03c} Ringtoets.Common.Data.TestUtil + + {888D4097-8BC2-4703-9FB1-8744C94D525E} + Ringtoets.HydraRing.Calculation + {74CBA865-9338-447F-BAD9-28312446AE84} Ringtoets.HydraRing.Calculation.TestUtil Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r7f8860b7aa23930fb9f49e9a28d8ebb709395cb5 -r47a932015ac8c889b4efadeded6d0acfc533e6c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 7f8860b7aa23930fb9f49e9a28d8ebb709395cb5) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 47a932015ac8c889b4efadeded6d0acfc533e6c8) @@ -44,6 +44,7 @@ using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Data.TestUtil; @@ -767,7 +768,7 @@ // Setup var assessmentSection = mocks.Stub(); var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); - + var foreshoreProfileInput = new TestForeshoreProfile(); var calculation = new StructuresCalculation(); calculation.InputParameters.ForeshoreProfile = foreshoreProfileInput; @@ -978,6 +979,10 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); + + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(new TestStructuresStabilityPointCalculator()); mocks.ReplayAll(); plugin.Gui = gui; @@ -988,7 +993,7 @@ }; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // When Action action = () => contextMenuStrip.Items[contextMenuCalculateIndex].PerformClick(); @@ -998,12 +1003,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(6, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' beëindigd om: ", msgs[1]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[2]); StringAssert.StartsWith("Puntconstructies berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[4]); - StringAssert.StartsWith(string.Format("Uitvoeren van '{0}' is gelukt.", calculation.Name), msgs[5]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[4]); + StringAssert.StartsWith($"Uitvoeren van '{calculation.Name}' is gelukt.", msgs[5]); }); Assert.AreNotSame(initialOutput, calculation.Output); @@ -1065,8 +1070,8 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(2, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculation.Name}' beëindigd om: ", msgs[1]); }); } } Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r7b372ed3506cd00bcf09c6c026e2bf5783868f74 -r47a932015ac8c889b4efadeded6d0acfc533e6c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 7b372ed3506cd00bcf09c6c026e2bf5783868f74) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 47a932015ac8c889b4efadeded6d0acfc533e6c8) @@ -46,6 +46,7 @@ using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms; using Ringtoets.Common.Forms.Helpers; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Data.TestUtil; @@ -1319,6 +1320,13 @@ gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + + int calculators = failureMechanism.Calculations.Count(); + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(new TestStructuresStabilityPointCalculator()) + .Repeat + .Times(calculators); mocks.ReplayAll(); plugin.Gui = gui; @@ -1329,7 +1337,7 @@ }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndexRootGroup].PerformClick(), messages => Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -rff948d4633181ead2677ab35467a93b4118c6751 -r47a932015ac8c889b4efadeded6d0acfc533e6c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision ff948d4633181ead2677ab35467a93b4118c6751) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision 47a932015ac8c889b4efadeded6d0acfc533e6c8) @@ -42,6 +42,7 @@ using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Data.TestUtil; @@ -680,6 +681,13 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); + + int calculators = failureMechanism.Calculations.Count(); + var calculatorFactory = mocksRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(new TestStructuresStabilityPointCalculator()) + .Repeat + .Times(calculators); mocksRepository.ReplayAll(); TreeNodeInfo info = GetInfo(plugin); @@ -691,7 +699,7 @@ }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndex].PerformClick(), messages => Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs =================================================================== diff -u -rff948d4633181ead2677ab35467a93b4118c6751 -r47a932015ac8c889b4efadeded6d0acfc533e6c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs (.../StabilityPointStructuresCalculationServiceTest.cs) (revision ff948d4633181ead2677ab35467a93b4118c6751) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs (.../StabilityPointStructuresCalculationServiceTest.cs) (revision 47a932015ac8c889b4efadeded6d0acfc533e6c8) @@ -784,6 +784,7 @@ var mockRepository = new MockRepository(); var assessmentSectionStub = mockRepository.Stub(); + var calculatorFactory = mockRepository.Stub(); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -797,20 +798,15 @@ var service = new StabilityPointStructuresCalculationService(); // Call - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call TestDelegate call = () => service.Calculate(calculation, assessmentSectionStub, failureMechanism, testDataPath); - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); - // Assert - Assert.AreEqual(0, calculationInputs.Length); const string expectedMessage = "The value of argument 'calculation' (100) is invalid for Enum type 'StabilityPointStructureInflowModelType'."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName; @@ -834,6 +830,8 @@ var mockRepository = new MockRepository(); var assessmentSectionStub = mockRepository.Stub(); + + var calculatorFactory = mockRepository.Stub(); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -847,20 +845,15 @@ var service = new StabilityPointStructuresCalculationService(); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call TestDelegate call = () => service.Calculate(calculation, assessmentSectionStub, failureMechanism, testDataPath); - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); - // Assert - Assert.AreEqual(0, calculationInputs.Length); const string expectedMessage = "The value of argument 'calculation' (100) is invalid for Enum type 'LoadSchematizationType'."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage).ParamName; @@ -880,6 +873,11 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -897,20 +895,17 @@ calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(useBreakWater); } - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call new StabilityPointStructuresCalculationService().Calculate(calculation, assessmentSectionStub, failureMechanism, validFilePath); // Assert - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); + StructuresStabilityPointCalculationInput[] calculationInputs = testStructuresStabilityPointCalculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); - Assert.AreEqual(testDataPath, calculator.HydraulicBoundaryDatabaseDirectory); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; StabilityPointStructuresInput input = calculation.InputParameters; @@ -981,7 +976,7 @@ var actualInput = (StructuresStabilityPointLowSillLinearCalculationInput) calculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.IsFalse(calculator.IsCanceled); + Assert.IsFalse(testStructuresStabilityPointCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -997,6 +992,11 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1014,20 +1014,17 @@ calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(useBreakWater); } - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call new StabilityPointStructuresCalculationService().Calculate(calculation, assessmentSectionStub, failureMechanism, validFilePath); // Assert - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); + StructuresStabilityPointCalculationInput[] calculationInputs = testStructuresStabilityPointCalculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); - Assert.AreEqual(testDataPath, calculator.HydraulicBoundaryDatabaseDirectory); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; StabilityPointStructuresInput input = calculation.InputParameters; @@ -1098,7 +1095,7 @@ var actualInput = (StructuresStabilityPointLowSillQuadraticCalculationInput) calculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.IsFalse(calculator.IsCanceled); + Assert.IsFalse(testStructuresStabilityPointCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -1114,6 +1111,11 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1131,20 +1133,17 @@ calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(useBreakWater); } - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call new StabilityPointStructuresCalculationService().Calculate(calculation, assessmentSectionStub, failureMechanism, validFilePath); // Assert - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); + StructuresStabilityPointCalculationInput[] calculationInputs = testStructuresStabilityPointCalculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); - Assert.AreEqual(testDataPath, calculator.HydraulicBoundaryDatabaseDirectory); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; StabilityPointStructuresInput input = calculation.InputParameters; @@ -1215,7 +1214,7 @@ var actualInput = (StructuresStabilityPointFloodedCulvertLinearCalculationInput) calculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.IsFalse(calculator.IsCanceled); + Assert.IsFalse(testStructuresStabilityPointCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -1231,6 +1230,11 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1248,20 +1252,17 @@ calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(useBreakWater); } - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - // Call new StabilityPointStructuresCalculationService().Calculate(calculation, assessmentSectionStub, failureMechanism, validFilePath); // Assert - StructuresStabilityPointCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); + StructuresStabilityPointCalculationInput[] calculationInputs = testStructuresStabilityPointCalculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); - Assert.AreEqual(testDataPath, calculator.HydraulicBoundaryDatabaseDirectory); GeneralStabilityPointStructuresInput generalInput = failureMechanism.GeneralInput; StabilityPointStructuresInput input = calculation.InputParameters; @@ -1332,7 +1333,7 @@ var actualInput = (StructuresStabilityPointFloodedCulvertQuadraticCalculationInput) calculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.IsFalse(calculator.IsCanceled); + Assert.IsFalse(testStructuresStabilityPointCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -1354,6 +1355,10 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(new TestStructuresStabilityPointCalculator()); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1385,7 +1390,7 @@ } // Call - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { Action call = () => new StabilityPointStructuresCalculationService().Calculate(calculation, assessmentSectionStub, @@ -1420,6 +1425,11 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1432,11 +1442,10 @@ } }; - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; var service = new StabilityPointStructuresCalculationService(); - calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); + testStructuresStabilityPointCalculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call service.Calculate(calculation, @@ -1446,7 +1455,7 @@ // Assert Assert.IsNull(calculation.Output); - Assert.IsTrue(calculator.IsCanceled); + Assert.IsTrue(testStructuresStabilityPointCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -1465,6 +1474,14 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator + { + LastErrorFileContent = "An error occurred", + EndInFailure = true + }; + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1476,12 +1493,8 @@ } }; - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - calculator.LastErrorFileContent = "An error occurred"; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -1529,6 +1542,13 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator + { + EndInFailure = true + }; + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1540,11 +1560,8 @@ } }; - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -1592,6 +1609,13 @@ var mockRepository = new MockRepository(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); + var testStructuresStabilityPointCalculator = new TestStructuresStabilityPointCalculator + { + LastErrorFileContent = "An error occurred" + }; + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresStabilityPointCalculator(testDataPath)) + .Return(testStructuresStabilityPointCalculator); mockRepository.ReplayAll(); var calculation = new TestStabilityPointStructuresCalculation @@ -1603,12 +1627,8 @@ } }; - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestStructuresStabilityPointCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresStabilityPointCalculator; - calculator.EndInFailure = false; - calculator.LastErrorFileContent = "An error occurred"; - var exceptionThrown = false; string exceptionMessage = string.Empty; @@ -1640,7 +1660,7 @@ }); Assert.IsTrue(exceptionThrown); Assert.IsNull(calculation.Output); - Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); + Assert.AreEqual(testStructuresStabilityPointCalculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); }