Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Calculation/Piping/PipingProfileCreator.cs
===================================================================
diff -u -re5a53456f16d530cb56abb35a256d8cf1f91df3d -rd0e0e368f3f1b297abe0e073a2c313fd38c77c16
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Calculation/Piping/PipingProfileCreator.cs (.../PipingProfileCreator.cs) (revision e5a53456f16d530cb56abb35a256d8cf1f91df3d)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Calculation/Piping/PipingProfileCreator.cs (.../PipingProfileCreator.cs) (revision d0e0e368f3f1b297abe0e073a2c313fd38c77c16)
@@ -25,7 +25,7 @@
{
BottomLevel = soilProfile.Bottom
};
- foreach (PipingSoilLayer layer in soilProfile.Layers.OrderByDescending(l => l.Top))
+ foreach (PipingSoilLayer layer in soilProfile.Layers)
{
profile.Layers.Add(new PipingLayer
{
Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingSoilProfile.cs
===================================================================
diff -u -re5a53456f16d530cb56abb35a256d8cf1f91df3d -rd0e0e368f3f1b297abe0e073a2c313fd38c77c16
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision e5a53456f16d530cb56abb35a256d8cf1f91df3d)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision d0e0e368f3f1b297abe0e073a2c313fd38c77c16)
@@ -52,7 +52,7 @@
}
private set
{
- layers = value.ToArray();
+ layers = value.OrderByDescending(l => l.Top).ToArray();
}
}
Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs
===================================================================
diff -u -re5a53456f16d530cb56abb35a256d8cf1f91df3d -rd0e0e368f3f1b297abe0e073a2c313fd38c77c16
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision e5a53456f16d530cb56abb35a256d8cf1f91df3d)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision d0e0e368f3f1b297abe0e073a2c313fd38c77c16)
@@ -167,57 +167,58 @@
private void CreateDataReader()
{
var mechanismParameterName = "mechanism";
- var query = new SQLiteCommand(connection)
+ using (var query = new SQLiteCommand(connection)
{
- CommandText = string.Format(string.Join(" ",
- "SELECT",
- "p.SP2D_Name as {0},",
- "l.GeometrySurface as {1},",
- "mpl.X as {2},",
- "null as {3},",
- "null as {4},",
- "sum(case when mat.PN_Name = 'AbovePhreaticLevel' then mat.PV_Value end) {5},",
- "sum(case when mat.PN_Name = 'BelowPhreaticLevel' then mat.PV_Value end) {6},",
- "sum(case when mat.PN_Name = 'PermeabKx' then mat.PV_Value end) {7},",
- "sum(case when mat.PN_Name = 'DiameterD70' then mat.PV_Value end) {8},",
- "sum(case when mat.PN_Name = 'WhitesConstant' then mat.PV_Value end) {9},",
- "sum(case when mat.PN_Name = 'BeddingAngle' then mat.PV_Value end) {10},",
- "2 as {11}",
- "FROM MechanismPointLocation as m",
- "JOIN MechanismPointLocation as mpl ON p.SP2D_ID = mpl.SP2D_ID",
- "JOIN SoilProfile2D as p ON m.SP2D_ID = p.SP2D_ID",
- "JOIN SoilLayer2D as l ON l.SP2D_ID = p.SP2D_ID",
- "JOIN (",
- "SELECT m.MA_ID, pn.PN_Name, pv.PV_Value",
- "FROM ParameterNames as pn",
- "JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID",
- "JOIN Materials as m ON m.MA_ID = pv.MA_ID) as mat ON l.MA_ID = mat.MA_ID",
- "WHERE m.ME_ID = @{12}",
- "GROUP BY l.SL2D_ID",
- "UNION",
- "SELECT",
- "p.SP1D_Name as {0},",
- "null as {1},",
- "null as {2},",
- "p.BottomLevel as {3},",
- "l.TopLevel as {4},",
- "sum(case when mat.PN_Name = 'AbovePhreaticLevel' then mat.PV_Value end) {5},",
- "sum(case when mat.PN_Name = 'BelowPhreaticLevel' then mat.PV_Value end) {6},",
- "sum(case when mat.PN_Name = 'PermeabKx' then mat.PV_Value end) {7},",
- "sum(case when mat.PN_Name = 'DiameterD70' then mat.PV_Value end) {8},",
- "sum(case when mat.PN_Name = 'WhitesConstant' then mat.PV_Value end) {9},",
- "sum(case when mat.PN_Name = 'BeddingAngle' then mat.PV_Value end) {10},",
- "1 as {11}",
- "FROM SoilProfile1D as p",
- "JOIN SoilLayer1D as l ON l.SP1D_ID = p.SP1D_ID",
- "JOIN (",
- "SELECT m.MA_ID, pn.PN_Name, pv.PV_Value",
- "FROM ParameterNames as pn",
- "JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID",
- "JOIN Materials as m ON m.MA_ID = pv.MA_ID) as mat ON l.MA_ID = mat.MA_ID",
- "GROUP BY l.SL1D_ID",
- "ORDER BY ProfileName"
- ),
+ CommandText = string.Format(string.Join(
+ " ",
+ "SELECT",
+ "p.SP2D_Name as {0},",
+ "l.GeometrySurface as {1},",
+ "mpl.X as {2},",
+ "null as {3},",
+ "null as {4},",
+ "sum(case when mat.PN_Name = 'AbovePhreaticLevel' then mat.PV_Value end) {5},",
+ "sum(case when mat.PN_Name = 'BelowPhreaticLevel' then mat.PV_Value end) {6},",
+ "sum(case when mat.PN_Name = 'PermeabKx' then mat.PV_Value end) {7},",
+ "sum(case when mat.PN_Name = 'DiameterD70' then mat.PV_Value end) {8},",
+ "sum(case when mat.PN_Name = 'WhitesConstant' then mat.PV_Value end) {9},",
+ "sum(case when mat.PN_Name = 'BeddingAngle' then mat.PV_Value end) {10},",
+ "2 as {11}",
+ "FROM MechanismPointLocation as m",
+ "JOIN MechanismPointLocation as mpl ON p.SP2D_ID = mpl.SP2D_ID",
+ "JOIN SoilProfile2D as p ON m.SP2D_ID = p.SP2D_ID",
+ "JOIN SoilLayer2D as l ON l.SP2D_ID = p.SP2D_ID",
+ "JOIN (",
+ "SELECT m.MA_ID, pn.PN_Name, pv.PV_Value",
+ "FROM ParameterNames as pn",
+ "JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID",
+ "JOIN Materials as m ON m.MA_ID = pv.MA_ID) as mat ON l.MA_ID = mat.MA_ID",
+ "WHERE m.ME_ID = @{12}",
+ "GROUP BY l.SL2D_ID",
+ "UNION",
+ "SELECT",
+ "p.SP1D_Name as {0},",
+ "null as {1},",
+ "null as {2},",
+ "p.BottomLevel as {3},",
+ "l.TopLevel as {4},",
+ "sum(case when mat.PN_Name = 'AbovePhreaticLevel' then mat.PV_Value end) {5},",
+ "sum(case when mat.PN_Name = 'BelowPhreaticLevel' then mat.PV_Value end) {6},",
+ "sum(case when mat.PN_Name = 'PermeabKx' then mat.PV_Value end) {7},",
+ "sum(case when mat.PN_Name = 'DiameterD70' then mat.PV_Value end) {8},",
+ "sum(case when mat.PN_Name = 'WhitesConstant' then mat.PV_Value end) {9},",
+ "sum(case when mat.PN_Name = 'BeddingAngle' then mat.PV_Value end) {10},",
+ "1 as {11}",
+ "FROM SoilProfile1D as p",
+ "JOIN SoilLayer1D as l ON l.SP1D_ID = p.SP1D_ID",
+ "JOIN (",
+ "SELECT m.MA_ID, pn.PN_Name, pv.PV_Value",
+ "FROM ParameterNames as pn",
+ "JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID",
+ "JOIN Materials as m ON m.MA_ID = pv.MA_ID) as mat ON l.MA_ID = mat.MA_ID",
+ "GROUP BY l.SL1D_ID",
+ "ORDER BY ProfileName"
+ ),
profileNameColumn,
layerGeometryColumn,
intersectionXColumn,
@@ -231,22 +232,25 @@
beddingAngleColumn,
dimensionsColumn,
mechanismParameterName)
- };
- query.Parameters.Add(new SQLiteParameter
+ })
{
- DbType = DbType.Int32,
- Value = pipingMechanismId,
- ParameterName = mechanismParameterName
- });
+ query.Parameters.Add(new SQLiteParameter
+ {
+ DbType = DbType.Int32,
+ Value = pipingMechanismId,
+ ParameterName = mechanismParameterName
+ });
+
+ try
+ {
+ dataReader = query.ExecuteReader();
+ }
+ catch (SQLiteException e)
+ {
+ throw new PipingSoilProfileReadException(string.Format(Resources.Error_SoilProfileReadFromDatabase, connection.DataSource), e);
+ }
- try
- {
- dataReader = query.ExecuteReader();
}
- catch (SQLiteException e)
- {
- throw new PipingSoilProfileReadException(string.Format(Resources.Error_SoilProfileReadFromDatabase, connection.DataSource), e);
- }
}
}
}
\ No newline at end of file
Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs
===================================================================
diff -u -r92ea66818567a23223b31d658ef8db3349f9e8f0 -rd0e0e368f3f1b297abe0e073a2c313fd38c77c16
--- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 92ea66818567a23223b31d658ef8db3349f9e8f0)
+++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision d0e0e368f3f1b297abe0e073a2c313fd38c77c16)
@@ -8,6 +8,7 @@
using Ringtoets.Piping.IO.Calculation;
using Ringtoets.Piping.IO.Exceptions;
using Ringtoets.Piping.IO.Properties;
+using Ringtoets.Piping.IO.Test.TestHelpers;
namespace Ringtoets.Piping.IO.Test
{
@@ -30,6 +31,37 @@
}
[Test]
+ public void Dispose_AfterConstruction_CorrectlyReleasesFile()
+ {
+ // Setup
+ var testFile = "empty.soil";
+ var dbFile = Path.Combine(testDataPath, testFile);
+ var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile);
+
+ // Call
+ pipingSoilProfilesReader.Dispose();
+
+ // Assert
+ Assert.IsTrue(FileHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
+ public void Dispose_WhenRead_CorrectlyReleasesFile()
+ {
+ // Setup
+ var testFile = "1dprofile.soil";
+ var dbFile = Path.Combine(testDataPath, testFile);
+ var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile);
+ pipingSoilProfilesReader.Read();
+
+ // Call
+ pipingSoilProfilesReader.Dispose();
+
+ // Assert
+ Assert.IsTrue(FileHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
public void Constructor_NonExistingPath_ThrowsFileNotFoundException()
{
// Setup
@@ -130,9 +162,13 @@
// Assert
Assert.AreEqual(1, result.Length);
Assert.AreEqual(-12, result[0].Bottom);
- CollectionAssert.AreEquivalent(new[] { 60, 0.63, -7.0 }, result[0].Layers.Select(l => l.Top));
+ CollectionAssert.AreEquivalent(new[]
+ {
+ 60,
+ 0.63,
+ -7.0
+ }, result[0].Layers.Select(l => l.Top));
}
-
}
private void ReadSoilProfiles_CompleteDatabase_Returns2ProfilesWithLayersAndGeometries()
Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj
===================================================================
diff -u -r1d5aa9555ab25c06f0a322173953a79c6ead1404 -rd0e0e368f3f1b297abe0e073a2c313fd38c77c16
--- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404)
+++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision d0e0e368f3f1b297abe0e073a2c313fd38c77c16)
@@ -56,6 +56,7 @@
+
@@ -75,6 +76,7 @@
Ringtoets.Piping.Data.TestUtil
+