Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs =================================================================== diff -u -rda4a311b2ac60defe1a27a61c8d151f47268a941 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision da4a311b2ac60defe1a27a61c8d151f47268a941) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a) @@ -282,6 +282,7 @@ [Test] public void ReadStochasticSoilModel_EmptySoilModelAndNoGeometry_ReturnsSoilModelWithoutGeometry() { + // Setup string dbFile = Path.Combine(testDataPath, "modelWithoutGeometry.soil"); using (var reader = new StochasticSoilModelReader(dbFile)) @@ -304,7 +305,7 @@ public void GivenDatabaseWithStochasticSoilModelWithAndWithoutGeometry_WhenReading_ThenReturnsAllModels() { // Setup - string dbFile = Path.Combine(testDataPath, "skippedStochasticSoilModel.soil"); + string dbFile = Path.Combine(testDataPath, "modelsWithAndWithoutGeometry.soil"); var readModels = new List(); using (var reader = new StochasticSoilModelReader(dbFile)) @@ -367,91 +368,154 @@ } [Test] - public void ReadStochasticSoilModel_OtherFailureMechanism_ThrowsStochasticSoilModelException() + public void ReadStochasticSoilModel_SoilModelWithoutStochasticSoilProfiles_ReturnsSoilModelWithoutLayers() { // Setup - string dbFile = Path.Combine(testDataPath, "otherFailureMechanism.soil"); + string dbFile = Path.Combine(testDataPath, "modelWithoutStochasticSoilProfiles.soil"); using (var reader = new StochasticSoilModelReader(dbFile)) { reader.Validate(); // Call - TestDelegate test = () => reader.ReadStochasticSoilModel(); + StochasticSoilModel model = reader.ReadStochasticSoilModel(); // Assert - var exception = Assert.Throws(test); - - const string expectedMessage = "Het faalmechanisme 'UNKNOWN' wordt niet ondersteund."; - Assert.AreEqual(expectedMessage, exception.Message); + Assert.AreEqual("SoilModel", model.Name); + Assert.AreEqual(FailureMechanismType.Piping, model.FailureMechanismType); + CollectionAssert.IsEmpty(model.StochasticSoilProfiles); } Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } [Test] - public void ReadStochasticSoilModel_SoilModelWithoutStochasticSoilProfile_ThrowsStochasticSoilModelExceptionAndCanContinueReading() + public void GivenDatabaseWithStochasticSoilModelWithAndWithoutSoilProfiles_WhenReading_ReturnsAllModels() { // Setup - string dbFile = Path.Combine(testDataPath, "modelWithoutProfile.soil"); + string dbFile = Path.Combine(testDataPath, "modelsWithAndWithoutStochasticSoilProfiles.soil"); - StochasticSoilModelException expectedException = null; var readModels = new List(); using (var reader = new StochasticSoilModelReader(dbFile)) { reader.Validate(); + // Call while (reader.HasNext) { - try - { - // Call - readModels.Add(reader.ReadStochasticSoilModel()); - } - catch (StochasticSoilModelException e) - { - expectedException = e; - reader.MoveNext(); - } + readModels.Add(reader.ReadStochasticSoilModel()); } + // Assert Assert.IsFalse(reader.HasNext); + + CollectionAssert.AreEqual(new[] + { + "36005_Stability", + "36005_Piping", + "36006_Stability", + "36006_Piping", + "36007_Stability", + "36007_Piping" + }, readModels.Select(m => m.Name)); + CollectionAssert.AreEqual(new[] + { + 10, + 0, + 6, + 0, + 8, + 0 + }, readModels.Select(m => m.StochasticSoilProfiles.Count)); } - // Assert - var expectedSegmentAndModelNames = new[] + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadStochasticSoilModel_ModelWithStochasticSoilProfilesWith1DProfiles_ReturnsModelWithStochasticProfiles() + { + // Setup + string dbFile = Path.Combine(testDataPath, "modelWithStochasticSoilProfile1D.soil"); + + using (var reader = new StochasticSoilModelReader(dbFile)) { - "36005_Stability", - "36005_Piping", - "36006_Stability", - "36007_Stability", - "36007_Piping" - }; - var expectedSegmentPointCount = new[] + reader.Validate(); + + // Call + StochasticSoilModel model = reader.ReadStochasticSoilModel(); + + // Assert + Assert.AreEqual("SoilModel", model.Name); + Assert.AreEqual(FailureMechanismType.Stability, model.FailureMechanismType); + CollectionAssert.AreEqual(new[] + { + 0.1, + 0.35, + 0.05, + 0.1, + 0.35, + 0.05 + }.OrderBy(p => p), model.StochasticSoilProfiles.Select(profile => profile.Probability)); + CollectionAssert.AllItemsAreInstancesOfType(model.StochasticSoilProfiles.Select(profile => profile.SoilProfile), typeof(SoilProfile1D)); + } + } + + [Test] + public void ReadStochasticSoilModel_ModelWithStochasticProfilesWith2DProfiles_ReturnsModelWithStochasticProfiles() + { + // Setup + string dbFile = Path.Combine(testDataPath, "modelWithStochasticSoilProfile2D.soil"); + + using (var reader = new StochasticSoilModelReader(dbFile)) { - 1797, - 1797, - 144, - 606, - 606 - }; - var expectedProfileCount = new[] + reader.Validate(); + + // Call + StochasticSoilModel model = reader.ReadStochasticSoilModel(); + + // Assert + Assert.AreEqual("SoilModel", model.Name); + Assert.AreEqual(FailureMechanismType.Stability, model.FailureMechanismType); + CollectionAssert.AreEqual(new[] + { + 0.15, + 0.175, + 0.075, + 0.05, + 0.05, + 0.15, + 0.175, + 0.075, + 0.05, + 0.05 + }.OrderBy(p => p), model.StochasticSoilProfiles.Select(profile => profile.Probability)); + CollectionAssert.AllItemsAreInstancesOfType(model.StochasticSoilProfiles.Select(profile => profile.SoilProfile), typeof(SoilProfile2D)); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadStochasticSoilModel_OtherFailureMechanism_ThrowsStochasticSoilModelException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "otherFailureMechanism.soil"); + + using (var reader = new StochasticSoilModelReader(dbFile)) { - 10, - 10, - 6, - 8, - 8 - }; + reader.Validate(); - CollectionAssert.AreEqual(expectedSegmentAndModelNames, readModels.Select(m => m.Name)); - CollectionAssert.AreEqual(expectedSegmentPointCount, readModels.Select(m => m.Geometry.Count)); - CollectionAssert.AreEqual(expectedProfileCount, readModels.Select(m => m.StochasticSoilProfiles.Count)); + // Call + TestDelegate test = () => reader.ReadStochasticSoilModel(); - Assert.IsNotNull(expectedException); - Assert.AreEqual("Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel '36006_Piping'.", - expectedException.Message); + // Assert + var exception = Assert.Throws(test); + const string expectedMessage = "Het faalmechanisme 'UNKNOWN' wordt niet ondersteund."; + Assert.AreEqual(expectedMessage, exception.Message); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); }