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(); }