Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -rfa05755175660f1738a1c3bf82fb4505b93ffa1f -r6e0a4fb94b3cd5631842025c95d2b1460fc7a6ce --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision fa05755175660f1738a1c3bf82fb4505b93ffa1f) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 6e0a4fb94b3cd5631842025c95d2b1460fc7a6ce) @@ -30,6 +30,7 @@ using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.Structures; using Ringtoets.Common.Service.TestUtil; using Ringtoets.HydraRing.Calculation.Calculator; @@ -48,6 +49,17 @@ private static readonly string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); [Test] + public void Constructor_MessageProviderNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new TestStructuresCalculationService(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("messageProvider", exception.ParamName); + } + + [Test] public void Validate_CalculationNull_ThrowArgumentNullException() { // Setup @@ -329,7 +341,7 @@ var failureMechanism = new TestFailureMechanism(); // Call - TestDelegate test = () => new TestStructuresCalculationService().Calculate(null, + TestDelegate test = () => new TestStructuresCalculationService(new TestMessageProvider()).Calculate(null, assessmentSection, failureMechanism, string.Empty); @@ -348,7 +360,7 @@ var failureMechanism = new TestFailureMechanism(); // Call - TestDelegate test = () => new TestStructuresCalculationService().Calculate(calculation, + TestDelegate test = () => new TestStructuresCalculationService(new TestMessageProvider()).Calculate(calculation, null, failureMechanism, string.Empty); @@ -369,7 +381,7 @@ var calculation = new TestStructuresCalculation(); // Call - TestDelegate test = () => new TestStructuresCalculationService().Calculate(calculation, + TestDelegate test = () => new TestStructuresCalculationService(new TestMessageProvider()).Calculate(calculation, assessmentSection, null, string.Empty); @@ -405,7 +417,7 @@ using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - var service = new TestStructuresCalculationService(); + var service = new TestStructuresCalculationService(new TestMessageProvider()); // Call service.Calculate(calculation, @@ -450,7 +462,7 @@ using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - var service = new TestStructuresCalculationService(); + var service = new TestStructuresCalculationService(new TestMessageProvider()); calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call @@ -469,6 +481,8 @@ private class TestStructuresCalculationService : StructuresCalculationServiceBase { + public TestStructuresCalculationService(IStructuresCalculationMessageProvider messageProvider) : base(messageProvider) {} + protected override ExceedanceProbabilityCalculationInput CreateInput(StructuresCalculation calculation, TestFailureMechanism failureMechanism, string hydraulicBoundaryDatabaseFilePath) @@ -502,5 +516,23 @@ } } } + + private class TestMessageProvider : IStructuresCalculationMessageProvider + { + public string GetCalculationFailedMessage(string calculationSubject) + { + return $"Calculation {calculationSubject} failed."; + } + + public string GetCalculationFailedWithErrorReportMessage(string calculationSubject, string errorReport) + { + return $"Calculation {calculationSubject} failed with report {errorReport}."; + } + + public string GetCalculationPerformedMessage(string calculationSubject) + { + return $"Calculation {calculationSubject} performed."; + } + } } } \ No newline at end of file