Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r02670d8c9fceeaea5f829937a2eb269f3488c6b1 -re90324ad44fdf6e7af3a755239246727123a1591 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 02670d8c9fceeaea5f829937a2eb269f3488c6b1) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision e90324ad44fdf6e7af3a755239246727123a1591) @@ -124,27 +124,76 @@ using (new HydraRingCalculatorFactoryConfig()) { - var testFactory = (TestHydraRingCalculatorFactory)HydraRingCalculatorFactory.Instance; + var testFactory = (TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance; var testCalculator = testFactory.DesignWaterLevelCalculator; // Call new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, - validFilePath, - ringId, - norm, - calculationMessageProviderMock); + validFilePath, + ringId, + norm, + calculationMessageProviderMock); // Assert Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); Assert.AreEqual(ringId, testCalculator.RingId); var expectedInput = CreateInput(hydraulicBoundaryLocation, norm); AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); + Assert.IsFalse(testCalculator.IsCanceled); } mockRepository.VerifyAll(); } [Test] + public void Calculate_CancelCalculationWithValidInput_CancelsCalculation() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + const string locationName = "punt_flw_ 1"; + const string calculationName = "locationName"; + const string calculationNotConvergedMessage = "calculationNotConvergedMessage"; + const string ringId = "ringId"; + const double norm = 30; + + var mockRepository = new MockRepository(); + 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 HydraRingCalculatorFactoryConfig()) + { + var testFactory = (TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance; + var testCalculator = testFactory.DesignWaterLevelCalculator; + + // Call + var service = new DesignWaterLevelCalculationService(); + service.Calculate(hydraulicBoundaryLocation, + validFilePath, + ringId, + norm, + calculationMessageProviderMock); + service.Cancel(); + + // Assert + Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); + Assert.AreEqual(ringId, testCalculator.RingId); + + var expectedInput = CreateInput(hydraulicBoundaryLocation, norm); + AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); + Assert.IsTrue(testCalculator.IsCanceled); + } + mockRepository.VerifyAll(); + } + + [Test] public void Calculate_CalculationFails_LogError() { // Setup @@ -190,7 +239,6 @@ exceptionThrown = true; } }; - // Assert TestHelper.AssertLogMessages(call, messages =>