Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/SoilProfile/PipingStochasticSoilProfileTest.cs =================================================================== diff -u -r94ce658a9488c346f114446f0e37dabab7acaa38 -r26f527fb809a2325c8f883ece9da01a8f8040eb3 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/SoilProfile/PipingStochasticSoilProfileTest.cs (.../PipingStochasticSoilProfileTest.cs) (revision 94ce658a9488c346f114446f0e37dabab7acaa38) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/SoilProfile/PipingStochasticSoilProfileTest.cs (.../PipingStochasticSoilProfileTest.cs) (revision 26f527fb809a2325c8f883ece9da01a8f8040eb3) @@ -26,6 +26,7 @@ using NUnit.Framework; using Ringtoets.Piping.Data.SoilProfile; using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.KernelWrapper.TestUtil; using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Data.Test.SoilProfile @@ -84,6 +85,55 @@ } [Test] + public void Update_WithNullProfile_ThrowsArgumentNullException() + { + // Setup + var stochasticProfile = new PipingStochasticSoilProfile(0.0, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + + // Call + TestDelegate test = () => stochasticProfile.Update(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("fromProfile", paramName); + } + + [Test] + [TestCaseSource(nameof(PipingStochasticProfileUnequalCombinations))] + public void Update_WithValidProfile_UpdatesProperties(PipingStochasticSoilProfile stochasticProfile, + PipingStochasticSoilProfile otherStochasticProfile) + { + // Call + bool updated = stochasticProfile.Update(otherStochasticProfile); + + // Assert + Assert.IsTrue(updated); + Assert.AreEqual(otherStochasticProfile.Probability, stochasticProfile.Probability); + Assert.AreSame(otherStochasticProfile.SoilProfile, stochasticProfile.SoilProfile); + } + + [Test] + public void Update_WithEqualProfile_ReturnsFalse() + { + // Setup + const double probability = 1.0; + var profile = new TestPipingSoilProfile(); + var stochasticProfile = new PipingStochasticSoilProfile(probability, profile); + var otherStochasticProfile = new PipingStochasticSoilProfile(probability, profile); + + // Precondition + Assert.AreEqual(stochasticProfile, otherStochasticProfile); + + // Call + bool updated = stochasticProfile.Update(otherStochasticProfile); + + // Assert + Assert.IsFalse(updated); + Assert.AreEqual(probability, stochasticProfile.Probability); + Assert.AreSame(profile, stochasticProfile.SoilProfile); + } + + [Test] public void Equals_OtherType_ReturnsFalse() { // Setup @@ -142,6 +192,29 @@ Assert.AreEqual(hashCodeOne, hashCodeTwo); } + private static TestCaseData[] PipingStochasticProfileUnequalCombinations() + { + const string profileName = "newProfile"; + var stochasticSoilProfileA = new PipingStochasticSoilProfile(1.0, new TestPipingSoilProfile( + profileName, SoilProfileType.SoilProfile1D)); + var stochasticSoilProfileB = new PipingStochasticSoilProfile(0.5, new TestPipingSoilProfile( + profileName, SoilProfileType.SoilProfile1D)); + var stochasticSoilProfileC = new PipingStochasticSoilProfile(1.0, new TestPipingSoilProfile( + profileName, SoilProfileType.SoilProfile2D)); + + return new[] + { + new TestCaseData(stochasticSoilProfileA, stochasticSoilProfileB) + { + TestName = "Update_ProfileWithProfileA_UpdatesProperties" + }, + new TestCaseData(stochasticSoilProfileA, stochasticSoilProfileC) + { + TestName = "Update_ProfileWithProfileB_UpdatesProperties" + } + }; + } + private static TestCaseData[] StochasticProfileCombinations() { PipingStochasticSoilProfile profileA = CreateRandomStochasticProfile(21);