Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs =================================================================== diff -u -rd2b5b334c49948fa49297a1d24c13bc98aa6ee1e -rdc2b06cb5a46cf2508d28fe9a6f8dcaa710346a7 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision d2b5b334c49948fa49297a1d24c13bc98aa6ee1e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision dc2b06cb5a46cf2508d28fe9a6f8dcaa710346a7) @@ -1,46 +1,43 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; +using Core.Common.TestUtil; using NUnit.Framework; namespace Ringtoets.Piping.Data.Test { public class PipingSoilProfileTest { [Test] - [TestCase(1)] - [TestCase(5)] - public void Constructor_WithNameBottomLayersAndAquifer_ReturnsInstanceWithPropsAndEquivalentLayerCollection(int layerCount) + public void Constructor_WithNameBottomLayersAndAquifer_ReturnsInstanceWithPropsAndEquivalentLayerCollection() { // Setup var name = "Profile"; - var bottom = new Random(22).NextDouble(); - var equivalentLayers = new Collection(); - for (var i = 0; i < layerCount; i++) + var random = new Random(22); + var bottom = random.NextDouble(); + var layers = new Collection { - equivalentLayers.Add(new PipingSoilLayer(0.0) - { - IsAquifer = i == 0 - }); - } + new PipingSoilLayer(bottom) + }; // Call - var profile = new PipingSoilProfile(name, bottom, equivalentLayers); + var profile = new PipingSoilProfile(name, bottom, layers); // Assert - Assert.AreNotSame(equivalentLayers, profile.Layers); - CollectionAssert.AreEqual(equivalentLayers, profile.Layers); + Assert.AreNotSame(layers, profile.Layers); Assert.AreEqual(name, profile.Name); Assert.AreEqual(bottom, profile.Bottom); } + [Test] public void Constructor_WithNameBottomLayersEmpty_ThrowsArgumentException() { // Call TestDelegate test = () => new PipingSoilProfile(String.Empty, Double.NaN, new Collection()); // Assert - var message = Assert.Throws(test).Message; - Assert.AreEqual(Properties.Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers, message); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, Properties.Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers); } [Test] @@ -50,11 +47,96 @@ TestDelegate test = () => new PipingSoilProfile(String.Empty, Double.NaN, null); // Assert - var message = Assert.Throws(test).Message; - StringAssert.StartsWith(Properties.Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers, message); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, Properties.Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers); } [Test] + [TestCase(1)] + [TestCase(5)] + [TestCase(15)] + public void Layers_Always_ReturnsDescendingByTopOrderedList(int layerCount) + { + // Setup + var random = new Random(21); + var bottom = 0.0; + var equivalentLayers = new List(layerCount); + for (var i = 0; i < layerCount; i++) + { + equivalentLayers.Add(new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = i == 0 + }); + } + + var profile = new PipingSoilProfile(string.Empty, bottom, equivalentLayers); + + // Call + var result = profile.Layers.ToArray(); + + // Assert + CollectionAssert.AreEquivalent(equivalentLayers, result); + CollectionAssert.AreEqual(equivalentLayers.OrderByDescending(l => l.Top).Select(l => l.Top), result.Select(l => l.Top)); + } + + [Test] + [TestCase(1e-6)] + [TestCase(4)] + public void Constructor_WithNameBottomLayersBelowBottom_ThrowsArgumentException(double deltaBelowBottom) + { + // Setup + var bottom = 0.0; + var pipingSoilLayers = new[] + { + new PipingSoilLayer(bottom - deltaBelowBottom), + new PipingSoilLayer(1.1) + }; + + // Call + TestDelegate test = () => new PipingSoilProfile(String.Empty, bottom, pipingSoilLayers); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "Eén of meerdere lagen hebben een top onder de bodem van het profiel."); + } + + [Test] + [TestCase(0,0)] + [TestCase(1,1.1)] + public void GetLayerThickness_LayerInProfile_ReturnsThicknessOfLayer(int layerIndex, double expectedThickness) + { + // Setup + var pipingSoilLayers = new[] + { + new PipingSoilLayer(0.0), + new PipingSoilLayer(1.1) + }; + var profile = new PipingSoilProfile(string.Empty, 0.0, pipingSoilLayers); + + // Call + var thickness = profile.GetLayerThickness(pipingSoilLayers[layerIndex]); + + // Assert + Assert.AreEqual(expectedThickness, thickness); + } + + [Test] + public void GetLayerThickness_LayerNotInProfile_ThrowsArgumentException() + { + // Setup + var pipingSoilLayers = new[] + { + new PipingSoilLayer(0.0), + new PipingSoilLayer(1.1) + }; + var profile = new PipingSoilProfile(string.Empty, 0.0, pipingSoilLayers); + + // Call + TestDelegate test = () => profile.GetLayerThickness(new PipingSoilLayer(1.1)); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "Layer not found in profile."); + } + + [Test] [TestCase(null)] [TestCase("")] [TestCase("some name")]