Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs
===================================================================
diff -u -rc1e57c344103b0219edc5bb853da2a0ca5c41877 -r24145cb7feea063e2986e8f4b2270bb2a478b3fd
--- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision c1e57c344103b0219edc5bb853da2a0ca5c41877)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelTest.cs (.../StochasticSoilModelTest.cs) (revision 24145cb7feea063e2986e8f4b2270bb2a478b3fd)
@@ -1,25 +1,5 @@
-// Copyright (C) Stichting Deltares 2016. All rights reserved.
-//
-// This file is part of Ringtoets.
-//
-// Ringtoets is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-//
-// All names, logos, and references to "Deltares" are registered trademarks of
-// Stichting Deltares and remain full property of Stichting Deltares at all times.
-// All rights reserved.
-
-using System;
+using System;
+using System.Collections.Generic;
using Core.Common.Base;
using Core.Common.Base.Geometry;
using NUnit.Framework;
@@ -38,15 +18,15 @@
public void Constructor_Always_ExpectedValues(long segmentSoilModelId, string segmentSoilModelName, string segmentName)
{
// Call
- StochasticSoilModel stochasticSoilModelSegment = new StochasticSoilModel(segmentSoilModelId, segmentSoilModelName, segmentName);
+ var stochasticSoilModel = new StochasticSoilModel(segmentSoilModelId, segmentSoilModelName, segmentName);
// Assert
- Assert.IsInstanceOf(stochasticSoilModelSegment);
- Assert.AreEqual(segmentSoilModelId, stochasticSoilModelSegment.Id);
- Assert.AreEqual(segmentSoilModelName, stochasticSoilModelSegment.Name);
- Assert.AreEqual(segmentName, stochasticSoilModelSegment.SegmentName);
- CollectionAssert.IsEmpty(stochasticSoilModelSegment.Geometry);
- CollectionAssert.IsEmpty(stochasticSoilModelSegment.StochasticSoilProfiles);
+ Assert.IsInstanceOf(stochasticSoilModel);
+ Assert.AreEqual(segmentSoilModelId, stochasticSoilModel.Id);
+ Assert.AreEqual(segmentSoilModelName, stochasticSoilModel.Name);
+ Assert.AreEqual(segmentName, stochasticSoilModel.SegmentName);
+ CollectionAssert.IsEmpty(stochasticSoilModel.Geometry);
+ CollectionAssert.IsEmpty(stochasticSoilModel.StochasticSoilProfiles);
}
[Test]
@@ -56,18 +36,18 @@
const long expectedSegmentSoilModelId = 1234L;
const string expectedSegmentSoilModelName = "someSegmentSoilModelName";
const string expectedSegmentName = "someSegmentName";
- StochasticSoilModel stochasticSoilModelSegment = new StochasticSoilModel(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName);
+ var stochasticSoilModel = new StochasticSoilModel(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName);
var point2D = new Point2D(1.0, 2.0);
// Call
- stochasticSoilModelSegment.Geometry.Add(point2D);
+ stochasticSoilModel.Geometry.Add(point2D);
// Assert
- Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModelSegment.Id);
- Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModelSegment.Name);
- Assert.AreEqual(expectedSegmentName, stochasticSoilModelSegment.SegmentName);
- Assert.AreEqual(1, stochasticSoilModelSegment.Geometry.Count);
- Assert.AreEqual(point2D, stochasticSoilModelSegment.Geometry[0]);
+ Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModel.Id);
+ Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModel.Name);
+ Assert.AreEqual(expectedSegmentName, stochasticSoilModel.SegmentName);
+ Assert.AreEqual(1, stochasticSoilModel.Geometry.Count);
+ Assert.AreEqual(point2D, stochasticSoilModel.Geometry[0]);
}
[Test]
@@ -77,21 +57,21 @@
const long expectedSegmentSoilModelId = 1234L;
const string expectedSegmentSoilModelName = "someSegmentSoilModelName";
const string expectedSegmentName = "someSegmentName";
- StochasticSoilModel stochasticSoilModelSegment = new StochasticSoilModel(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName);
+ var stochasticSoilModel = new StochasticSoilModel(expectedSegmentSoilModelId, expectedSegmentSoilModelName, expectedSegmentName);
- MockRepository mockRepository = new MockRepository();
+ var mockRepository = new MockRepository();
var stochasticSoilProfileProbabilityMock = mockRepository.StrictMock(1.0, null, null);
mockRepository.ReplayAll();
// Call
- stochasticSoilModelSegment.StochasticSoilProfiles.Add(stochasticSoilProfileProbabilityMock);
+ stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfileProbabilityMock);
// Assert
- Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModelSegment.Id);
- Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModelSegment.Name);
- Assert.AreEqual(expectedSegmentName, stochasticSoilModelSegment.SegmentName);
- Assert.AreEqual(1, stochasticSoilModelSegment.StochasticSoilProfiles.Count);
- Assert.AreEqual(stochasticSoilProfileProbabilityMock, stochasticSoilModelSegment.StochasticSoilProfiles[0]);
+ Assert.AreEqual(expectedSegmentSoilModelId, stochasticSoilModel.Id);
+ Assert.AreEqual(expectedSegmentSoilModelName, stochasticSoilModel.Name);
+ Assert.AreEqual(expectedSegmentName, stochasticSoilModel.SegmentName);
+ Assert.AreEqual(1, stochasticSoilModel.StochasticSoilProfiles.Count);
+ Assert.AreEqual(stochasticSoilProfileProbabilityMock, stochasticSoilModel.StochasticSoilProfiles[0]);
mockRepository.VerifyAll();
}
@@ -110,13 +90,144 @@
}
[Test]
+ public void Update_ModelWithUpdatedProperties_PropertiesUpdated()
+ {
+ // Assert
+ var model = new StochasticSoilModel(1234, "name", "segment");
+ model.Geometry.AddRange(new[]
+ {
+ new Point2D(1, 2),
+ new Point2D(4, 5)
+ });
+
+ const int expectedId = 1236;
+ const string expectedName = "otherName";
+ const string expectedSegmentName = "otherSegmentName";
+ var expectedGeometry = new[]
+ {
+ new Point2D(4, 2)
+ };
+
+ var otherModel = new StochasticSoilModel(expectedId, expectedName, expectedSegmentName);
+ otherModel.Geometry.AddRange(expectedGeometry);
+
+ // Call
+ StochasticSoilModelProfileDifference difference = model.Update(otherModel);
+
+ // Assert
+ Assert.AreEqual(expectedId, model.Id);
+ Assert.AreEqual(expectedName, model.Name);
+ Assert.AreEqual(expectedSegmentName, model.SegmentName);
+ CollectionAssert.AreEqual(expectedGeometry, model.Geometry);
+
+ CollectionAssert.IsEmpty(difference.AddedProfiles);
+ CollectionAssert.IsEmpty(difference.UpdatedProfiles);
+ CollectionAssert.IsEmpty(difference.RemovedProfiles);
+ }
+
+ [Test]
+ public void Update_ModelWithAddedProfile_ProfileAdded()
+ {
+ // Setup
+ StochasticSoilModel model = CreateEmptyModel();
+ StochasticSoilModel otherModel = CreateEmptyModel();
+ var expectedAddedProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3)
+ {
+ SoilProfile = new TestPipingSoilProfile()
+ };
+ otherModel.StochasticSoilProfiles.Add(expectedAddedProfile);
+
+ // Call
+ StochasticSoilModelProfileDifference difference = model.Update(otherModel);
+
+ // Assert
+ Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count);
+ Assert.AreEqual(expectedAddedProfile, otherModel.StochasticSoilProfiles[0]);
+
+ CollectionAssert.AreEqual(new[]
+ {
+ expectedAddedProfile
+ }, difference.AddedProfiles);
+ CollectionAssert.IsEmpty(difference.UpdatedProfiles);
+ CollectionAssert.IsEmpty(difference.RemovedProfiles);
+ }
+
+ [Test]
+ public void Update_ModelWithUpdatedProfile_ProfileUpdated()
+ {
+ // Setup
+ var profileName = "A";
+ var expectedUpdatedProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3)
+ {
+ SoilProfile = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D, -5)
+ };
+ StochasticSoilModel model = CreateEmptyModel();
+ model.StochasticSoilProfiles.Add(expectedUpdatedProfile);
+ StochasticSoilModel otherModel = CreateEmptyModel();
+ otherModel.StochasticSoilProfiles.Add(new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3)
+ {
+ SoilProfile = new PipingSoilProfile(profileName, -1, CreateLayers(), SoilProfileType.SoilProfile1D, -5)
+ });
+
+ // Call
+ StochasticSoilModelProfileDifference difference = model.Update(otherModel);
+
+ // Assert
+ Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count);
+ Assert.AreEqual(expectedUpdatedProfile, otherModel.StochasticSoilProfiles[0]);
+
+ CollectionAssert.IsEmpty(difference.AddedProfiles);
+ CollectionAssert.AreEqual(new[]
+ {
+ expectedUpdatedProfile
+ }, difference.UpdatedProfiles);
+ CollectionAssert.IsEmpty(difference.RemovedProfiles);
+ }
+
+ [Test]
+ public void Update_ModelWithUpdatedStochasticSoilProfile_ProfileUpdated()
+ {
+ // Setup
+ var profileName = "A";
+ var soilProfile = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D, -5);
+ var expectedUpdatedProfile = new StochasticSoilProfile(0.2, SoilProfileType.SoilProfile1D, 3)
+ {
+ SoilProfile = soilProfile
+ };
+ StochasticSoilModel model = CreateEmptyModel();
+ model.StochasticSoilProfiles.Add(expectedUpdatedProfile);
+
+ StochasticSoilModel otherModel = CreateEmptyModel();
+ otherModel.StochasticSoilProfiles.Add(new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 3)
+ {
+ SoilProfile = soilProfile
+ });
+
+ // Call
+ StochasticSoilModelProfileDifference difference = model.Update(otherModel);
+
+ // Assert
+ CollectionAssert.IsEmpty(difference.AddedProfiles);
+ CollectionAssert.AreEqual(new[]
+ {
+ expectedUpdatedProfile
+ }, difference.UpdatedProfiles);
+ CollectionAssert.IsEmpty(difference.RemovedProfiles);
+ }
+
+ [Test]
+ public void Update_ModelWithRemovedProfile_ProfileRemoved()
+ {
+ var modelName = "name";
+ StochasticSoilModel model = CreateEmptyModel();
+ }
+
+ [Test]
public void Update_WithOtherModel_PropertiesUpdated()
{
// Setup
var equalProfileName = "nameA";
- var model = new StochasticSoilModel(1234, "name", "segment");
- model.Geometry.Add(new Point2D(6, 2));
- model.Geometry.Add(new Point2D(4, 3));
+ StochasticSoilModel model = CreateEmptyModel();
var stochasticProfileA = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, -11)
{
@@ -133,14 +244,17 @@
var otherSegmentName = "other segment";
var otherModel = new StochasticSoilModel(41, otherName, otherSegmentName);
- var otherPointA = new Point2D(2,0);
- var otherPointB = new Point2D(3,0);
+ var otherPointA = new Point2D(2, 0);
+ var otherPointB = new Point2D(3, 0);
otherModel.Geometry.Add(otherPointA);
otherModel.Geometry.Add(otherPointB);
var otherStochasticProfileA = new StochasticSoilProfile(0.7, SoilProfileType.SoilProfile1D, -1)
{
- SoilProfile = new TestPipingSoilProfile(equalProfileName)
+ SoilProfile = new PipingSoilProfile(equalProfileName, -1, new[]
+ {
+ new PipingSoilLayer(0)
+ }, SoilProfileType.SoilProfile1D, -1)
};
var otherStochasticProfileB = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, -2)
{
@@ -150,7 +264,7 @@
otherModel.StochasticSoilProfiles.Add(otherStochasticProfileB);
// Call
- model.Update(otherModel);
+ StochasticSoilModelProfileDifference difference = model.Update(otherModel);
// Assert
Assert.AreEqual(otherName, model.Name);
@@ -162,6 +276,19 @@
Assert.AreSame(otherStochasticProfileA.SoilProfile, model.StochasticSoilProfiles[0].SoilProfile);
Assert.AreNotSame(stochasticProfileB, model.StochasticSoilProfiles[1]);
Assert.AreSame(otherStochasticProfileB.SoilProfile, model.StochasticSoilProfiles[1].SoilProfile);
+
+ CollectionAssert.AreEqual(new[]
+ {
+ stochasticProfileA
+ }, difference.UpdatedProfiles);
+ CollectionAssert.AreEqual(new[]
+ {
+ stochasticProfileB
+ }, difference.RemovedProfiles);
+ CollectionAssert.AreEqual(new[]
+ {
+ otherStochasticProfileB
+ }, difference.AddedProfiles);
}
[Test]
@@ -176,5 +303,19 @@
// Call & Assert
Assert.AreEqual(name, stochasticSoilModel.ToString());
}
+
+ private IEnumerable CreateLayers()
+ {
+ return new[]
+ {
+ new PipingSoilLayer(2),
+ };
+ }
+
+ private StochasticSoilModel CreateEmptyModel()
+ {
+ var model = new StochasticSoilModel(1234, "name", "segment");
+ return model;
+ }
}
}
\ No newline at end of file