Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs =================================================================== diff -u -r80f04760977eeb1f2f2781ff9600ffa4d51b7060 -rc7c07e0937c3148b6223ebdad64fe7d326d1625f --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 80f04760977eeb1f2f2781ff9600ffa4d51b7060) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision c7c07e0937c3148b6223ebdad64fe7d326d1625f) @@ -19,13 +19,15 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base.IO; using Core.Common.IO.Readers; using Core.Common.TestUtil; using Core.Common.Utils.Builders; +using log4net.Core; using NUnit.Framework; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.SoilProfile; @@ -38,6 +40,8 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(StochasticSoilModelReader)); private readonly string constraintsReaderTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(SoilDatabaseConstraintsReader)); private readonly string versionReaderTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(SoilDatabaseVersionReader)); + private readonly string soilProfile1DReaderTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(SoilProfile1DReader)); + private readonly string soilProfile2DReaderTestDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(SoilProfile2DReader)); [Test] public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() @@ -180,6 +184,63 @@ } [Test] + public void Validate_InvalidSoilProfile1d_LogsWarning() + { + // Setup + string dbFile = Path.Combine(soilProfile1DReaderTestDataPath, "1dprofileWithIncorrectBottom.soil"); + + using (var reader = new StochasticSoilModelReader(dbFile)) + { + // Call + Action call = () => reader.Validate(); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples => + { + Tuple[] tuplesArray = tuples.ToArray(); + Assert.AreEqual(1, tuplesArray.Length); + + string expectedMessage = "Het uitlezen van de ondergrondschematisatie is mislukt. " + + "Deze ondergrondschematisatie wordt overgeslagen."; + Assert.AreEqual(expectedMessage, tuplesArray[0].Item1); + Assert.AreEqual(Level.Warn, tuplesArray[0].Item2); + Assert.IsInstanceOf(tuplesArray[0].Item3); + }); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void Validate_InvalidSoilProfile2d_LogsWarning() + { + // Setup + string dbFile = Path.Combine(soilProfile2DReaderTestDataPath, "2dProfileWithXInvalid.soil"); + + using (var reader = new StochasticSoilModelReader(dbFile)) + { + // Call + Action call = () => reader.Validate(); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples => + { + Tuple[] tuplesArray = tuples.ToArray(); + Assert.AreEqual(1, tuplesArray.Length); + + string expectedMessage = "Het lezen van de ondergrondschematisatie 'Profile' is mislukt. " + + "Geen geldige waarde in kolom 'IntersectionX'. " + + "Deze ondergrondschematisatie wordt overgeslagen."; + Assert.AreEqual(expectedMessage, tuplesArray[0].Item1); + Assert.AreEqual(Level.Warn, tuplesArray[0].Item2); + Assert.IsInstanceOf(tuplesArray[0].Item3); + }); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] public void HasNext_EmptyDatabase_ReturnsFalse() { // Setup