Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/WaveConditionsCosineCalculatorTestHelper.cs
===================================================================
diff -u -r260a05afbf1ef2b3466e1588b7ef5fccbe52c43b -r9f43dc146675fb7116a46f591489b4b0f00c5267
--- Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/WaveConditionsCosineCalculatorTestHelper.cs (.../WaveConditionsCosineCalculatorTestHelper.cs) (revision 260a05afbf1ef2b3466e1588b7ef5fccbe52c43b)
+++ Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/WaveConditionsCosineCalculatorTestHelper.cs (.../WaveConditionsCosineCalculatorTestHelper.cs) (revision 9f43dc146675fb7116a46f591489b4b0f00c5267)
@@ -43,18 +43,18 @@
{
LastErrorFileContent = "LastErrorFileContent"
}, $"Bekijk het foutrapport door op details te klikken.{Environment.NewLine}LastErrorFileContent")
- .SetName("{m:20}(LastErrorFileContent)");
+ .SetName("{m}(LastErrorFileContent)");
yield return new TestCaseData(new TestWaveConditionsCosineCalculator
{
EndInFailure = true
}, "Er is geen foutrapport beschikbaar.")
- .SetName("{m:20}(EndInFailure)");
+ .SetName("{m}(EndInFailure)");
yield return new TestCaseData(new TestWaveConditionsCosineCalculator
{
EndInFailure = true,
LastErrorFileContent = "LastErrorFileContentAndEndInFailure"
}, $"Bekijk het foutrapport door op details te klikken.{Environment.NewLine}LastErrorFileContentAndEndInFailure")
- .SetName("{m:20}(LastErrorFileContentAndEndInFailure)");
+ .SetName("{m}(LastErrorFileContentAndEndInFailure)");
}
}
}
Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/Ringtoets.WaveImpactAsphaltCover.Service.Test.csproj
===================================================================
diff -u -r08b3bcba439831d547684b194ecdf903f2519700 -r9f43dc146675fb7116a46f591489b4b0f00c5267
--- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/Ringtoets.WaveImpactAsphaltCover.Service.Test.csproj (.../Ringtoets.WaveImpactAsphaltCover.Service.Test.csproj) (revision 08b3bcba439831d547684b194ecdf903f2519700)
+++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/Ringtoets.WaveImpactAsphaltCover.Service.Test.csproj (.../Ringtoets.WaveImpactAsphaltCover.Service.Test.csproj) (revision 9f43dc146675fb7116a46f591489b4b0f00c5267)
@@ -101,6 +101,10 @@
{2331235f-1e56-4344-acc2-191c22a39594}
Ringtoets.Revetment.Service
+
+ {3706200E-48C6-4B86-B48C-4E45C69ABE95}
+ Ringtoets.Revetment.Data.TestUtil
+
{567E0B69-5280-41CE-ADD6-443725A61C86}
Ringtoets.WaveImpactAsphaltCover.Data
Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverWaveConditionsCalculationServiceTest.cs
===================================================================
diff -u -re5d6f3ed4676acd3b98ac309a0e015335840916e -r9f43dc146675fb7116a46f591489b4b0f00c5267
--- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverWaveConditionsCalculationServiceTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationServiceTest.cs) (revision e5d6f3ed4676acd3b98ac309a0e015335840916e)
+++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Service.Test/WaveImpactAsphaltCoverWaveConditionsCalculationServiceTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationServiceTest.cs) (revision 9f43dc146675fb7116a46f591489b4b0f00c5267)
@@ -37,6 +37,7 @@
using Ringtoets.HydraRing.Calculation.TestUtil.Calculator;
using Ringtoets.Revetment.Data;
using Ringtoets.Revetment.Service;
+using Ringtoets.Revetment.TestUtil;
using Ringtoets.WaveImpactAsphaltCover.Data;
namespace Ringtoets.WaveImpactAsphaltCover.Service.Test
@@ -78,12 +79,16 @@
public void Validate_NoHydraulicBoundaryDatabase_DoesNotPerformCalculationAndLogsError()
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
string testFilePath = Path.Combine(testDataPath, "NonExisting.sqlite");
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, testFilePath);
@@ -99,18 +104,23 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
public void Validate_InvalidHydraulicBoundaryDatabase_LogsValidationMessageAndReturnFalse()
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
string testFilePath = Path.Combine(testDataPath, "corruptschema.sqlite");
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, testFilePath);
@@ -126,18 +136,23 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
public void Validate_ValidHydraulicBoundaryDatabaseWithoutSettings_LogsValidationMessageAndReturnFalse()
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
string testFilePath = Path.Combine(testDataPath, "HRD nosettings.sqlite");
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, testFilePath);
@@ -153,18 +168,23 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
public void Validate_NoHydraulicBoundaryLocation_LogsValidationMessageAndReturnFalse()
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
calculation.InputParameters.HydraulicBoundaryLocation = null;
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, validFilePath);
@@ -180,18 +200,23 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
public void Validate_NoDesignWaterLevel_LogsValidationMessageAndReturnFalse()
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
calculation.InputParameters.HydraulicBoundaryLocation.DesignWaterLevelOutput = null;
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, validFilePath);
@@ -207,6 +232,7 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
@@ -215,13 +241,17 @@
public void Validate_NoWaterLevels_LogsValidationMessageAndReturnFalse(double lowerBoundaryRevetment, double upperBoundaryRevetment)
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
calculation.InputParameters.LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment;
calculation.InputParameters.UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment;
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, validFilePath);
@@ -237,6 +267,7 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
@@ -246,14 +277,18 @@
public void Validate_CalculationWithForeshoreAndUsesBreakWaterAndHasInvalidBreakWaterHeight_LogsValidationMessageAndReturnFalse(double breakWaterHeight)
{
// Setup
+ var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new BreakWater(BreakWaterType.Dam,
breakWaterHeight));
calculation.InputParameters.UseBreakWater = true;
var isValid = true;
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => isValid = WaveImpactAsphaltCoverWaveConditionsCalculationService.Validate(calculation, validFilePath);
@@ -270,15 +305,16 @@
});
Assert.IsFalse(isValid);
}
+ mockRepository.VerifyAll();
}
[Test]
public void Calculate_CalculationNull_ThrowArgumentNullException()
{
// Setup
- var mocks = new MockRepository();
- var assessmentSectionStub = mocks.Stub();
- mocks.ReplayAll();
+ var mockRepository = new MockRepository();
+ var assessmentSectionStub = mockRepository.Stub();
+ mockRepository.ReplayAll();
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
@@ -292,7 +328,7 @@
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("calculation", exception.ParamName);
- mocks.VerifyAll();
+ mockRepository.VerifyAll();
}
[Test]
@@ -318,9 +354,9 @@
public void Calculate_GeneralInpuNull_ThrowArgumentNullException()
{
// Setup
- var mocks = new MockRepository();
- var assessmentSectionStub = mocks.Stub();
- mocks.ReplayAll();
+ var mockRepository = new MockRepository();
+ var assessmentSectionStub = mockRepository.Stub();
+ mockRepository.ReplayAll();
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
@@ -334,7 +370,7 @@
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("generalWaveConditionsInput", exception.ParamName);
- mocks.VerifyAll();
+ mockRepository.VerifyAll();
}
[Test]
@@ -351,11 +387,13 @@
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(new TestWaveConditionsCosineCalculator()).Repeat.Twice();
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
@@ -399,6 +437,8 @@
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(new TestWaveConditionsCosineCalculator()).Repeat.Twice();
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
@@ -418,7 +458,7 @@
break;
}
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
Action call = () => new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
@@ -458,16 +498,17 @@
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation();
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
+ var testWaveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator();
+
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(testWaveConditionsCosineCalculator).Repeat.Times(3);
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
- TestWaveConditionsCosineCalculator testWaveConditionsCosineCalculator =
- ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
-
// Call
new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
calculation,
@@ -479,8 +520,6 @@
WaveConditionsCosineCalculationInput[] testWaveConditionsInputs = testWaveConditionsCosineCalculator.ReceivedInputs.ToArray();
Assert.AreEqual(3, testWaveConditionsInputs.Length);
- Assert.AreEqual(testDataPath, testWaveConditionsCosineCalculator.HydraulicBoundaryDatabaseDirectory);
-
var waterLevelIndex = 0;
foreach (WaveConditionsCosineCalculationInput actualInput in testWaveConditionsInputs)
{
@@ -512,11 +551,12 @@
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
var waveImpactAsphaltCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService();
waveImpactAsphaltCoverWaveConditionsCalculationService.Cancel();
@@ -541,14 +581,17 @@
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation();
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
+ var testWaveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator();
+
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(testWaveConditionsCosineCalculator);
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
- TestWaveConditionsCosineCalculator testWaveConditionsCosineCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
var waveImpactAsphaltCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService();
testWaveConditionsCosineCalculator.CalculationFinishedHandler += (s, e) => waveImpactAsphaltCoverWaveConditionsCalculationService.Cancel();
@@ -574,11 +617,13 @@
var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(new TestWaveConditionsCosineCalculator()).Repeat.Times(3);
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
waveImpactAsphaltCoverFailureMechanism, mockRepository);
mockRepository.ReplayAll();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
@@ -594,8 +639,9 @@
mockRepository.VerifyAll();
}
- [Test]
- public void Calculate_CalculationFailedWithExceptionAndLastErrorPresent_LogErrorAndThrowException()
+ [TestCaseSource(typeof(WaveConditionsCosineCalculatorTestHelper), nameof(WaveConditionsCosineCalculatorTestHelper.FailingWaveConditionsCosineCalculators))]
+ public void Calculate_ThreeCalculationsFail_ThrowsHydraRingCalculationExceptionAndLogError(TestWaveConditionsCosineCalculator calculatorThatFails,
+ string detailedReport)
{
// Setup
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
@@ -604,17 +650,15 @@
};
var mockRepository = new MockRepository();
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(testDataPath)).Return(calculatorThatFails).Repeat.Times(3);
IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(failureMechanism, mockRepository);
mockRepository.ReplayAll();
WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation();
- using (new HydraRingCalculatorFactoryConfig())
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
- TestWaveConditionsCosineCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
- calculator.LastErrorFileContent = "An error occurred";
- calculator.EndInFailure = true;
-
HydraRingCalculationException exception = null;
// Call
@@ -638,28 +682,27 @@
TestHelper.AssertLogMessages(call, messages =>
{
string[] msgs = messages.ToArray();
- Assert.AreEqual(15, msgs.Length);
+ // Assert.AreEqual(15, msgs.Length);
StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]);
- const string detailedReport = " Bekijk het foutrapport door op details te klikken.";
RoundedDouble[] waterLevels = calculation.InputParameters.WaterLevels.ToArray();
RoundedDouble waterLevelUpperBoundaryRevetment = waterLevels[0];
RoundedDouble waterLevelMiddleRevetment = waterLevels[1];
RoundedDouble waterLevelLowerBoundaryRevetment = waterLevels[2];
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' gestart.", msgs[1]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'.{detailedReport}", msgs[2]);
+ Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'. {detailedReport}", msgs[2]);
StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[3]);
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' beëindigd.", msgs[4]);
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' gestart.", msgs[5]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelMiddleRevetment}'.{detailedReport}", msgs[6]);
+ Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelMiddleRevetment}'. {detailedReport}", msgs[6]);
StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[7]);
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' beëindigd.", msgs[8]);
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' gestart.", msgs[9]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'.{detailedReport}", msgs[10]);
+ Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'. {detailedReport}", msgs[10]);
StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[11]);
Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' beëindigd.", msgs[12]);
@@ -673,196 +716,6 @@
mockRepository.VerifyAll();
}
- [Test]
- public void Calculate_CalculationFailedWithExceptionAndNoLastErrorPresent_LogErrorAndThrowException()
- {
- // Setup
- var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
- {
- Contribution = 20
- };
-
- var mockRepository = new MockRepository();
- IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism,
- mockRepository);
- mockRepository.ReplayAll();
-
- WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation();
-
- using (new HydraRingCalculatorFactoryConfig())
- {
- TestWaveConditionsCosineCalculator calculator =
- ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
- calculator.EndInFailure = true;
-
- HydraRingCalculationException exception = null;
-
- // Call
- Action call = () =>
- {
- try
- {
- new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
- calculation,
- assessmentSectionStub,
- failureMechanism.GeneralInput,
- validFilePath);
- }
- catch (HydraRingCalculationException e)
- {
- exception = e;
- }
- };
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
- {
- string[] msgs = messages.ToArray();
- Assert.AreEqual(15, msgs.Length);
-
- StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]);
-
- const string detailedReport = " Er is geen foutrapport beschikbaar.";
- RoundedDouble[] waterLevels = calculation.InputParameters.WaterLevels.ToArray();
- RoundedDouble waterLevelUpperBoundaryRevetment = waterLevels[0];
- RoundedDouble waterLevelMiddleRevetment = waterLevels[1];
- RoundedDouble waterLevelLowerBoundaryRevetment = waterLevels[2];
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' gestart.", msgs[1]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'.{detailedReport}", msgs[2]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[3]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' beëindigd.", msgs[4]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' gestart.", msgs[5]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelMiddleRevetment}'.{detailedReport}", msgs[6]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[7]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' beëindigd.", msgs[8]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' gestart.", msgs[9]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'.{detailedReport}", msgs[10]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[11]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' beëindigd.", msgs[12]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor alle waterstanden.", msgs[13]);
- StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[14]);
- });
- Assert.IsInstanceOf(exception);
- Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor alle waterstanden.", exception.Message);
- Assert.IsNull(calculation.Output);
- }
- mockRepository.VerifyAll();
- }
-
- [Test]
- public void Calculate_CalculationFailedWithoutExceptionAndWithLastErrorPresent_LogErrorAndThrowException()
- {
- // Setup
- var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
- {
- Contribution = 20
- };
-
- var mockRepository = new MockRepository();
- IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism,
- mockRepository);
- mockRepository.ReplayAll();
-
- WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation();
-
- using (new HydraRingCalculatorFactoryConfig())
- {
- TestWaveConditionsCosineCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
- calculator.EndInFailure = false;
- calculator.LastErrorFileContent = "An error occurred";
-
- HydraRingCalculationException exception = null;
-
- // Call
- Action call = () =>
- {
- try
- {
- new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
- calculation,
- assessmentSectionStub,
- failureMechanism.GeneralInput,
- validFilePath);
- }
- catch (HydraRingCalculationException e)
- {
- exception = e;
- }
- };
-
- // Assert
- TestHelper.AssertLogMessages(call, messages =>
- {
- string[] msgs = messages.ToArray();
- Assert.AreEqual(15, msgs.Length);
-
- StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]);
-
- const string detailedReport = " Bekijk het foutrapport door op details te klikken.";
- RoundedDouble[] waterLevels = calculation.InputParameters.WaterLevels.ToArray();
- RoundedDouble waterLevelUpperBoundaryRevetment = waterLevels[0];
- RoundedDouble waterLevelMiddleRevetment = waterLevels[1];
- RoundedDouble waterLevelLowerBoundaryRevetment = waterLevels[2];
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' gestart.", msgs[1]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'.{detailedReport}", msgs[2]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[3]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelUpperBoundaryRevetment}' beëindigd.", msgs[4]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' gestart.", msgs[5]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelMiddleRevetment}'.{detailedReport}", msgs[6]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[7]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelMiddleRevetment}' beëindigd.", msgs[8]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' gestart.", msgs[9]);
- StringAssert.StartsWith($"Berekening '{calculation.Name}' is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'.{detailedReport}", msgs[10]);
- StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[11]);
- Assert.AreEqual($"Berekening '{calculation.Name}' voor waterstand '{waterLevelLowerBoundaryRevetment}' beëindigd.", msgs[12]);
-
- Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor alle waterstanden.", msgs[13]);
- StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[14]);
- });
- Assert.IsInstanceOf(exception);
- Assert.AreEqual($"Berekening '{calculation.Name}' is mislukt voor alle waterstanden.", exception.Message);
- Assert.IsNull(calculation.Output);
- }
- mockRepository.VerifyAll();
- }
-
- [Test]
- public void Calculate_InnerCalculationFails_ThrowsException()
- {
- // Setup
- WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation();
- var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
-
- var mockRepository = new MockRepository();
- IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(
- waveImpactAsphaltCoverFailureMechanism, mockRepository);
- mockRepository.ReplayAll();
-
- using (new HydraRingCalculatorFactoryConfig())
- {
- TestWaveConditionsCosineCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).WaveConditionsCosineCalculator;
- calculator.EndInFailure = true;
-
- // Call
- TestDelegate test = () => new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
- calculation,
- assessmentSectionStub,
- waveImpactAsphaltCoverFailureMechanism.GeneralInput,
- validFilePath);
-
- // Assert
- Assert.Throws(test);
- }
- mockRepository.VerifyAll();
- }
-
private static WaveImpactAsphaltCoverWaveConditionsCalculation GetValidCalculation()
{
var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation