Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r96a6ad152dc45508f0501e489c29611244e9d76c -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 96a6ad152dc45508f0501e489c29611244e9d76c) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -25,6 +25,7 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Rhino.Mocks.Constraints; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.TestUtil; @@ -129,7 +130,7 @@ } [Test] - public void Calculate_HydraulicBoundaryLocationNull_ThrowArgumentNullException() + public void Calculate_DesignWaterLevelCalculationNull_ThrowArgumentNullException() { // Setup var mockRepository = new MockRepository(); @@ -141,7 +142,7 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("hydraulicBoundaryLocation", exception.ParamName); + Assert.AreEqual("designWaterLevelCalculation", exception.ParamName); } [Test] @@ -150,6 +151,7 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); + const long id = 100; const string locationName = "punt_flw_ 1"; const double norm = 1.0 / 30; @@ -158,23 +160,27 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(id); + calculation.Expect(c => c.SetOutput(null)).Constraints(new TypeOf(typeof(HydraulicBoundaryLocationOutput))); + var calculationMessageProviderStub = mockRepository.Stub(); calculationMessageProviderStub.Stub(calc => calc.GetCalculationName(locationName)).Return(string.Empty); calculationMessageProviderStub.Stub(calc => calc.GetCalculatedNotConvergedMessage(locationName)).Return(string.Empty); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderStub); // Assert - AssessmentLevelCalculationInput expectedInput = CreateInput(hydraulicBoundaryLocation, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); } @@ -192,20 +198,23 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return("name"); + calculation.Expect(c => c.GetId()).Return(0); + 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(calculatorFactory)) { var service = new DesignWaterLevelCalculationService(); calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call - service.Calculate(hydraulicBoundaryLocation, + service.Calculate(calculation, validFilePath, norm, calculationMessageProviderStub); @@ -236,13 +245,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + 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(calculatorFactory)) { var exceptionThrown = false; @@ -252,7 +264,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -274,7 +286,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); } mockRepository.VerifyAll(); } @@ -298,13 +309,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedUnexplainedMessage(locationName)).Return(calculationFailedUnexplainedMessage); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var exceptionThrown = false; @@ -314,7 +328,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -336,7 +350,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); } mockRepository.VerifyAll(); } @@ -361,13 +374,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + 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(calculatorFactory)) { var exceptionThrown = false; @@ -378,7 +394,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -401,7 +417,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); @@ -414,9 +429,9 @@ Assert.AreEqual(expectedInput.Beta, hydraRingCalculationInput.Beta); } - private static AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm) + private static AssessmentLevelCalculationInput CreateInput(long hydraulicBoundaryLocationId, double norm) { - return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); + return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocationId, norm); } } } \ No newline at end of file