Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GuiServices/HydraulicBoundaryLocationCalculationGuiServiceTest.cs =================================================================== diff -u -r8737389949c6578649c7788bd3a0550699276eac -r3f08de6c9ea2fce2f5fc15302fda17c119b3798c --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GuiServices/HydraulicBoundaryLocationCalculationGuiServiceTest.cs (.../HydraulicBoundaryLocationCalculationGuiServiceTest.cs) (revision 8737389949c6578649c7788bd3a0550699276eac) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GuiServices/HydraulicBoundaryLocationCalculationGuiServiceTest.cs (.../HydraulicBoundaryLocationCalculationGuiServiceTest.cs) (revision 3f08de6c9ea2fce2f5fc15302fda17c119b3798c) @@ -29,6 +29,7 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.GuiServices; using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.TestUtil; @@ -43,11 +44,6 @@ private MockRepository mockRepository; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); - public override void Setup() - { - mockRepository = new MockRepository(); - } - [Test] public void Constructor_NullMainWindow_ThrowsArgumentNullException() { @@ -260,7 +256,7 @@ Action call = () => guiService.CalculateDesignWaterLevels(validDatabasePath, new List { - new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + new TestHydraulicBoundaryLocation(hydraulicLocationName) }, 1, calculationMessageProviderMock); @@ -310,7 +306,7 @@ bool successfulCalculation = guiService.CalculateDesignWaterLevels(validDatabasePath, new List { - new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + new TestHydraulicBoundaryLocation(hydraulicLocationName) }, 1, calculationMessageProviderMock); @@ -508,7 +504,7 @@ Action call = () => guiService.CalculateWaveHeights(validDatabasePath, new List { - new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + new TestHydraulicBoundaryLocation(hydraulicLocationName) }, 1, calculationMessageProviderMock); @@ -558,7 +554,7 @@ bool successfulCalculation = guiService.CalculateWaveHeights(validDatabasePath, new List { - new HydraulicBoundaryLocation(1, hydraulicLocationName, 2, 3) + new TestHydraulicBoundaryLocation(hydraulicLocationName) }, 1, calculationMessageProviderMock); @@ -567,5 +563,10 @@ } mockRepository.VerifyAll(); } + + public override void Setup() + { + mockRepository = new MockRepository(); + } } } \ No newline at end of file Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/GuiServices/DuneLocationCalculationGuiService.cs =================================================================== diff -u -r22b6bdeb7d18ce2492b61394783e0a93257859a7 -r3f08de6c9ea2fce2f5fc15302fda17c119b3798c --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/GuiServices/DuneLocationCalculationGuiService.cs (.../DuneLocationCalculationGuiService.cs) (revision 22b6bdeb7d18ce2492b61394783e0a93257859a7) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/GuiServices/DuneLocationCalculationGuiService.cs (.../DuneLocationCalculationGuiService.cs) (revision 3f08de6c9ea2fce2f5fc15302fda17c119b3798c) @@ -24,8 +24,11 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Gui.Forms.ProgressDialog; +using log4net; +using Ringtoets.Common.IO.HydraRing; using Ringtoets.DuneErosion.Data; using Ringtoets.DuneErosion.Service; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.DuneErosion.Forms.GuiServices { @@ -34,6 +37,7 @@ /// public class DuneLocationCalculationGuiService { + private static readonly ILog log = LogManager.GetLogger(typeof(DuneLocationCalculationGuiService)); private readonly IWin32Window viewParent; /// @@ -67,6 +71,14 @@ throw new ArgumentNullException(nameof(locations)); } + string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabaseFilePath); + if (!string.IsNullOrEmpty(validationProblem)) + { + log.ErrorFormat(RingtoetsCommonFormsResources.CalculateHydraulicBoundaryLocation_ContextMenuStrip_Start_calculation_failed_0_, + validationProblem); + return; + } + ActivityProgressDialogRunner.Run( viewParent, locations.Select(l => new DuneErosionBoundaryCalculationActivity(l, Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj =================================================================== diff -u -rf1f94637a6b45b394493bf16a078b317c02d329b -r3f08de6c9ea2fce2f5fc15302fda17c119b3798c --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision f1f94637a6b45b394493bf16a078b317c02d329b) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/Ringtoets.DuneErosion.Forms.csproj (.../Ringtoets.DuneErosion.Forms.csproj) (revision 3f08de6c9ea2fce2f5fc15302fda17c119b3798c) @@ -32,6 +32,10 @@ AllRules.ruleset + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + @@ -78,6 +82,7 @@ Copying.licenseheader + @@ -120,6 +125,11 @@ Ringtoets.Common.Forms False + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + False + {888D4097-8BC2-4703-9FB1-8744C94D525E} Ringtoets.HydraRing.Calculation Index: Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/packages.config =================================================================== diff -u --- Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/packages.config (revision 0) +++ Ringtoets/DuneErosion/src/Ringtoets.DuneErosion.Forms/packages.config (revision 3f08de6c9ea2fce2f5fc15302fda17c119b3798c) @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/GuiServices/DuneLocationCalculationGuiServiceTest.cs =================================================================== diff -u -re93f3cb97066cae85be4a977098261d47ba6eb57 -r3f08de6c9ea2fce2f5fc15302fda17c119b3798c --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/GuiServices/DuneLocationCalculationGuiServiceTest.cs (.../DuneLocationCalculationGuiServiceTest.cs) (revision e93f3cb97066cae85be4a977098261d47ba6eb57) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/GuiServices/DuneLocationCalculationGuiServiceTest.cs (.../DuneLocationCalculationGuiServiceTest.cs) (revision 3f08de6c9ea2fce2f5fc15302fda17c119b3798c) @@ -30,6 +30,7 @@ using Rhino.Mocks; using Ringtoets.Common.Service.TestUtil; using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; using Ringtoets.DuneErosion.Forms.GuiServices; using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; @@ -39,8 +40,15 @@ [TestFixture] public class DuneLocationCalculationGuiServiceTest { + private MockRepository mockRepository; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); + [SetUp] + public void Setup() + { + mockRepository = new MockRepository(); + } + [Test] public void Constructor_ViewParentNull_ThrowArgumentNullException() { @@ -95,7 +103,6 @@ }) }; - var mockRepository = new MockRepository(); int nrOfCalculators = duneLocations.Length; var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath)) @@ -143,5 +150,77 @@ mockRepository.VerifyAll(); } + + [Test] + public void Calculate_HydraulicDatabaseDoesNotExist_LogsError() + { + // Setup + var calculatorFactory = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + const string databasePath = "Does not exist"; + using (var viewParent = new Form()) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + var guiService = new DuneLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.Calculate(Enumerable.Empty(), databasePath, 1); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First()); + }); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidPathOneLocationInTheList_LogsMessages() + { + // Setup + const string hydraulicLocationName = "name"; + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var viewParent = mockRepository.Stub(); + + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(testDataPath)).Return(new TestDunesBoundaryConditionsCalculator()); + mockRepository.ReplayAll(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + var guiService = new DuneLocationCalculationGuiService(viewParent); + + // Call + Action call = () => guiService.Calculate( + new List + { + new TestDuneLocation(hydraulicLocationName) + }, validFilePath, + 1); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(7, msgs.Length); + + string calculationName = $"Hydraulische belasting berekenen voor locatie '{hydraulicLocationName}'"; + + CalculationServiceTestHelper.AssertValidationStartMessage(calculationName, msgs[0]); + CalculationServiceTestHelper.AssertValidationEndMessage(calculationName, msgs[1]); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[2]); + Assert.AreEqual($"Hydraulische randvoorwaarden berekening voor locatie '{hydraulicLocationName}' is niet geconvergeerd.", msgs[3]); + StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[5]); + StringAssert.AreNotEqualIgnoringCase($"Uitvoeren van '{calculationName}' is gelukt.", msgs[6]); + }); + } + mockRepository.VerifyAll(); + } } } \ No newline at end of file