Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -r96a6ad152dc45508f0501e489c29611244e9d76c -r959924f8d1ddff924bb3306444d1f13fef85e545 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 96a6ad152dc45508f0501e489c29611244e9d76c) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 959924f8d1ddff924bb3306444d1f13fef85e545) @@ -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_WaveHeightCalculationNull_ThrowArgumentNullException() { // Setup var mockRepository = new MockRepository(); @@ -141,7 +142,7 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("hydraulicBoundaryLocation", exception.ParamName); + Assert.AreEqual("waveHeightCalculation", 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,22 +160,26 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(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 calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(string.Empty); calculationMessageProviderMock.Stub(calc => calc.GetCalculatedNotConvergedMessage(locationName)).Return(string.Empty); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, + new WaveHeightCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); // Assert - AssessmentLevelCalculationInput expectedInput = CreateInput(hydraulicBoundaryLocation, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); } @@ -190,10 +196,14 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(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(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, "punt_flw_ 1", 0, 0); const double norm = 1.0 / 30; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) @@ -202,7 +212,7 @@ calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call - service.Calculate(hydraulicBoundaryLocation, + service.Calculate(calculation, validFilePath, norm, calculationMessageProviderStub); @@ -233,13 +243,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(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; @@ -249,7 +262,7 @@ { try { - new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, + new WaveHeightCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -271,7 +284,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); } mockRepository.VerifyAll(); } @@ -295,13 +307,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(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; @@ -311,7 +326,7 @@ { try { - new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, + new WaveHeightCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -333,7 +348,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); } mockRepository.VerifyAll(); } @@ -358,13 +372,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(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; @@ -375,7 +392,7 @@ { try { - new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, + new WaveHeightCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -398,7 +415,7 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight); + Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); } @@ -410,9 +427,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