Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs
===================================================================
diff -u -r36e7a0a258891013379258ea856d49351594666e -r2dc7bb7aef782fd08d2474e14cc5486725896b38
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs (.../SegmentPointReader.cs) (revision 36e7a0a258891013379258ea856d49351594666e)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs (.../SegmentPointReader.cs) (revision 2dc7bb7aef782fd08d2474e14cc5486725896b38)
@@ -39,10 +39,11 @@
public class SegmentPointReader : SqLiteDatabaseReaderBase
{
private IDataReader dataReader;
+ private long currentStochasticSoilModelId = -1;
///
/// Creates a new instance of ,
- /// which will use the as its source.
+ /// that will use the as its source.
///
/// The path of the database file to open.
/// Thrown when:
@@ -65,20 +66,39 @@
}
///
- /// Reads the segment points corresponding to the stochastic soil model with id .
+ /// Reads the segment points corresponding to the stochastic soil model.
///
- ///
- /// The segment points corresponding to the stochastic soil model
+ /// The segment points corresponding to the stochastic soil model.
/// Thrown when the geometry could not be read.
- public IEnumerable ReadSegmentPoints(long stochasticSoilModelId)
+ public IEnumerable ReadSegmentPoints()
{
- while (HasNext && ReadStochasticSoilModelSegmentId() <= stochasticSoilModelId)
+ while (HasNext && ReadStochasticSoilModelId() == currentStochasticSoilModelId)
{
yield return ReadSegmentPoint();
MoveNext();
}
}
+ ///
+ /// Moves the reader to the stochastic soil model with id .
+ ///
+ /// The id of the stochastic soil model.
+ /// true if the reader was moved to the stochastic soil model with id
+ /// successfully, false otherwise.
+ public bool MoveToStochasticSoilModel(long stochasticSoilModelId)
+ {
+ while (HasNext && ReadStochasticSoilModelId() <= stochasticSoilModelId)
+ {
+ if (ReadStochasticSoilModelId() == stochasticSoilModelId)
+ {
+ currentStochasticSoilModelId = stochasticSoilModelId;
+ return true;
+ }
+ MoveNext();
+ }
+ return false;
+ }
+
protected override void Dispose(bool disposing)
{
if (dataReader != null)
@@ -92,7 +112,7 @@
private bool HasNext { get; set; }
- private long ReadStochasticSoilModelSegmentId()
+ private long ReadStochasticSoilModelId()
{
return Convert.ToInt64(dataReader[StochasticSoilModelTableDefinitions.StochasticSoilModelId]);
}
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs
===================================================================
diff -u -r133fb73ed33467075fa1317ab736902755ff6e4f -r2dc7bb7aef782fd08d2474e14cc5486725896b38
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 133fb73ed33467075fa1317ab736902755ff6e4f)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 2dc7bb7aef782fd08d2474e14cc5486725896b38)
@@ -195,6 +195,7 @@
/// Thrown when:
///
/// - no stochastic soil profiles could be read;
+ /// - the geometry could not be read;
/// - the read failure mechanism type is not supported.
///
///
@@ -208,13 +209,32 @@
StochasticSoilModel stochasticSoilModel = CreateStochasticSoilModel();
long currentSoilModelId = ReadStochasticSoilModelId();
- stochasticSoilModel.Geometry.AddRange(segmentPointReader.ReadSegmentPoints(currentSoilModelId));
+ SetGeometry(stochasticSoilModel);
stochasticSoilModel.StochasticSoilProfiles.AddRange(ReadStochasticSoilProfiles(currentSoilModelId));
return stochasticSoilModel;
}
///
+ /// Sets the geometry points of from the database.
+ ///
+ /// The stochastic soil model of which the geometry to set.
+ /// Thrown when the geometry could not be read.
+ private void SetGeometry(StochasticSoilModel stochasticSoilModel)
+ {
+ long currentSoilModelId = ReadStochasticSoilModelId();
+
+ if (!segmentPointReader.MoveToStochasticSoilModel(currentSoilModelId))
+ {
+ throw new StochasticSoilModelException(
+ string.Format(Resources.SegmentPointReader_ReadSegmentPoint_StochasticSoilModel_0_must_contain_geometry,
+ ReadStochasticSoilModelName()));
+ }
+
+ stochasticSoilModel.Geometry.AddRange(segmentPointReader.ReadSegmentPoints());
+ }
+
+ ///
/// Reads and returns objects that belong to soil model
/// with id .
///
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs
===================================================================
diff -u -r36e7a0a258891013379258ea856d49351594666e -r2dc7bb7aef782fd08d2474e14cc5486725896b38
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs (.../SegmentPointReaderTest.cs) (revision 36e7a0a258891013379258ea856d49351594666e)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs (.../SegmentPointReaderTest.cs) (revision 2dc7bb7aef782fd08d2474e14cc5486725896b38)
@@ -109,6 +109,70 @@
}
[Test]
+ public void MoveToStochasticSoilModel_EmptyDatabase_ReturnsFalse()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "emptySchema.soil");
+
+ using (var reader = new SegmentPointReader(dbFile))
+ {
+ reader.Initialize();
+
+ // Call
+ bool success = reader.MoveToStochasticSoilModel(1);
+
+ // Assert
+ Assert.IsFalse(success);
+ }
+
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
+ public void MoveToStochasticSoilModel_IdNotInDatabase_ReturnsFalse()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "complete.soil");
+
+ using (var reader = new SegmentPointReader(dbFile))
+ {
+ reader.Initialize();
+
+ // Call
+ bool success = reader.MoveToStochasticSoilModel(10000);
+
+ // Assert
+ Assert.IsFalse(success);
+ }
+
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
+ public void GivenMovedToIdNotInDatabase_WhenMoveToStochasticSoilModel_ThenRetunsTrue()
+ {
+ // Given
+ string dbFile = Path.Combine(testDataPath, "skippedStochasticSoilModel.soil");
+ using (var reader = new SegmentPointReader(dbFile))
+ {
+ reader.Initialize();
+
+ bool hasThree = reader.MoveToStochasticSoilModel(3);
+
+ // Precondition
+ Assert.IsFalse(hasThree);
+
+ // When
+ bool hasFour = reader.MoveToStochasticSoilModel(4);
+
+ // Then
+ Assert.IsTrue(hasFour);
+ }
+
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
public void ReadStochasticSoilModel_SegmentPointNull_ThrowsStochasticSoilModelException()
{
// Setup
@@ -117,9 +181,10 @@
using (var reader = new SegmentPointReader(dbFile))
{
reader.Initialize();
+ reader.MoveToStochasticSoilModel(1);
// Call
- TestDelegate test = () => reader.ReadSegmentPoints(1).ToArray();
+ TestDelegate test = () => reader.ReadSegmentPoints().ToArray();
// Assert
var exception = Assert.Throws(test);
@@ -141,7 +206,7 @@
reader.Initialize();
// Call
- Point2D[] segmentPoints = reader.ReadSegmentPoints(1).ToArray();
+ Point2D[] segmentPoints = reader.ReadSegmentPoints().ToArray();
// Assert
CollectionAssert.IsEmpty(segmentPoints);
@@ -159,9 +224,10 @@
using (var reader = new SegmentPointReader(dbFile))
{
reader.Initialize();
+ reader.MoveToStochasticSoilModel(1);
// Call
- Point2D[] segmentPoints = reader.ReadSegmentPoints(1).ToArray();
+ Point2D[] segmentPoints = reader.ReadSegmentPoints().ToArray();
// Assert
Assert.AreEqual(1797, segmentPoints.Length);
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs
===================================================================
diff -u -r2ff863d4f541aa91cc29852317a4ff50b0fb71ed -r2dc7bb7aef782fd08d2474e14cc5486725896b38
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 2ff863d4f541aa91cc29852317a4ff50b0fb71ed)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 2dc7bb7aef782fd08d2474e14cc5486725896b38)
@@ -1,5 +1,4 @@
-
-// Copyright (C) Stichting Deltares 2017. All rights reserved.
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
@@ -243,6 +242,29 @@
}
[Test]
+ public void ReadStochasticSoilModel_MissingSegmentPoint_ThrowsStochasticSoilModelException()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "skippedStochasticSoilModel.soil");
+
+ using (var reader = new StochasticSoilModelReader(dbFile))
+ {
+ reader.Validate();
+
+ // Call
+ TestDelegate test = () => reader.ReadStochasticSoilModel();
+
+ // Assert
+ var exception = Assert.Throws(test);
+
+ const string expectedMessage = "Het stochastische ondergrondmodel '36005_Stability' moet een geometrie bevatten.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
public void ReadStochasticSoilModel_InvalidSegmentPoint_ThrowsStochasticSoilModelException()
{
// Setup
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SegmentPointReader/skippedStochasticSoilModel.soil
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/skippedStochasticSoilModel.soil
===================================================================
diff -u
Binary files differ