Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfile/MacroStabilityInwardsStochasticSoilModelTest.cs =================================================================== diff -u -r69d647795daacbf48e17d0cf3a02a21865ab4ae6 -rda4a311b2ac60defe1a27a61c8d151f47268a941 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfile/MacroStabilityInwardsStochasticSoilModelTest.cs (.../MacroStabilityInwardsStochasticSoilModelTest.cs) (revision 69d647795daacbf48e17d0cf3a02a21865ab4ae6) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/SoilProfile/MacroStabilityInwardsStochasticSoilModelTest.cs (.../MacroStabilityInwardsStochasticSoilModelTest.cs) (revision da4a311b2ac60defe1a27a61c8d151f47268a941) @@ -25,6 +25,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Data.TestUtil.SoilProfile; @@ -37,34 +38,72 @@ [Test] public void Constructor_WithoutName_ExpectedValues() { + // Setup + var random = new Random(21); + // Call - TestDelegate test = () => new MacroStabilityInwardsStochasticSoilModel(null); + TestDelegate test = () => new MacroStabilityInwardsStochasticSoilModel(null, new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); // Assert var exception = Assert.Throws(test); Assert.AreEqual("name", exception.ParamName); } + [Test] + public void Constructor_GeometryNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new MacroStabilityInwardsStochasticSoilModel(string.Empty, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("geometry", exception.ParamName); + } + [Test] + public void Constructor_GeometryEmpty_ThrowsArgumentException() + { + // Setup + const string name = "modelName"; + + // Call + TestDelegate call = () => new MacroStabilityInwardsStochasticSoilModel(name, null); + + // Assert + string expectedMessage = $"Het stochastische ondergrond model '{name}'moet een geometrie bevatten."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] [TestCase("")] [TestCase("segmentSoilModelName")] public void Constructor_WithName_ExpectedValues(string segmentSoilModelName) { + // Setup + var random = new Random(21); + var geometry = new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }; + // Call - var stochasticSoilModel = new MacroStabilityInwardsStochasticSoilModel(segmentSoilModelName); + var stochasticSoilModel = new MacroStabilityInwardsStochasticSoilModel(segmentSoilModelName, geometry); // Assert Assert.IsInstanceOf(stochasticSoilModel); Assert.AreEqual(segmentSoilModelName, stochasticSoilModel.Name); - CollectionAssert.IsEmpty(stochasticSoilModel.Geometry); + Assert.AreSame(geometry, stochasticSoilModel.Geometry); CollectionAssert.IsEmpty(stochasticSoilModel.StochasticSoilProfiles); } [Test] public void Update_WithNullModel_ThrowsArgumentNullException() { // Setup - var model = new MacroStabilityInwardsStochasticSoilModel("name"); + MacroStabilityInwardsStochasticSoilModel model = CreateEmptyModel(); // Call TestDelegate test = () => model.Update(null); @@ -78,22 +117,18 @@ public void Update_ModelWithUpdatedProperties_PropertiesUpdated() { // Setup - var model = new MacroStabilityInwardsStochasticSoilModel("name"); - model.Geometry.AddRange(new[] + var model = new MacroStabilityInwardsStochasticSoilModel("name", new[] { new Point2D(1, 2), new Point2D(4, 5) }); const string expectedName = "otherName"; - var expectedGeometry = new[] + var otherModel = new MacroStabilityInwardsStochasticSoilModel(expectedName, new[] { new Point2D(4, 2) - }; + }); - var otherModel = new MacroStabilityInwardsStochasticSoilModel(expectedName); - otherModel.Geometry.AddRange(expectedGeometry); - // Call MacroStabilityInwardsStochasticSoilModelProfileDifference difference = model.Update(otherModel); @@ -250,13 +285,13 @@ model.StochasticSoilProfiles.Add(stochasticProfileB); const string otherName = "other name"; - var otherModel = new MacroStabilityInwardsStochasticSoilModel(otherName); + var otherGeometry = new[] + { + new Point2D(2, 0), + new Point2D(3, 0) + }; + var otherModel = new MacroStabilityInwardsStochasticSoilModel(otherName, otherGeometry); - var otherPointA = new Point2D(2, 0); - var otherPointB = new Point2D(3, 0); - otherModel.Geometry.Add(otherPointA); - otherModel.Geometry.Add(otherPointB); - var otherStochasticProfileA = new MacroStabilityInwardsStochasticSoilProfile( 0.7, new MacroStabilityInwardsSoilProfile1D(equalProfileName, -1, new[] @@ -272,8 +307,7 @@ // Assert AssertStochasticSoilModelAreEqual(otherModel, model); - Assert.AreSame(otherPointA, model.Geometry[0]); - Assert.AreSame(otherPointB, model.Geometry[1]); + Assert.AreSame(otherGeometry, model.Geometry); Assert.AreEqual(2, model.StochasticSoilProfiles.Count); Assert.AreSame(stochasticProfileA, model.StochasticSoilProfiles[0]); Assert.AreSame(otherStochasticProfileA.SoilProfile, model.StochasticSoilProfiles[0].SoilProfile); @@ -307,7 +341,7 @@ otherModel.StochasticSoilProfiles.Add(addedStochasticSoilProfile); MacroStabilityInwardsSoilProfile1D soilProfile = MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(profileName); - var existingStochasticSoilProfileOne = new MacroStabilityInwardsStochasticSoilProfile(0.2,soilProfile); + var existingStochasticSoilProfileOne = new MacroStabilityInwardsStochasticSoilProfile(0.2, soilProfile); var existingStochasticSoilProfileTwo = new MacroStabilityInwardsStochasticSoilProfile(0.3, soilProfile); MacroStabilityInwardsStochasticSoilModel model = CreateEmptyModel(); @@ -337,7 +371,12 @@ public void ToString_WithName_ReturnsName(string name) { // Setup - var stochasticSoilModel = new MacroStabilityInwardsStochasticSoilModel(name); + var random = new Random(21); + var stochasticSoilModel = new MacroStabilityInwardsStochasticSoilModel(name, + new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); // Call & Assert Assert.AreEqual(name, stochasticSoilModel.ToString()); @@ -385,7 +424,12 @@ private static MacroStabilityInwardsStochasticSoilModel CreateEmptyModel() { - return new MacroStabilityInwardsStochasticSoilModel("name"); + var random = new Random(21); + return new MacroStabilityInwardsStochasticSoilModel("name", + new[] + { + new Point2D(random.NextDouble(), random.NextDouble()) + }); } private static void AssertStochasticSoilModelAreEqual(MacroStabilityInwardsStochasticSoilModel expected,