Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -rfae43a9590e1fd964bd37cdcdf62b4d7f8a00b15 -r02670d8c9fceeaea5f829937a2eb269f3488c6b1 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision fae43a9590e1fd964bd37cdcdf62b4d7f8a00b15) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 02670d8c9fceeaea5f829937a2eb269f3488c6b1) @@ -27,13 +27,11 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Service.MessageProviders; -using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data.Input; using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics; -using Ringtoets.HydraRing.Calculation.Data.Output; using Ringtoets.HydraRing.Calculation.Parsers; -using Ringtoets.HydraRing.Calculation.Services; -using Ringtoets.HydraRing.Calculation.TestUtil; +using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.HydraRing.Data; namespace Ringtoets.Common.Service.Test @@ -45,25 +43,20 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); [Test] - public void Constructor_ExpectedValues() - { - // Call - var service = new DesignWaterLevelCalculationService(); - - // Assert - Assert.IsInstanceOf>(service); - } - - [Test] public void Validate_ValidHydraulicBoundaryDatabasePath_ReturnsTrue() { // Setup const string calculationName = "calculationName"; string validFilePath = Path.Combine(testDataPath, validFile); bool valid = false; + var mockRepository = new MockRepository(); + ICalculationMessageProvider messageProvider = mockRepository.Stub(); + messageProvider.Stub(mp => mp.GetCalculationName(calculationName)).Return(calculationName); + mockRepository.ReplayAll(); + // Call - Action call = () => valid = DesignWaterLevelCalculationService.Instance.Validate(calculationName, validFilePath); + Action call = () => valid = new DesignWaterLevelCalculationService().Validate(calculationName, validFilePath, messageProvider); // Assert TestHelper.AssertLogMessages(call, messages => @@ -74,6 +67,7 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[1]); }); Assert.IsTrue(valid); + mockRepository.VerifyAll(); } [Test] @@ -84,8 +78,13 @@ string notValidFilePath = Path.Combine(testDataPath, "notexisting.sqlite"); bool valid = false; + var mockRepository = new MockRepository(); + ICalculationMessageProvider messageProviderStub = mockRepository.Stub(); + messageProviderStub.Stub(mp => mp.GetCalculationName(calculationName)).Return(calculationName); + mockRepository.ReplayAll(); + // Call - Action call = () => valid = DesignWaterLevelCalculationService.Instance.Validate(calculationName, notValidFilePath); + Action call = () => valid = new DesignWaterLevelCalculationService().Validate(calculationName, notValidFilePath, messageProviderStub); // Assert TestHelper.AssertLogMessages(call, messages => @@ -97,6 +96,7 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[2]); }); Assert.IsFalse(valid); + mockRepository.VerifyAll(); } [Test] @@ -107,47 +107,45 @@ const string locationName = "punt_flw_ 1"; const string calculationName = "locationName"; - const string calculationFailedMessage = "calculationFailedMessage"; + const string calculationNotConvergedMessage = "calculationNotConvergedMessage"; const string ringId = "ringId"; const double norm = 30; var mockRepository = new MockRepository(); - var calculationMessageProviderMock = mockRepository.StrictMock(); - calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName); - calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return(calculationFailedMessage); + var calculationMessageProviderMock = mockRepository.Stub(); + 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) { DesignWaterLevel = new RoundedDouble(2, double.NaN) }; - using (new HydraRingCalculationServiceConfig()) + using (new HydraRingCalculatorFactoryConfig()) { - var testService = (TestHydraRingCalculationService) HydraRingCalculationService.Instance; + var testFactory = (TestHydraRingCalculatorFactory)HydraRingCalculatorFactory.Instance; + var testCalculator = testFactory.DesignWaterLevelCalculator; // Call - DesignWaterLevelCalculationService.Instance.Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, ringId, norm, calculationMessageProviderMock); // Assert - Assert.AreEqual(testDataPath, testService.HlcdDirectory); - Assert.AreEqual(ringId, testService.RingId); - Assert.AreEqual(HydraRingUncertaintiesType.All, testService.UncertaintiesType); - var parsers = testService.Parsers.ToArray(); - Assert.AreEqual(1, parsers.Length); - Assert.IsInstanceOf(parsers[0]); + Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); + Assert.AreEqual(ringId, testCalculator.RingId); + var expectedInput = CreateInput(hydraulicBoundaryLocation, norm); - AssertInput(expectedInput, testService.HydraRingCalculationInput); + AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); } mockRepository.VerifyAll(); } [Test] - public void Calculate_CalculationOutputNull_LogError() + public void Calculate_CalculationFails_LogError() { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -169,15 +167,30 @@ DesignWaterLevel = new RoundedDouble(2, double.NaN) }; - ReliabilityIndexCalculationOutput output = null; - using (new HydraRingCalculationServiceConfig()) + using (new HydraRingCalculatorFactoryConfig()) { + var testFactory = (TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance; + var testCalculator = testFactory.DesignWaterLevelCalculator; + testCalculator.EndInFailure = true; + bool exceptionThrown = false; + // Call - Action call = () => output = DesignWaterLevelCalculationService.Instance.Calculate(hydraulicBoundaryLocation, - validFilePath, - ringId, - norm, - calculationMessageProviderMock); + Action call = () => + { + try + { + new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + validFilePath, + ringId, + norm, + calculationMessageProviderMock); + } + catch (HydraRingFileParserException) + { + exceptionThrown = true; + } + }; + // Assert TestHelper.AssertLogMessages(call, messages => @@ -188,7 +201,8 @@ StringAssert.StartsWith(calculationFailedMessage, msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[2]); }); - Assert.IsNull(output); + Assert.IsTrue(exceptionThrown); + Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); } mockRepository.VerifyAll(); }