Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs =================================================================== diff -u -r24145cb7feea063e2986e8f4b2270bb2a478b3fd -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs (.../StochasticSoilModel.cs) (revision 24145cb7feea063e2986e8f4b2270bb2a478b3fd) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModel.cs (.../StochasticSoilModel.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -24,6 +24,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Base.Geometry; +using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Data { @@ -101,30 +102,33 @@ Geometry.Add(point); } - var newNames = new List(); + var newSoilProfiles = new List(); var updatedProfiles = new List(); var addedProfiles = new List(); var removedProfiles = new List(); - foreach (var fromProfile in fromModel.StochasticSoilProfiles) + foreach (StochasticSoilProfile fromProfile in fromModel.StochasticSoilProfiles) { - StochasticSoilProfile sameProfile = StochasticSoilProfiles.SingleOrDefault(sp => sp.SoilProfile.Name.Equals(fromProfile.SoilProfile.Name)); + StochasticSoilProfile sameProfile = StochasticSoilProfiles.SingleOrDefault( + sp => IsSame(sp, fromProfile) + ); if (sameProfile != null) { if (sameProfile.Update(fromProfile)) { updatedProfiles.Add(sameProfile); - } + } } else { StochasticSoilProfiles.Add(fromProfile); addedProfiles.Add(fromProfile); } - newNames.Add(fromProfile.SoilProfile.Name); + newSoilProfiles.Add(fromProfile.SoilProfile); } - foreach (StochasticSoilProfile profileToRemove in StochasticSoilProfiles.Where(sp => !newNames.Contains(sp.SoilProfile.Name)).ToArray()) + foreach (StochasticSoilProfile profileToRemove in StochasticSoilProfiles.Where( + sp => !newSoilProfiles.Any(newSp => IsSame(newSp, sp.SoilProfile))).ToArray()) { StochasticSoilProfiles.Remove(profileToRemove); removedProfiles.Add(profileToRemove); @@ -137,5 +141,16 @@ { return Name; } + + private static bool IsSame(PipingSoilProfile pipingSoilProfile, PipingSoilProfile otherPipingSoilProfile) + { + return pipingSoilProfile.Name.Equals(otherPipingSoilProfile.Name) + && pipingSoilProfile.SoilProfileType.Equals(otherPipingSoilProfile.SoilProfileType); + } + + private static bool IsSame(StochasticSoilProfile stochasticSoilProfile, StochasticSoilProfile otherStochasticSoilProfile) + { + return IsSame(stochasticSoilProfile.SoilProfile, otherStochasticSoilProfile.SoilProfile); + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs =================================================================== diff -u -r7172df944db7fd2d59d68a7a8def96110a44ed9b -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 7172df944db7fd2d59d68a7a8def96110a44ed9b) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -53,7 +53,7 @@ /// /// Gets the type of the stochastic soil profile. /// - public SoilProfileType SoilProfileType { get; } + public SoilProfileType SoilProfileType { get; private set; } /// /// Gets the database identifier of the stochastic soil profile. @@ -119,6 +119,7 @@ if (!Equals(fromProfile)) { SoilProfile = fromProfile.SoilProfile; + SoilProfileType = fromProfile.SoilProfileType; Probability = fromProfile.Probability; return true; } Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs =================================================================== diff -u -r34023112e9d57acf92ed6a713d6e2d1df8548098 -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision 34023112e9d57acf92ed6a713d6e2d1df8548098) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -264,6 +264,41 @@ } [Test] + public void Update_ModelWithRemovedProfileSameNameOtherType_ProfileRemoved() + { + // Setup + var profileName = "A"; + var soilProfile = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D, -5); + var expectedRemovedProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3) + { + SoilProfile = soilProfile + }; + var newProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile2D, 3) + { + SoilProfile = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile2D, -5) + }; + StochasticSoilModel model = CreateEmptyModel(); + model.StochasticSoilProfiles.Add(expectedRemovedProfile); + + StochasticSoilModel otherModel = CreateEmptyModel(); + otherModel.StochasticSoilProfiles.Add(newProfile); + + // Call + StochasticSoilModelProfileDifference difference = model.Update(otherModel); + + // Assert + CollectionAssert.AreEqual(new[] + { + newProfile + }, difference.AddedProfiles); + CollectionAssert.IsEmpty(difference.UpdatedProfiles); + CollectionAssert.AreEqual(new[] + { + expectedRemovedProfile + }, difference.RemovedProfiles); + } + + [Test] public void Update_WithOtherModel_PropertiesUpdated() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs =================================================================== diff -u -r583456a0f5395189a54a8cedf4e4a7b40945d990 -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 583456a0f5395189a54a8cedf4e4a7b40945d990) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -120,27 +120,48 @@ } [Test] - public void Update_WithValidProfile_UpdatesProperties() + [TestCaseSource(nameof(StochasticProfileUnequalCombinations))] + public void Update_WithValidProfile_UpdatesProperties(StochasticSoilProfile stochasticProfile, StochasticSoilProfile otherStochasticProfile) { - // Setup - var newProbability = 1.0; - var newProfile = new TestPipingSoilProfile(); - var otherStochasticProfile = new StochasticSoilProfile(newProbability, SoilProfileType.SoilProfile1D, 0) - { - SoilProfile = newProfile - }; - - var stochasticProfile = new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 0); - // Call bool updated = stochasticProfile.Update(otherStochasticProfile); // Assert Assert.IsTrue(updated); - Assert.AreEqual(newProbability, stochasticProfile.Probability); - Assert.AreSame(newProfile, stochasticProfile.SoilProfile); + Assert.AreEqual(otherStochasticProfile.Probability, stochasticProfile.Probability); + Assert.AreEqual(otherStochasticProfile.SoilProfileType, stochasticProfile.SoilProfileType); + Assert.AreSame(otherStochasticProfile.SoilProfile, stochasticProfile.SoilProfile); } + private static TestCaseData[] StochasticProfileUnequalCombinations() + { + const string profileName = "newProfile"; + var stochasticSoilProfile = new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new TestPipingSoilProfile(profileName, SoilProfileType.SoilProfile1D) + }; + var otherStochasticSoilProfileA = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new TestPipingSoilProfile(profileName, SoilProfileType.SoilProfile1D) + }; + var otherStochasticSoilProfileB = new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile2D, 0) + { + SoilProfile = new TestPipingSoilProfile(profileName, SoilProfileType.SoilProfile2D) + }; + + return new[] + { + new TestCaseData(stochasticSoilProfile, otherStochasticSoilProfileA) + { + TestName = "Update_ProfileWithProfileA_UpdatesProperties" + }, + new TestCaseData(stochasticSoilProfile, otherStochasticSoilProfileB) + { + TestName = "Update_ProfileWithProfileB_UpdatesProperties" + } + }; + } + [Test] public void Update_WithEqualProfile_ReturnsFalse() { @@ -255,8 +276,8 @@ StochasticSoilProfile profileA = CreateRandomStochasticProfile(21); StochasticSoilProfile profileB = CreateRandomStochasticProfile(21); StochasticSoilProfile profileC = CreateRandomStochasticProfile(73); - StochasticSoilProfile profileE = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 25); - StochasticSoilProfile profileF = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 45); + var profileE = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 25); + var profileF = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 45); return new[] { @@ -278,7 +299,7 @@ private static StochasticSoilProfile CreateRandomStochasticProfile(int randomSeed) { var random = new Random(randomSeed); - return new StochasticSoilProfile(random.NextDouble(), SoilProfileType.SoilProfile1D, profileIdRandom.Next()) + return new StochasticSoilProfile(random.NextDouble(), random.NextEnumValue(), profileIdRandom.Next()) { SoilProfile = CreateRandomProfile(random) }; @@ -301,7 +322,7 @@ PermeabilityDeviation = random.NextDouble(), PermeabilityMean = random.NextDouble() } - }, SoilProfileType.SoilProfile1D, random.Next()); + }, random.NextEnumValue(), random.Next()); } private static string GetRandomName(Random random) Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/Ringtoets.Piping.KernelWrapper.TestUtil.Test.csproj =================================================================== diff -u -r5e70f173b3839314912e086b6c1c784b975ee646 -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/Ringtoets.Piping.KernelWrapper.TestUtil.Test.csproj (.../Ringtoets.Piping.KernelWrapper.TestUtil.Test.csproj) (revision 5e70f173b3839314912e086b6c1c784b975ee646) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/Ringtoets.Piping.KernelWrapper.TestUtil.Test.csproj (.../Ringtoets.Piping.KernelWrapper.TestUtil.Test.csproj) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -69,6 +69,10 @@ + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + {D64E4F0E-E341-496F-82B2-941AD202B4E3} Ringtoets.Piping.KernelWrapper Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/TestPipingSoilProfileTest.cs =================================================================== diff -u -r5e70f173b3839314912e086b6c1c784b975ee646 -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/TestPipingSoilProfileTest.cs (.../TestPipingSoilProfileTest.cs) (revision 5e70f173b3839314912e086b6c1c784b975ee646) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/TestPipingSoilProfileTest.cs (.../TestPipingSoilProfileTest.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -19,8 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Linq; using NUnit.Framework; +using Ringtoets.Piping.Primitives; +using Core.Common.TestUtil; namespace Ringtoets.Piping.KernelWrapper.TestUtil.Test { @@ -36,6 +39,7 @@ // Assert Assert.IsEmpty(profile.Name); Assert.AreEqual(0.0, profile.Bottom); + Assert.AreEqual(SoilProfileType.SoilProfile1D, profile.SoilProfileType); CollectionAssert.AreEquivalent(new[] { true }, profile.Layers.Select(l => l.IsAquifer)); CollectionAssert.AreEquivalent(new[] { 0.0 }, profile.Layers.Select(l => l.Top)); } @@ -44,16 +48,35 @@ public void Constructor_WitValidName_ExpectedPropertiesSet() { // Setup - var name = "some name"; + const string name = "some name"; // Call var profile = new TestPipingSoilProfile(name); // Assert Assert.AreEqual(name, profile.Name); Assert.AreEqual(0.0, profile.Bottom); + Assert.AreEqual(SoilProfileType.SoilProfile1D, profile.SoilProfileType); CollectionAssert.AreEquivalent(new[] { true }, profile.Layers.Select(l => l.IsAquifer)); CollectionAssert.AreEquivalent(new[] { 0.0 }, profile.Layers.Select(l => l.Top)); } + + [Test] + public void Constructor_WitValidNameAndType_ExpectedPropertiesSet() + { + // Setup + const string name = "some name"; + SoilProfileType soilProfileType = new Random(6543).NextEnumValue(); + + // Call + var profile = new TestPipingSoilProfile(name, soilProfileType); + + // Assert + Assert.AreEqual(name, profile.Name); + Assert.AreEqual(0.0, profile.Bottom); + Assert.AreEqual(soilProfileType, profile.SoilProfileType); + CollectionAssert.AreEquivalent(new[] { true }, profile.Layers.Select(l => l.IsAquifer)); + CollectionAssert.AreEquivalent(new[] { 0.0 }, profile.Layers.Select(l => l.Top)); + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/TestPipingSoilProfile.cs =================================================================== diff -u -ra9ab2d906323a908ed5e7a245b5813380776961a -r303f3924f66df0bc726646b29031a926a94882bc --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/TestPipingSoilProfile.cs (.../TestPipingSoilProfile.cs) (revision a9ab2d906323a908ed5e7a245b5813380776961a) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/TestPipingSoilProfile.cs (.../TestPipingSoilProfile.cs) (revision 303f3924f66df0bc726646b29031a926a94882bc) @@ -38,6 +38,7 @@ /// set to 0.0 /// set to a collection with a single /// with set to 0.0. + /// set to . /// /// public TestPipingSoilProfile() : this("") {} @@ -50,15 +51,31 @@ /// set to 0.0 /// set to a collection with a single /// with set to 0.0. + /// set to . /// /// /// The name for the profile. - public TestPipingSoilProfile(string name) : base(name, 0.0, new Collection + public TestPipingSoilProfile(string name) : this(name, SoilProfileType.SoilProfile1D) {} + + /// + /// Creates a new instance of , which is a + /// which has: + /// + /// set to + /// set to 0.0 + /// set to a collection with a single + /// with set to 0.0. + /// set to . + /// + /// + /// The name for the profile. + /// The type of the profile. + public TestPipingSoilProfile(string name, SoilProfileType soilProfileType) : base(name, 0.0, new Collection { new PipingSoilLayer(0.0) { IsAquifer = true } - }, SoilProfileType.SoilProfile1D, 0) {} + }, soilProfileType, 0) {} } } \ No newline at end of file