Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -rcdfbf84b1449ce60926c5fefd2a06085bcbefbe9 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision cdfbf84b1449ce60926c5fefd2a06085bcbefbe9) @@ -154,29 +154,29 @@ const string calculationNotConvergedMessage = "calculationNotConvergedMessage"; const double norm = 1.0 / 30; + var testWaveHeightCalculator = new TestWaveHeightCalculator(); + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(testWaveHeightCalculator); var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculatedNotConvergedMessage(locationName)).Return(calculationNotConvergedMessage); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestWaveHeightCalculator testCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveHeightCalculator; - new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, norm, calculationMessageProviderMock); // Assert - Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); - AssessmentLevelCalculationInput expectedInput = CreateInput(hydraulicBoundaryLocation, norm); - AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); - Assert.IsFalse(testCalculator.IsCanceled); + AssertInput(expectedInput, testWaveHeightCalculator.ReceivedInputs.First()); + Assert.IsFalse(testWaveHeightCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -186,20 +186,21 @@ { // Setup string validFilePath = Path.Combine(testDataPath, validFile); + var testWaveHeightCalculator = new TestWaveHeightCalculator(); var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(testWaveHeightCalculator); var calculationMessageProviderStub = mockRepository.Stub(); mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, "punt_flw_ 1", 0, 0); const double norm = 1.0 / 30; - using (new HydraRingCalculatorFactoryConfig()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - TestWaveHeightCalculator testCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveHeightCalculator; - var service = new WaveHeightCalculationService(); - testCalculator.CalculationFinishedHandler += (s, e) => service.Cancel(); + testWaveHeightCalculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call service.Calculate(hydraulicBoundaryLocation, @@ -208,7 +209,7 @@ calculationMessageProviderStub); // Assert - Assert.IsTrue(testCalculator.IsCanceled); + Assert.IsTrue(testWaveHeightCalculator.IsCanceled); } mockRepository.VerifyAll(); } @@ -224,20 +225,24 @@ const string calculationFailedMessage = "calculationFailedMessage"; const double norm = 1.0 / 30; + var testWaveHeightCalculator = new TestWaveHeightCalculator + { + LastErrorFileContent = "An error occurred", + EndInFailure = true + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(testWaveHeightCalculator); 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)) { - TestWaveHeightCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveHeightCalculator; - calculator.LastErrorFileContent = "An error occurred"; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -283,19 +288,23 @@ const string calculationFailedMessage = "calculationFailedUnexplainedMessage"; const double norm = 1.0 / 30; + var testWaveHeightCalculator = new TestWaveHeightCalculator + { + EndInFailure = true + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(testWaveHeightCalculator); 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)) { - TestWaveHeightCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveHeightCalculator; - calculator.EndInFailure = true; - var exceptionThrown = false; // Call @@ -341,20 +350,24 @@ const string calculationFailedMessage = "calculationFailedMessage"; const double norm = 1.0 / 30; + var testWaveHeightCalculator = new TestWaveHeightCalculator + { + LastErrorFileContent = "An error occurred", + EndInFailure = false + }; + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(testWaveHeightCalculator); 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)) { - TestWaveHeightCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveHeightCalculator; - calculator.EndInFailure = false; - calculator.LastErrorFileContent = "An error occurred"; - var exceptionThrown = false; string exceptionMessage = string.Empty; @@ -387,7 +400,6 @@ }); Assert.IsTrue(exceptionThrown); Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); - Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); }