Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs
===================================================================
diff -u -r8aea6e032ff8aeb4a4f1b85210fd0e2fbbce3a4a -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision 8aea6e032ff8aeb4a4f1b85210fd0e2fbbce3a4a)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -84,10 +84,10 @@
return;
}
- PerformRun(() => DesignWaterLevelCalculationService.Validate(
+ PerformRun(() => DesignWaterLevelCalculationService.Instance.Validate(
messageProvider.GetCalculationName(hydraulicBoundaryLocation.Name), hydraulicBoundaryDatabaseFilePath),
() => hydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble) double.NaN,
- () => DesignWaterLevelCalculationService.Calculate(
+ () => DesignWaterLevelCalculationService.Instance.Calculate(
messageProvider, hydraulicBoundaryLocation, hydraulicBoundaryDatabaseFilePath,
ringId, norm));
}
Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs
===================================================================
diff -u -r06b2840a2bb64c0960c8ac29322b5a0971c73c77 -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 06b2840a2bb64c0960c8ac29322b5a0971c73c77)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -36,19 +36,28 @@
///
/// Service that provides methods for performing Hydra-Ring calculations for design water level.
///
- internal static class DesignWaterLevelCalculationService
+ public class DesignWaterLevelCalculationService : IDesignWaterLevelCalculationService
{
private static readonly ILog log = LogManager.GetLogger(typeof(DesignWaterLevelCalculationService));
+ private static IDesignWaterLevelCalculationService instance;
///
- /// Performs validation of the values in the given . Error information is logged during
- /// the execution of the operation.
+ /// Gets or sets an instance of .
///
- /// The name to use in the validation logs.
- /// The HLCD file that should be used for performing the calculation.
- /// False if the connection to contains validation errors; True otherwise.
- internal static bool Validate(string name, string hydraulicBoundaryDatabaseFilePath)
+ public static IDesignWaterLevelCalculationService Instance
{
+ get
+ {
+ return instance ?? (instance = new DesignWaterLevelCalculationService());
+ }
+ set
+ {
+ instance = value;
+ }
+ }
+
+ public bool Validate(string name, string hydraulicBoundaryDatabaseFilePath)
+ {
CalculationServiceHelper.LogValidationBeginTime(name);
string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabaseFilePath);
@@ -65,20 +74,10 @@
return isValid;
}
- ///
- /// Performs a design water level calculation based on the supplied and returns the result
- /// if the calculation was successful. Error and status information is logged during the execution of the operation.
- ///
- /// The message provider for the services.
- /// The to perform the calculation for.
- /// The HLCD file that should be used for performing the calculation.
- /// The id of the ring to perform the calculation for.
- /// The norm to use during the calculation.
- /// A on a successful calculation, null otherwise.
- internal static ReliabilityIndexCalculationOutput Calculate(ICalculationMessageProvider messageProvider,
- IHydraulicBoundaryLocation hydraulicBoundaryLocation,
- string hydraulicBoundaryDatabaseFilePath,
- string ringId, double norm)
+ public ReliabilityIndexCalculationOutput Calculate(ICalculationMessageProvider messageProvider,
+ IHydraulicBoundaryLocation hydraulicBoundaryLocation,
+ string hydraulicBoundaryDatabaseFilePath,
+ string ringId, double norm)
{
var hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath);
var input = CreateInput(hydraulicBoundaryLocation, norm);
Index: Ringtoets/Common/src/Ringtoets.Common.Service/IDesignWaterLevelCalculationService.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Service/IDesignWaterLevelCalculationService.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/IDesignWaterLevelCalculationService.cs (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -0,0 +1,54 @@
+// 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 Ringtoets.Common.Service.MessageProviders;
+using Ringtoets.HydraRing.Calculation.Data.Output;
+using Ringtoets.HydraRing.Data;
+
+namespace Ringtoets.Common.Service
+{
+ public interface IDesignWaterLevelCalculationService
+ {
+ ///
+ /// Performs validation of the values in the given . Error information is logged during
+ /// the execution of the operation.
+ ///
+ /// The name to use in the validation logs.
+ /// The HLCD file that should be used for performing the calculation.
+ /// False if the connection to contains validation errors; True otherwise.
+ bool Validate(string name, string hydraulicBoundaryDatabaseFilePath);
+
+ ///
+ /// Performs a design water level calculation based on the supplied and returns the result
+ /// if the calculation was successful. Error and status information is logged during the execution of the operation.
+ ///
+ /// The message provider for the services.
+ /// The to perform the calculation for.
+ /// The HLCD file that should be used for performing the calculation.
+ /// The id of the ring to perform the calculation for.
+ /// The norm to use during the calculation.
+ /// A on a successful calculation, null otherwise.
+ ReliabilityIndexCalculationOutput Calculate(ICalculationMessageProvider messageProvider,
+ IHydraulicBoundaryLocation hydraulicBoundaryLocation,
+ string hydraulicBoundaryDatabaseFilePath,
+ string ringId, double norm);
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj
===================================================================
diff -u -r06b2840a2bb64c0960c8ac29322b5a0971c73c77 -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 06b2840a2bb64c0960c8ac29322b5a0971c73c77)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -51,6 +51,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs
===================================================================
diff -u -r8aea6e032ff8aeb4a4f1b85210fd0e2fbbce3a4a -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision 8aea6e032ff8aeb4a4f1b85210fd0e2fbbce3a4a)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -28,6 +28,7 @@
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Service.MessageProviders;
+using Ringtoets.Common.Service.TestUtil;
using Ringtoets.HydraRing.Data;
namespace Ringtoets.Common.Service.Test
@@ -147,7 +148,7 @@
}
[Test]
- public void Run_ValidHydraulicBoundaryHydraulicBoundaryLocation_PerformValidationAndCalculationAndLogStartAndEnd()
+ public void Run_ValidHydraulicBoundaryHydraulicBoundaryLocation_PerformValidationValidParameters()
{
// Setup
string validFilePath = Path.Combine(testDataPath, validFile);
@@ -156,7 +157,6 @@
const string calculationName = "locationName";
var hydraulicBoundaryLocationMock = mockRepository.Stub();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Id).Return(1300001).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
@@ -169,65 +169,17 @@
hydraulicBoundaryLocationMock,
validFilePath, "", 30);
- // Call
- Action call = () => activity.Run();
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
+ using (new DesignWaterLevelCalculationServiceConfig())
{
- var msgs = messages.ToArray();
- Assert.AreEqual(5, msgs.Length);
- StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculationName), msgs[0]);
- StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[1]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculationName), msgs[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[4]);
- });
- Assert.AreEqual(ActivityState.Executed, activity.State);
- mockRepository.VerifyAll();
- }
+ var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance;
- [Test]
- public void Run_InvalidHydraulicBoundaryLocation_PerformValidationAndCalculationAndLogStartAndEndAndError()
- {
- // Setup
- string validFilePath = Path.Combine(testDataPath, validFile);
- const string locationName = "locationName";
- const string activityName = "GetActivityName";
- const string calculationName = "locationName";
- const string calculationFailedMessage = "calculationFailedMessage";
+ // Call
+ activity.Run();
- var hydraulicBoundaryLocationMock = mockRepository.Stub();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Id).Return(1).Repeat.AtLeastOnce();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce();
- hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
-
- var calculationMessageProviderMock = mockRepository.StrictMock();
- calculationMessageProviderMock.Expect(calc => calc.GetActivityName(locationName)).Return(activityName);
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName).Repeat.AtLeastOnce();
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return(calculationFailedMessage);
- mockRepository.ReplayAll();
-
- var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock,
- validFilePath, "", 30);
-
- // Call
- Action call = () => activity.Run();
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
- {
- var msgs = messages.ToArray();
- Assert.AreEqual(6, msgs.Length);
- StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculationName), msgs[0]);
- StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[1]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculationName), msgs[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
- StringAssert.StartsWith(calculationFailedMessage, msgs[4]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[5]);
- });
- Assert.AreEqual(ActivityState.Failed, activity.State);
- Assert.IsNaN(hydraulicBoundaryLocationMock.DesignWaterLevel);
+ // Assert
+ Assert.AreSame(calculationMessageProviderMock, testService.MessageProvider);
+ }
+ Assert.AreEqual(ActivityState.Executed, activity.State);
mockRepository.VerifyAll();
}
@@ -267,9 +219,8 @@
public void Finish_ValidCalculationAndRun_SetsDesignWaterLevelAndConvergence()
{
// Setup
- const string locationName = "punt_flw_ 1";
+ const string locationName = "locationName 1";
var hydraulicBoundaryLocationMock = mockRepository.Stub();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Id).Return(1300001).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
hydraulicBoundaryLocationMock.DesignWaterLevelCalculationConvergence = CalculationConvergence.CalculatedNotConverged;
@@ -283,7 +234,10 @@
var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock,
validFilePath, "", 30);
- activity.Run();
+ using (new DesignWaterLevelCalculationServiceConfig())
+ {
+ activity.Run();
+ }
// Call
activity.Finish();
@@ -302,10 +256,8 @@
const string locationName = "locationName";
calculationMessageProviderMock.Expect(calc => calc.GetActivityName(locationName)).Return("");
calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return("").Repeat.AtLeastOnce();
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return("");
var hydraulicBoundaryLocationMock = mockRepository.Stub();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Id).Return(1).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
hydraulicBoundaryLocationMock.DesignWaterLevelCalculationConvergence = CalculationConvergence.CalculatedConverged;
@@ -315,8 +267,14 @@
var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock,
validFilePath, "", 30);
- activity.Run();
+ using (new DesignWaterLevelCalculationServiceConfig())
+ {
+ var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance;
+ testService.SetCalculationConvergenceOutput = CalculationConvergence.NotCalculated;
+ activity.Run();
+ }
+
// Call
activity.Finish();
@@ -330,12 +288,11 @@
public void Finish_ValidCalculationAndRun_LogWarningNoConvergence()
{
// Setup
- const string locationName = "HRbasis_ijsslm_1000";
+ const string locationName = "locationName";
const string activityName = "getActivityName";
const string calculationNotConvergedMessage = "GetCalculatedNotConvergedMessage";
var hydraulicBoundaryLocationMock = mockRepository.Stub();
- hydraulicBoundaryLocationMock.Expect(hbl => hbl.Id).Return(700002).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce();
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
hydraulicBoundaryLocationMock.DesignWaterLevelCalculationConvergence = CalculationConvergence.CalculatedConverged;
@@ -351,8 +308,14 @@
var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock,
validFilePath, "", norm);
- activity.Run();
+ using (new DesignWaterLevelCalculationServiceConfig())
+ {
+ var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance;
+ testService.SetCalculationConvergenceOutput = CalculationConvergence.CalculatedNotConverged;
+ activity.Run();
+ }
+
// Precondition
Assert.AreEqual(CalculationConvergence.CalculatedConverged, hydraulicBoundaryLocationMock.DesignWaterLevelCalculationConvergence);
@@ -389,7 +352,10 @@
var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock, validFilePath, "", 30);
- activity.Run();
+ using (new DesignWaterLevelCalculationServiceConfig())
+ {
+ activity.Run();
+ }
// Call
activity.Finish();
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs
===================================================================
diff -u -r06b2840a2bb64c0960c8ac29322b5a0971c73c77 -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 06b2840a2bb64c0960c8ac29322b5a0971c73c77)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -27,7 +27,13 @@
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Service.MessageProviders;
+using Ringtoets.HydraRing.Calculation.Data;
+using Ringtoets.HydraRing.Calculation.Data.Input;
+using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics;
using Ringtoets.HydraRing.Calculation.Data.Output;
+using Ringtoets.HydraRing.Calculation.Parsers;
+using Ringtoets.HydraRing.Calculation.Services;
+using Ringtoets.HydraRing.Calculation.TestUtil;
using Ringtoets.HydraRing.Data;
namespace Ringtoets.Common.Service.Test
@@ -47,7 +53,7 @@
bool valid = false;
// Call
- Action call = () => valid = DesignWaterLevelCalculationService.Validate(calculationName, validFilePath);
+ Action call = () => valid = DesignWaterLevelCalculationService.Instance.Validate(calculationName, validFilePath);
// Assert
TestHelper.AssertLogMessages(call, messages =>
@@ -69,7 +75,7 @@
bool valid = false;
// Call
- Action call = () => valid = DesignWaterLevelCalculationService.Validate(calculationName, notValidFilePath);
+ Action call = () => valid = DesignWaterLevelCalculationService.Instance.Validate(calculationName, notValidFilePath);
// Assert
TestHelper.AssertLogMessages(call, messages =>
@@ -84,13 +90,16 @@
}
[Test]
- public void Calculate_ValidHydraulicBoundaryLocation_LogStartAndEndAndReturnOutput()
+ public void Calculate_ValidHydraulicBoundaryLocation_StartsCalculationWithRightParameters()
{
// Setup
string validFilePath = Path.Combine(testDataPath, validFile);
const string locationName = "punt_flw_ 1";
const string calculationName = "locationName";
+ const string calculationFailedMessage = "calculationFailedMessage";
+ const string ringId = "ringId";
+ const double norm = 30;
var mockRepository = new MockRepository();
var hydraulicBoundaryLocationMock = mockRepository.Stub();
@@ -99,37 +108,43 @@
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
var calculationMessageProviderMock = mockRepository.StrictMock();
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName).Repeat.AtLeastOnce();
-
+ calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName);
+ calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return(calculationFailedMessage);
mockRepository.ReplayAll();
- ReliabilityIndexCalculationOutput output = null;
- // Call
- Action call = () => output = DesignWaterLevelCalculationService.Calculate(calculationMessageProviderMock,
- hydraulicBoundaryLocationMock,
- validFilePath, "", 30);
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
+ using (new HydraRingCalculationServiceConfig())
{
- var msgs = messages.ToArray();
- Assert.AreEqual(3, msgs.Length);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculationName), msgs[0]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[1]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[2]);
- });
- Assert.IsNotNull(output);
+ var testService = (TestHydraRingCalculationService) HydraRingCalculationService.Instance;
+
+ // Call
+ DesignWaterLevelCalculationService.Instance.Calculate(calculationMessageProviderMock,
+ hydraulicBoundaryLocationMock,
+ validFilePath, ringId, norm);
+
+ // Assert
+ Assert.AreEqual(testDataPath, testService.HlcdDirectory);
+ Assert.AreEqual(ringId, testService.RingId);
+ Assert.AreEqual(HydraRingUncertaintiesType.All, testService.UncertaintiesType);
+ var parsers = testService.Parsers.ToArray();
+ Assert.AreEqual(1, parsers.Length);
+ Assert.IsInstanceOf(parsers[0]);
+ var expectedInput = CreateInput(hydraulicBoundaryLocationMock, norm);
+ AssertInput(expectedInput, testService.HydraRingCalculationInput);
+ }
mockRepository.VerifyAll();
}
[Test]
- public void Calculate_InvalidHydraulicBoundaryLocation_LogStartAndEndAndErrorMessageAndReturnNull()
+ public void Calculate_CalculationOutputNull_LogError()
{
// Setup
string validFilePath = Path.Combine(testDataPath, validFile);
- const string locationName = "locationName";
+
+ const string locationName = "punt_flw_ 1";
const string calculationName = "locationName";
const string calculationFailedMessage = "calculationFailedMessage";
+ const string ringId = "ringId";
+ const double norm = 30;
var mockRepository = new MockRepository();
var hydraulicBoundaryLocationMock = mockRepository.Stub();
@@ -138,29 +153,42 @@
hydraulicBoundaryLocationMock.DesignWaterLevel = new RoundedDouble(2, double.NaN);
var calculationMessageProviderMock = mockRepository.StrictMock();
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName).Repeat.AtLeastOnce();
- calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return(calculationFailedMessage).Repeat.AtLeastOnce();
+ calculationMessageProviderMock.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName);
+ calculationMessageProviderMock.Expect(calc => calc.GetCalculationFailedMessage(locationName)).Return(calculationFailedMessage);
mockRepository.ReplayAll();
ReliabilityIndexCalculationOutput output = null;
-
- // Call
- Action call = () => output = DesignWaterLevelCalculationService.Calculate(calculationMessageProviderMock,
- hydraulicBoundaryLocationMock,
- validFilePath, "", 30);
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
+ using (new HydraRingCalculationServiceConfig())
{
- var msgs = messages.ToArray();
- Assert.AreEqual(4, msgs.Length);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculationName), msgs[0]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[1]);
- StringAssert.StartsWith(calculationFailedMessage, msgs[2]);
- StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[3]);
- });
- Assert.IsNull(output);
+ // Call
+ Action call = () => output = DesignWaterLevelCalculationService.Instance.Calculate(calculationMessageProviderMock,
+ hydraulicBoundaryLocationMock,
+ validFilePath, ringId, norm);
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var msgs = messages.ToArray();
+ Assert.AreEqual(3, msgs.Length);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculationName), msgs[0]);
+ StringAssert.StartsWith(calculationFailedMessage, msgs[1]);
+ StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculationName), msgs[2]);
+ });
+ Assert.IsNull(output);
+ }
mockRepository.VerifyAll();
}
+
+ private static void AssertInput(AssessmentLevelCalculationInput expectedInput, HydraRingCalculationInput hydraRingCalculationInput)
+ {
+ Assert.AreEqual(expectedInput.Section.SectionId, hydraRingCalculationInput.Section.SectionId);
+ Assert.AreEqual(expectedInput.HydraulicBoundaryLocationId, hydraRingCalculationInput.HydraulicBoundaryLocationId);
+ Assert.AreEqual(expectedInput.Beta, hydraRingCalculationInput.Beta);
+ }
+
+ private static AssessmentLevelCalculationInput CreateInput(IHydraulicBoundaryLocation hydraulicBoundaryLocation, double norm)
+ {
+ return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj
===================================================================
diff -u -r63d5fc765fbe126346a952c02ae9298d03d89aa7 -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 63d5fc765fbe126346a952c02ae9298d03d89aa7)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -77,6 +77,10 @@
{3bbfd65b-b277-4e50-ae6d-bd24c3434609}
Core.Common.Base
+
+ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
+ Core.Common.Utils
+
{D749EE4C-CE50-4C17-BF01-9A953028C126}
Core.Common.TestUtil
@@ -89,6 +93,10 @@
{70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2}
Ringtoets.HydraRing.Data
+
+ {74CBA865-9338-447F-BAD9-28312446AE84}
+ Ringtoets.HydraRing.Calculation.TestUtil
+
{C8383B76-B3F1-4E6E-B56C-527B469FA20A}
Ringtoets.Integration.Plugin
@@ -105,6 +113,10 @@
{4843D6E5-066F-4795-94F5-1D53932DD03C}
Ringtoets.Common.Data.TestUtil
+
+ {73E7E100-C015-4874-A548-AD6E33E7955E}
+ Ringtoets.Common.Service.TestUtil
+
Index: Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/DesignWaterLevelCalculationServiceConfig.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/DesignWaterLevelCalculationServiceConfig.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/DesignWaterLevelCalculationServiceConfig.cs (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -0,0 +1,67 @@
+// 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;
+
+namespace Ringtoets.Common.Service.TestUtil
+{
+ ///
+ /// This class can be used to set a temporary
+ /// for while testing.
+ /// Disposing an instance of this class will revert the
+ /// .
+ ///
+ ///
+ /// The following is an example for how to use this class:
+ ///
+ /// using(new DesignWaterLevelCalculationServiceConfig())
+ /// {
+ /// var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance;
+ ///
+ /// // Perform test with service
+ /// }
+ ///
+ ///
+ public class DesignWaterLevelCalculationServiceConfig : IDisposable
+ {
+ private readonly IDesignWaterLevelCalculationService previousInstance;
+
+ ///
+ /// Creates a new instance of .
+ /// Sets a to
+ /// .
+ ///
+ public DesignWaterLevelCalculationServiceConfig()
+ {
+ previousInstance = DesignWaterLevelCalculationService.Instance;
+ DesignWaterLevelCalculationService.Instance = new TestDesignWaterLevelCalculationService();
+ }
+
+ ///
+ /// Reverts the to the value
+ /// it had at time of construction of the .
+ ///
+ public void Dispose()
+ {
+ DesignWaterLevelCalculationService.Instance = previousInstance;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/Ringtoets.Common.Service.TestUtil.csproj
===================================================================
diff -u -rd9fc827247231ca9d40e18e9f989a8bd978cb53b -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed
--- Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/Ringtoets.Common.Service.TestUtil.csproj (.../Ringtoets.Common.Service.TestUtil.csproj) (revision d9fc827247231ca9d40e18e9f989a8bd978cb53b)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/Ringtoets.Common.Service.TestUtil.csproj (.../Ringtoets.Common.Service.TestUtil.csproj) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed)
@@ -46,13 +46,37 @@
Properties\GlobalAssembly.cs
+
+
Copying.licenseheader
+
+
+ {3bbfd65b-b277-4e50-ae6d-bd24c3434609}
+ Core.Common.Base
+
+
+ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
+ Core.Common.Utils
+
+
+ {888D4097-8BC2-4703-9FB1-8744C94D525E}
+ Ringtoets.HydraRing.Calculation
+
+
+ {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2}
+ Ringtoets.HydraRing.Data
+
+
+ {D951D6DA-FE83-4920-9FDB-63BF96480B54}
+ Ringtoets.Common.Service
+
+