Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs =================================================================== diff -u -r8905298103eb01ce13dd5c1a2f267f879d4fda3e -rffe6f47c5c38e57f5c0c0d9c699c88ac6c818e7c --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision 8905298103eb01ce13dd5c1a2f267f879d4fda3e) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision ffe6f47c5c38e57f5c0c0d9c699c88ac6c818e7c) @@ -52,6 +52,37 @@ private static readonly string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); [Test] + public void Validate_CalculationNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => HeightStructuresCalculationService.Validate(null, assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculation", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Validate_AssessmentSectionNull_ThrowArgumentNullException() + { + // Setup + var calculation = new TestHeightStructuresCalculation(); + + // Call + TestDelegate test = () => HeightStructuresCalculationService.Validate(calculation, null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] public void Validate_ValidCalculationInvalidHydraulicBoundaryDatabase_ReturnsFalse() { // Setup @@ -73,9 +104,9 @@ var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); var calculationName = calculation.Name; - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculationName), msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculationName}' gestart om: ", msgs[0]); StringAssert.StartsWith("Validatie mislukt: Fout bij het lezen van bestand", msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[2]); + StringAssert.StartsWith($"Validatie van '{calculationName}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -104,9 +135,9 @@ var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); var calculationName = calculation.Name; - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculationName), msgs[0]); + StringAssert.StartsWith($"Validatie van '{calculationName}' gestart om: ", msgs[0]); StringAssert.StartsWith("Validatie mislukt: Fout bij het lezen van bestand", msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculationName), msgs[2]); + StringAssert.StartsWith($"Validatie van '{calculationName}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -143,9 +174,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); StringAssert.StartsWith("Validatie mislukt: Er is geen kunstwerk geselecteerd.", msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -178,9 +209,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual("Validatie mislukt: Er is geen hydraulische randvoorwaardenlocatie geselecteerd.", msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -221,17 +252,17 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual(expectedValidationMessage, msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); mockRepository.VerifyAll(); } [Test] - [TestCaseSource("NormalDistributionsWithInvalidMean")] + [TestCaseSource(nameof(NormalDistributionsWithInvalidMean))] public void Validate_NormalDistributionMeanInvalid_LogsErrorAndReturnsFalse(double meanOne, double meanTwo, double meanThree, string parameterName) { // Setup @@ -243,7 +274,7 @@ assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; const string name = ""; - string expectedValidationMessage = string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een concreet getal zijn.", parameterName); + string expectedValidationMessage = $"Validatie mislukt: De verwachtingswaarde voor '{parameterName}' moet een concreet getal zijn."; var calculation = new TestHeightStructuresCalculation { @@ -267,17 +298,17 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual(expectedValidationMessage, msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); mockRepository.VerifyAll(); } [Test] - [TestCaseSource("LogNormalDistributionsWithInvalidMean")] + [TestCaseSource(nameof(LogNormalDistributionsWithInvalidMean))] public void Validate_LogNormalDistributionMeanInvalid_LogsErrorAndReturnsFalse(double meanOne, double meanTwo, double meanThree, double meanFour, double meanFive, string parameterName) { @@ -289,7 +320,7 @@ assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; const string name = ""; - string expectedValidationMessage = string.Format("Validatie mislukt: De verwachtingswaarde voor '{0}' moet een positief getal zijn.", parameterName); + string expectedValidationMessage = $"Validatie mislukt: De verwachtingswaarde voor '{parameterName}' moet een positief getal zijn."; var calculation = new TestHeightStructuresCalculation { @@ -315,17 +346,17 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual(expectedValidationMessage, msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); mockRepository.VerifyAll(); } [Test] - [TestCaseSource("DistributionsWithInvalidDeviation")] + [TestCaseSource(nameof(DistributionsWithInvalidDeviation))] public void Validate_DistributionStandardDeviationInvalid_LogsErrorAndReturnsFalse(double deviationOne, double deviationTwo, double deviationThree, double deviationFour, string parameterName) { @@ -337,7 +368,7 @@ assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; const string name = ""; - string expectedValidationMessage = string.Format("Validatie mislukt: De standaardafwijking voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterName); + string expectedValidationMessage = $"Validatie mislukt: De standaardafwijking voor '{parameterName}' moet groter zijn dan of gelijk zijn aan 0."; var calculation = new TestHeightStructuresCalculation { @@ -362,17 +393,17 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual(expectedValidationMessage, msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); mockRepository.VerifyAll(); } [Test] - [TestCaseSource("DistributionsWithInvalidCoefficient")] + [TestCaseSource(nameof(DistributionsWithInvalidCoefficient))] public void Validate_DistributionVariationCoefficientInvalid_LogsErrorAndReturnsFalse( double coefficientOne, double coefficientTwo, double coefficientThree, double coefficientFour, string parameterName) { @@ -384,7 +415,7 @@ assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; const string name = ""; - string expectedValidationMessage = string.Format("Validatie mislukt: De variatiecoëfficiënt voor '{0}' moet groter zijn dan of gelijk zijn aan 0.", parameterName); + string expectedValidationMessage = $"Validatie mislukt: De variatiecoëfficiënt voor '{parameterName}' moet groter zijn dan of gelijk zijn aan 0."; var calculation = new TestHeightStructuresCalculation { @@ -409,9 +440,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual(expectedValidationMessage, msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -453,9 +484,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); Assert.AreEqual("Validatie mislukt: Er is geen geldige damhoogte ingevoerd.", msgs[1]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[2]); }); Assert.IsFalse(isValid); @@ -492,15 +523,77 @@ { var msgs = messages.ToArray(); Assert.AreEqual(2, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[1]); + StringAssert.StartsWith($"Validatie van '{name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"Validatie van '{name}' beëindigd om: ", msgs[1]); }); Assert.IsTrue(isValid); mockRepository.VerifyAll(); } [Test] + public void Calculate_CalculationNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + TestDelegate test = () => new HeightStructuresCalculationService().Calculate(null, + assessmentSection, + failureMechanism, + string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculation", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Calculate_AssessmentSectionNull_ThrowArgumentNullException() + { + // Setup + var calculation = new TestHeightStructuresCalculation(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + TestDelegate test = () => new HeightStructuresCalculationService().Calculate(calculation, + null, + failureMechanism, + string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Calculate_FailureMechanismNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new TestHeightStructuresCalculation(); + + // Call + TestDelegate test = () => new HeightStructuresCalculationService().Calculate(calculation, + assessmentSection, + null, + string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] [TestCase(CalculationType.NoForeshore)] [TestCase(CalculationType.ForeshoreWithValidBreakWater)] [TestCase(CalculationType.ForeshoreWithoutBreakWater)] @@ -557,11 +650,11 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie" + "" + "", msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[2]); }); Assert.IsNotNull(calculation.Output); } @@ -610,9 +703,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[2]); }); Assert.IsNotNull(calculation.Output); } @@ -793,10 +886,10 @@ { var msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[1]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"De berekening voor hoogte kunstwerk '{calculation.Name}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", msgs[1]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(calculation.Output); @@ -856,10 +949,10 @@ { var msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[1]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"De berekening voor hoogte kunstwerk '{calculation.Name}' is niet gelukt. Er is geen foutrapport beschikbaar.", msgs[1]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(calculation.Output); @@ -922,11 +1015,10 @@ { var msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", - calculation.Name), msgs[1]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' gestart om: ", msgs[0]); + StringAssert.StartsWith($"De berekening voor hoogte kunstwerk '{calculation.Name}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", msgs[1]); StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + StringAssert.StartsWith($"Berekening van '{calculation.Name}' beëindigd om: ", msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(calculation.Output);