Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs =================================================================== diff -u -r7abb391b5067105a9026a89b6076bf0b8b9315a3 -r5ff4beaae608500063af4819df1e32df7c5542b5 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision 7abb391b5067105a9026a89b6076bf0b8b9315a3) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision 5ff4beaae608500063af4819df1e32df7c5542b5) @@ -168,7 +168,13 @@ const double norm = 1.0 / 30; var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0); + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + Converged = true + }; + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProvider = mockRepository.Stub(); calculationMessageProvider.Stub(calc => calc.GetActivityName(locationName)).Return(activityName); calculationMessageProvider.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); @@ -179,11 +185,8 @@ norm, calculationMessageProvider); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator testDesignWaterLevelCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - testDesignWaterLevelCalculator.Converged = true; - // Call Action call = () => activity.Run(); @@ -202,7 +205,6 @@ AssessmentLevelCalculationInput designWaterLevelCalculationInput = testDesignWaterLevelCalculator.ReceivedInputs.First(); Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); - Assert.AreEqual(testDataPath, testDesignWaterLevelCalculator.HydraulicBoundaryDatabaseDirectory); Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(norm), designWaterLevelCalculationInput.Beta); } Assert.AreEqual(ActivityState.Executed, activity.State); @@ -249,29 +251,32 @@ { // Setup const string locationName = "locationName 1"; + const double norm = 1.0 / 30; + const double expectedDesignWaterLevel = 3.5; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0); + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + DesignWaterLevel = expectedDesignWaterLevel, + Converged = true + }; + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Expect(calc => calc.GetActivityName(locationName)).Return(string.Empty); calculationMessageProvider.Expect(calc => calc.GetCalculationName(locationName)).Return(string.Empty).Repeat.AtLeastOnce(); mockRepository.ReplayAll(); string validFilePath = Path.Combine(testDataPath, validFile); - const double norm = 1.0 / 30; - const double expectedDesignWaterLevel = 3.5; - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, validFilePath, norm, calculationMessageProvider); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator testDesignWaterLevelCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - testDesignWaterLevelCalculator.DesignWaterLevel = expectedDesignWaterLevel; - testDesignWaterLevelCalculator.Converged = true; - // Call activity.Run(); } @@ -289,6 +294,14 @@ const string locationName = "locationName"; const string calculationFailedMessage = "Something went wrong"; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + EndInFailure = true, + LastErrorFileContent = calculationFailedMessage + }; + + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProvider = mockRepository.Stub(); calculationMessageProvider.Stub(calc => calc.GetActivityName(locationName)).Return(string.Empty); calculationMessageProvider.Stub(calc => calc.GetCalculationName(locationName)).Return(string.Empty); @@ -308,12 +321,8 @@ 30, calculationMessageProvider); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.EndInFailure = true; - calculator.LastErrorFileContent = calculationFailedMessage; - // Call Action call = () => activity.Run(); @@ -333,6 +342,13 @@ const string activityName = "getActivityName"; const string calculationNotConvergedMessage = "GetCalculatedNotConvergedMessage"; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + Converged = false + }; + + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Expect(calc => calc.GetActivityName(locationName)).Return(activityName); calculationMessageProvider.Expect(calc => calc.GetCalculationName(locationName)).Return("GetCalculationName").Repeat.AtLeastOnce(); @@ -353,11 +369,8 @@ norm, calculationMessageProvider); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.Converged = false; - Action call = () => activity.Run(); // Assert @@ -388,6 +401,14 @@ double.NaN, CalculationConvergence.NotCalculated) }; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + EndInFailure = endInFailure, + LastErrorFileContent = lastErrorFileContent + }; + + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Stub(calc => calc.GetActivityName(locationName)).Return(locationName); calculationMessageProvider.Stub(calc => calc.GetCalculationName(locationName)).Return(locationName); @@ -404,12 +425,8 @@ norm, calculationMessageProvider); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.EndInFailure = endInFailure; - calculator.LastErrorFileContent = lastErrorFileContent; - // Call activity.Run(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r5ff4beaae608500063af4819df1e32df7c5542b5 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 5ff4beaae608500063af4819df1e32df7c5542b5) @@ -154,30 +154,30 @@ const string calculationNotConvergedMessage = "calculationNotConvergedMessage"; const double norm = 1.0 / 30; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator(); + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProviderStub = mockRepository.Stub(); calculationMessageProviderStub.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderStub.Stub(calc => calc.GetCalculatedNotConvergedMessage(locationName)).Return(calculationNotConvergedMessage); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator testCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - // Call new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, norm, calculationMessageProviderStub); // Assert - Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); - AssessmentLevelCalculationInput expectedInput = CreateInput(hydraulicBoundaryLocation, norm); - AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); - Assert.IsFalse(testCalculator.IsCanceled); + AssertInput(expectedInput, testDesignWaterLevelCalculator.ReceivedInputs.First()); + Assert.IsFalse(testDesignWaterLevelCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -188,20 +188,22 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator(); + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProviderStub = mockRepository.Stub(); mockRepository.ReplayAll(); const double norm = 1.0 / 30; var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, "punt_flw_ 1", 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator testCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - var service = new DesignWaterLevelCalculationService(); - testCalculator.CalculationFinishedHandler += (s, e) => service.Cancel(); + testDesignWaterLevelCalculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call service.Calculate(hydraulicBoundaryLocation, @@ -210,7 +212,7 @@ calculationMessageProviderStub); // Assert - Assert.IsTrue(testCalculator.IsCanceled); + Assert.IsTrue(testDesignWaterLevelCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -226,20 +228,24 @@ const string calculationFailedMessage = "calculationFailedMessage"; const double norm = 1.0 / 30; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + LastErrorFileContent = "An error occurred", + EndInFailure = true + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedMessage(null, null)).IgnoreArguments().Return(calculationFailedMessage); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.LastErrorFileContent = "An error occurred"; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -285,19 +291,23 @@ const string calculationFailedMessage = "calculationFailedUnexplainedMessage"; const double norm = 1.0 / 30; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + EndInFailure = true + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedUnexplainedMessage(locationName)).Return(calculationFailedMessage); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -343,20 +353,24 @@ const string calculationFailedMessage = "calculationFailedMessage"; const double norm = 1.0 / 30; + var testDesignWaterLevelCalculator = new TestDesignWaterLevelCalculator + { + EndInFailure = false, + LastErrorFileContent = "An error occurred" + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(testDesignWaterLevelCalculator); var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedMessage(null, null)).IgnoreArguments().Return(calculationFailedMessage); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestDesignWaterLevelCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DesignWaterLevelCalculator; - calculator.EndInFailure = false; - calculator.LastErrorFileContent = "An error occurred"; - var exceptionThrown = false; string exceptionMessage = string.Empty; @@ -389,7 +403,7 @@ }); Assert.IsTrue(exceptionThrown); Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); - Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); + Assert.AreEqual(testDesignWaterLevelCalculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); }