Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs
===================================================================
diff -u -rb32ec68f52968bc821b67cd973544bc2d0e7d568 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision b32ec68f52968bc821b67cd973544bc2d0e7d568)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -1025,8 +1025,24 @@
RingtoetsFormsResources.WaveHeight_Calculate,
RingtoetsFormsResources.WaveHeight_Calculate_ToolTip,
RingtoetsCommonFormsResources.FailureMechanismIcon,
- null);
+ (sender, args) =>
+ {
+ var hrdFile = nodeData.WrappedData.HydraulicBoundaryDatabase.FilePath;
+ var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hrdFile);
+ if (validationProblem == null)
+ {
+ var activities = nodeData.WrappedData.HydraulicBoundaryDatabase.Locations.Select(hbl => new WaveHeightCalculationActivity(nodeData.WrappedData, hbl)).ToArray();
+ ActivityProgressDialogRunner.Run(Gui.MainWindow, activities);
+
+ nodeData.WrappedData.NotifyObservers();
+ }
+ else
+ {
+ log.ErrorFormat(Resources.RingtoetsPlugin_HydraulicBoundaryDatabaseContextMenuStrip_Start_calculation_failed_0_, validationProblem);
+ }
+ });
+
if (nodeData.WrappedData.HydraulicBoundaryDatabase == null)
{
waveHeightItem.Enabled = false;
Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationActivity.cs
===================================================================
diff -u -rb7fd39761c3b5e879308bc5c1b8fc69783f4dd65 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision b7fd39761c3b5e879308bc5c1b8fc69783f4dd65)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -37,15 +37,6 @@
private readonly IAssessmentSection assessmentSection;
private readonly HydraulicBoundaryLocation hydraulicBoundaryLocation;
- public override string Name
- {
- get
- {
- return string.Format(Resources.DesignWaterLevelCalculationService_Name_Calculate_assessment_level_for_location_0_,
- hydraulicBoundaryLocation.Name);
- }
- }
-
///
/// Creates a new instance of .
///
@@ -67,6 +58,15 @@
this.hydraulicBoundaryLocation = hydraulicBoundaryLocation;
}
+ public override string Name
+ {
+ get
+ {
+ return string.Format(Resources.DesignWaterLevelCalculationService_Name_Calculate_assessment_level_for_location_0_,
+ hydraulicBoundaryLocation.Name);
+ }
+ }
+
protected override void OnRun()
{
if (!double.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel))
@@ -76,17 +76,16 @@
}
PerformRun(() => DesignWaterLevelCalculationService.Validate(assessmentSection.HydraulicBoundaryDatabase, hydraulicBoundaryLocation),
- () => hydraulicBoundaryLocation.DesignWaterLevel = double.NaN,
- () => DesignWaterLevelCalculationService.Calculate(assessmentSection,
- assessmentSection.HydraulicBoundaryDatabase,
- hydraulicBoundaryLocation,
- assessmentSection.Id));
-
+ () => hydraulicBoundaryLocation.DesignWaterLevel = double.NaN,
+ () => DesignWaterLevelCalculationService.Calculate(assessmentSection,
+ assessmentSection.HydraulicBoundaryDatabase,
+ hydraulicBoundaryLocation,
+ assessmentSection.Id));
}
protected override void OnFinish()
{
PerformFinish(() => hydraulicBoundaryLocation.DesignWaterLevel = Output.Result, hydraulicBoundaryLocation);
}
}
-}
+}
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.Designer.cs
===================================================================
diff -u -r7eb4647c7751883ebba18fcc71c72825636906b0 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7eb4647c7751883ebba18fcc71c72825636906b0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -88,5 +88,14 @@
return ResourceManager.GetString("WaveHeightCalculationService_Calculate_Error_in_wave_height_0_calculation", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Golfhoogte berekenen voor locatie '{0}'.
+ ///
+ internal static string WaveHeightCalculationService_Name_Calculate_assessment_level_for_location_0_ {
+ get {
+ return ResourceManager.GetString("WaveHeightCalculationService_Name_Calculate_assessment_level_for_location_0_", resourceCulture);
+ }
+ }
}
}
Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.resx
===================================================================
diff -u -r7eb4647c7751883ebba18fcc71c72825636906b0 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.resx (.../Resources.resx) (revision 7eb4647c7751883ebba18fcc71c72825636906b0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Properties/Resources.resx (.../Resources.resx) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -126,4 +126,7 @@
Er is een fout opgetreden tijdens de golfhoogte berekening '{0}': inspecteer het logbestand.
+
+ Golfhoogte berekenen voor locatie '{0}'
+
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj
===================================================================
diff -u -r7eb4647c7751883ebba18fcc71c72825636906b0 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision 7eb4647c7751883ebba18fcc71c72825636906b0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -55,6 +55,7 @@
True
Resources.resx
+
Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/WaveHeightCalculationActivity.cs
===================================================================
diff -u
--- Ringtoets/Integration/src/Ringtoets.Integration.Service/WaveHeightCalculationActivity.cs (revision 0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Service/WaveHeightCalculationActivity.cs (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -0,0 +1,93 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Common.Base.Service;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.HydraRing.Calculation.Activities;
+using Ringtoets.HydraRing.Calculation.Data.Output;
+using Ringtoets.HydraRing.Data;
+using Ringtoets.Integration.Service.Properties;
+
+namespace Ringtoets.Integration.Service
+{
+ ///
+ /// for running a water height calculation.
+ ///
+ public class WaveHeightCalculationActivity : HydraRingActivity
+ {
+ private readonly IAssessmentSection assessmentSection;
+ private readonly HydraulicBoundaryLocation hydraulicBoundaryLocation;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The data which is used for the calculation.
+ /// The to perform the calculation for.
+ /// Thrown when any input argument is null.
+ public WaveHeightCalculationActivity(IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation)
+ {
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException("assessmentSection");
+ }
+ if (hydraulicBoundaryLocation == null)
+ {
+ throw new ArgumentNullException("hydraulicBoundaryLocation");
+ }
+
+ this.assessmentSection = assessmentSection;
+ this.hydraulicBoundaryLocation = hydraulicBoundaryLocation;
+
+ }
+
+ public override string Name
+ {
+ get
+ {
+ return string.Format(Resources.WaveHeightCalculationService_Name_Calculate_assessment_level_for_location_0_,
+ hydraulicBoundaryLocation.Name);
+ }
+ }
+
+ protected override void OnRun()
+ {
+ if (!double.IsNaN(hydraulicBoundaryLocation.WaveHeight))
+ {
+ State = ActivityState.Skipped;
+ return;
+ }
+
+ PerformRun(() => WaveHeightCalculationService.Validate(assessmentSection.HydraulicBoundaryDatabase, hydraulicBoundaryLocation),
+ () => hydraulicBoundaryLocation.WaveHeight = double.NaN,
+ () => WaveHeightCalculationService.Calculate(assessmentSection,
+ assessmentSection.HydraulicBoundaryDatabase,
+ hydraulicBoundaryLocation,
+ assessmentSection.Id));
+
+ }
+
+ protected override void OnFinish()
+ {
+ PerformFinish(() => hydraulicBoundaryLocation.WaveHeight = Output.Result, hydraulicBoundaryLocation);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/WaveHeightContextTreeNodeInfoTest.cs
===================================================================
diff -u -rdd91bb7a97e4246970fcb455a884bde554e40426 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/WaveHeightContextTreeNodeInfoTest.cs (.../WaveHeightContextTreeNodeInfoTest.cs) (revision dd91bb7a97e4246970fcb455a884bde554e40426)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/WaveHeightContextTreeNodeInfoTest.cs (.../WaveHeightContextTreeNodeInfoTest.cs) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -19,24 +19,27 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Drawing;
using System.Linq;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.TestUtil.ContextMenu;
using Core.Common.TestUtil;
+using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Forms.Properties;
using Ringtoets.HydraRing.Data;
+using Ringtoets.Integration.Data;
using Ringtoets.Integration.Forms.PresentationObjects;
using Ringtoets.Integration.Plugin;
namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos
{
- public class WaveHeightContextTreeNodeInfoTest
+ public class WaveHeightContextTreeNodeInfoTest : NUnitFormTest
{
private MockRepository mockRepository;
@@ -237,14 +240,14 @@
var assessmentSection = mockRepository.Stub();
mockRepository.ReplayAll();
- var designWaterLevelContext = new WaveHeightContext(assessmentSection);
+ var waterLevelContext = new WaveHeightContext(assessmentSection);
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
- Color color = info.ForeColor(designWaterLevelContext);
+ Color color = info.ForeColor(waterLevelContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color);
@@ -260,21 +263,82 @@
assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
mockRepository.ReplayAll();
- var designWaterLevelContext = new WaveHeightContext(assessmentSection);
+ var waterLevelContext = new WaveHeightContext(assessmentSection);
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
- Color color = info.ForeColor(designWaterLevelContext);
+ Color color = info.ForeColor(waterLevelContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color);
}
mockRepository.VerifyAll();
}
+
+ [Test]
+ public void GivenHydraulicBoundaryDatabaseWithNonExistingFilePath_WhenCalculatingAssessmentLevelFromContextMenu_ThenLogMessagesAddedPreviousOutputNotAffected()
+ {
+ // Given
+ var gui = mockRepository.DynamicMock();
+
+ var contextMenuRunAssessmentLevelCalculationsIndex = 0;
+
+ var hydraulicBoundaryLocation1 = new HydraulicBoundaryLocation(100001, "", 1.1, 2.2);
+ var hydraulicBoundaryLocation2 = new HydraulicBoundaryLocation(100002, "", 3.3, 4.4)
+ {
+ WaveHeight = 4.2
+ };
+
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
+ {
+ Locations =
+ {
+ hydraulicBoundaryLocation1,
+ hydraulicBoundaryLocation2
+ },
+ FilePath = "D:/nonExistingDirectory/nonExistingFile",
+ Version = "random"
+ };
+
+ var assessmentSectionMock = new AssessmentSection(AssessmentSectionComposition.Dike)
+ {
+ HydraulicBoundaryDatabase = hydraulicBoundaryDatabase
+ };
+ var waveHeightContext = new WaveHeightContext(assessmentSectionMock);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ gui.Expect(cmp => cmp.Get(waveHeightContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
+
+ mockRepository.ReplayAll();
+
+ using (var plugin = new RingtoetsPlugin())
+ {
+ var info = GetInfo(plugin);
+ plugin.Gui = gui;
+
+ var contextMenuAdapter = info.ContextMenuStrip(waveHeightContext, null, treeViewControl);
+
+ // When
+ Action action = () => { contextMenuAdapter.Items[contextMenuRunAssessmentLevelCalculationsIndex].PerformClick(); };
+
+ // Then
+ string message = string.Format("Berekeningen konden niet worden gestart. Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.",
+ hydraulicBoundaryDatabase.FilePath);
+ TestHelper.AssertLogMessageWithLevelIsGenerated(action, new Tuple(message, LogLevelConstant.Error));
+
+ Assert.IsNaN(hydraulicBoundaryLocation1.WaveHeight); // No result set
+ Assert.AreEqual(4.2, hydraulicBoundaryLocation2.WaveHeight); // Previous result not cleared
+ }
+ }
+ mockRepository.VerifyAll();
+ }
+
+
private static TreeNodeInfo GetInfo(RingtoetsPlugin plugin)
{
return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(WaveHeightContext));
Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj
===================================================================
diff -u -r7eb4647c7751883ebba18fcc71c72825636906b0 -r5cf6fd5b4bd57890b104182c35fff4180b9d7aba
--- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 7eb4647c7751883ebba18fcc71c72825636906b0)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -59,6 +59,7 @@
+
Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/WaveHeightCalculationActivityTest.cs
===================================================================
diff -u
--- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/WaveHeightCalculationActivityTest.cs (revision 0)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/WaveHeightCalculationActivityTest.cs (revision 5cf6fd5b4bd57890b104182c35fff4180b9d7aba)
@@ -0,0 +1,296 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using System.Linq;
+using Core.Common.Base;
+using Core.Common.Base.Service;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.HydraRing.Data;
+using Ringtoets.Integration.Data;
+using Ringtoets.Integration.Plugin.FileImporters;
+
+namespace Ringtoets.Integration.Service.Test
+{
+ [TestFixture]
+ public class WaveHeightCalculationActivityTest
+ {
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation");
+
+ [Test]
+ public void ParameteredConstructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSectionMock = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0, 0);
+
+ // Call
+ var activity = new WaveHeightCalculationActivity(assessmentSectionMock, hydraulicBoundaryLocation);
+
+ // Assert
+ Assert.IsInstanceOf(activity);
+ string expectedName = string.Format("Golfhoogte berekenen voor locatie '{0}'",
+ hydraulicBoundaryLocation.Name);
+ Assert.AreEqual(expectedName, activity.Name);
+ Assert.IsNull(activity.ProgressText);
+ Assert.AreEqual(ActivityState.None, activity.State);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ParameteredConstructor_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0, 0);
+
+ // Call
+ TestDelegate call = () => new WaveHeightCalculationActivity(null, hydraulicBoundaryLocation);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void ParameteredConstructor_HydraulicBoundaryLocationNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var assessmentSectionMock = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate call = () => new WaveHeightCalculationActivity(assessmentSectionMock, null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("hydraulicBoundaryLocation", exception.ParamName);
+ }
+
+ [Test]
+ public void Run_InvalidHydraulicBoundaryDatabase_PerformValidationAndLogStartAndEndAndError()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
+ {
+ HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
+ {
+ FilePath = Path.Combine(testDataPath, "notexisting.sqlite")
+ }
+ };
+
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0, 0);
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ // Call
+ Action call = () => activity.Run();
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var msgs = messages.ToArray();
+ Assert.AreEqual(3, msgs.Length);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", hydraulicBoundaryLocation.Name), msgs[0]);
+ StringAssert.StartsWith("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. Fout bij het lezen van bestand", msgs[1]);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", hydraulicBoundaryLocation.Name), msgs[2]);
+ });
+ Assert.AreEqual(ActivityState.Failed, activity.State);
+ }
+
+ [Test]
+ public void Run_ValidHydraulicBoundaryDatabaseAndHydraulicBoundaryLocation_PerformValidationAndCalculationAndLogStartAndEnd()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ var hydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(loc => loc.Id == 1300001);
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ // Call
+ Action call = () => activity.Run();
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var msgs = messages.ToArray();
+ Assert.AreEqual(4, msgs.Length);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", hydraulicBoundaryLocation.Name), msgs[0]);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", hydraulicBoundaryLocation.Name), msgs[1]);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", hydraulicBoundaryLocation.Name), msgs[2]);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", hydraulicBoundaryLocation.Name), msgs[3]);
+ });
+ Assert.AreEqual(ActivityState.Executed, activity.State);
+ }
+
+ [Test]
+ public void Run_ValidHydraulicBoundaryDatabaseInvalidHydraulicBoundaryLocation_PerformValidationAndCalculationAndLogStartAndEndAndError()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1);
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ // Call
+ Action call = () => activity.Run();
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var msgs = messages.ToArray();
+ Assert.AreEqual(5, msgs.Length);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", hydraulicBoundaryLocation.Name), msgs[0]);
+ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", hydraulicBoundaryLocation.Name), msgs[1]);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", hydraulicBoundaryLocation.Name), msgs[2]);
+ StringAssert.StartsWith(string.Format("Er is een fout opgetreden tijdens de golfhoogte berekening '{0}': inspecteer het logbestand.", hydraulicBoundaryLocation.Name), msgs[3]);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", hydraulicBoundaryLocation.Name), msgs[4]);
+ });
+ Assert.AreEqual(ActivityState.Failed, activity.State);
+ Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight);
+ }
+
+ [Test]
+ public void Run_CalculationAlreadyRan_ValidationAndCalculationNotPerformedAndStateSkipped()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ const double waveHeight = 3.0;
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1)
+ {
+ WaveHeight = waveHeight
+ };
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ // Call
+ Action call = () => activity.Run();
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var msgs = messages.ToArray();
+ Assert.AreEqual(0, msgs.Length);
+ });
+ Assert.AreEqual(ActivityState.Skipped, activity.State);
+ }
+
+ [Test]
+ public void Finish_ValidCalculationAndRun_SetsWaveHeightAndNotifyObservers()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var observerMock = mocks.StrictMock();
+ observerMock.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ var hydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(loc => loc.Id == 1300001);
+ hydraulicBoundaryLocation.Attach(observerMock);
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ activity.Run();
+
+ // Call
+ activity.Finish();
+
+ // Assert
+ Assert.IsFalse(double.IsNaN(hydraulicBoundaryLocation.WaveHeight));
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Finish_InvalidCalculationAndRun_DoesNotSetWaveHeightAndUpdateObserver()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var observerMock = mocks.StrictMock();
+ observerMock.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1);
+ hydraulicBoundaryLocation.Attach(observerMock);
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ activity.Run();
+
+ // Call
+ activity.Finish();
+
+ // Assert
+ Assert.IsNaN(hydraulicBoundaryLocation.WaveHeight);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Finish_CalculationAlreadyRan_FinishNotPerformed()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ ImportHydraulicBoundaryDatabase(assessmentSection);
+
+ const double waveHeight = 3.0;
+ var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1)
+ {
+ WaveHeight = waveHeight
+ };
+
+ var activity = new WaveHeightCalculationActivity(assessmentSection, hydraulicBoundaryLocation);
+
+ activity.Run();
+
+ // Call
+ activity.Finish();
+
+ // Assert
+ Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight);
+ }
+
+
+ private void ImportHydraulicBoundaryDatabase(AssessmentSection assessmentSection)
+ {
+ string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite");
+
+ using (var importer = new HydraulicBoundaryDatabaseImporter())
+ importer.Import(assessmentSection, validFilePath);
+ }
+ }
+}
\ No newline at end of file