Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs =================================================================== diff -u -r1b9445050ddc7786014349d7014c7c4d85242a5d -r61da7f609eef63a149d27eb1c52b2bd908af33b3 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 1b9445050ddc7786014349d7014c7c4d85242a5d) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 61da7f609eef63a149d27eb1c52b2bd908af33b3) @@ -23,15 +23,13 @@ using System.Data; using System.Data.SQLite; using Core.Common.Base.IO; -using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using Core.Common.Utils.Builders; using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.IO.SoilProfile.Schema; using Ringtoets.Piping.Primitives; -using UtilsResources = Core.Common.Utils.Properties.Resources; namespace Ringtoets.Piping.IO.SoilProfile { @@ -102,10 +100,7 @@ public override void Dispose() { - if (dataReader != null) - { - dataReader.Dispose(); - } + dataReader?.Dispose(); base.Dispose(); } @@ -127,7 +122,7 @@ /// Thrown when the value in the column could not be casted to type . public T ReadOrDefault(string columnName) { - var valueObject = dataReader[columnName]; + object valueObject = dataReader[columnName]; if (valueObject.Equals(DBNull.Value)) { return default(T); @@ -210,11 +205,8 @@ } catch (SQLiteException e) { - if (dataReader != null) - { - dataReader.Dispose(); - } - var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_SoilProfile_read_from_database); + dataReader?.Dispose(); + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_SoilProfile_read_from_database); throw new CriticalFileReadException(message, e); } MoveNext(); @@ -231,95 +223,76 @@ string countQuery = SoilDatabaseQueryBuilder.GetPipingSoilProfileCountQuery(); string subQueryGetNumberOfLayerProfile1D = - string.Format("SELECT SP1D_ID, COUNT(*) as {0} " + - "FROM SoilLayer1D " + - "GROUP BY SP1D_ID", - SoilProfileTableColumns.LayerCount); + "SELECT " + + "SP1D_ID, " + + $"COUNT(*) as {SoilProfileTableColumns.LayerCount} " + + "FROM SoilLayer1D " + + "GROUP BY SP1D_ID"; string subQueryGetNumberOfLayerProfile2D = - string.Format("SELECT SP2D_ID, COUNT(*) as {0} " + - "FROM SoilLayer2D " + - "GROUP BY SP2D_ID", - SoilProfileTableColumns.LayerCount); + $"SELECT SP2D_ID, COUNT(*) as {SoilProfileTableColumns.LayerCount} " + + "FROM SoilLayer2D " + + "GROUP BY SP2D_ID"; string subQueryGetMaterialPropertiesOfLayer = - string.Format( - "SELECT " + - "mat.MA_ID, " + - "mat.MA_Name as {0}, " + - "max(case when pn.PN_Name = 'Color' then pv.PV_Value end) {1}, " + - "max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Dist_Type end) {2}, " + - "max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Shift end) {3}, " + - "max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Mean end) {4}, " + - "max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Deviation end) {5}, " + - "max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Dist_Type end) {6}, " + - "max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Shift end) {7}, " + - "max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Mean end) {8}, " + - "max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Deviation end) {9}, " + - "max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Dist_Type end) {10}, " + - "max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Shift end) {11}, " + - "max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Mean end) {12}, " + - "max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Deviation end) {13} " + - "FROM ParameterNames AS pn " + - "LEFT JOIN ParameterValues AS pv USING(PN_ID) " + - "LEFT JOIN Stochast AS s USING(PN_ID) " + - "JOIN Materials AS mat WHERE pv.MA_ID = mat.MA_ID OR s.MA_ID = mat.MA_ID " + - "GROUP BY mat.MA_ID ", - SoilProfileTableColumns.MaterialName, - SoilProfileTableColumns.Color, - SoilProfileTableColumns.BelowPhreaticLevelDistribution, - SoilProfileTableColumns.BelowPhreaticLevelShift, - SoilProfileTableColumns.BelowPhreaticLevelMean, - SoilProfileTableColumns.BelowPhreaticLevelDeviation, - SoilProfileTableColumns.PermeabilityDistribution, - SoilProfileTableColumns.PermeabilityShift, - SoilProfileTableColumns.PermeabilityMean, - SoilProfileTableColumns.PermeabilityDeviation, - SoilProfileTableColumns.DiameterD70Distribution, - SoilProfileTableColumns.DiameterD70Shift, - SoilProfileTableColumns.DiameterD70Mean, - SoilProfileTableColumns.DiameterD70Deviation - ); + "SELECT " + + "mat.MA_ID, " + + $"mat.MA_Name as {SoilProfileTableColumns.MaterialName}, " + + $"max(case when pn.PN_Name = 'Color' then pv.PV_Value end) {SoilProfileTableColumns.Color}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Dist_Type end) {SoilProfileTableColumns.BelowPhreaticLevelDistribution}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Shift end) {SoilProfileTableColumns.BelowPhreaticLevelShift}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Mean end) {SoilProfileTableColumns.BelowPhreaticLevelMean}, " + + $"max(case when pn.PN_Name = 'BelowPhreaticLevelStochast' then s.ST_Deviation end) {SoilProfileTableColumns.BelowPhreaticLevelDeviation}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Dist_Type end) {SoilProfileTableColumns.PermeabilityDistribution}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Shift end) {SoilProfileTableColumns.PermeabilityShift}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Mean end) {SoilProfileTableColumns.PermeabilityMean}, " + + $"max(case when pn.PN_Name = 'PermeabKxStochast' then s.ST_Deviation end) {SoilProfileTableColumns.PermeabilityDeviation}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Dist_Type end) {SoilProfileTableColumns.DiameterD70Distribution}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Shift end) {SoilProfileTableColumns.DiameterD70Shift}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Mean end) {SoilProfileTableColumns.DiameterD70Mean}, " + + $"max(case when pn.PN_Name = 'DiameterD70Stochast' then s.ST_Deviation end) {SoilProfileTableColumns.DiameterD70Deviation} " + + "FROM ParameterNames AS pn " + + "LEFT JOIN ParameterValues AS pv USING(PN_ID) " + + "LEFT JOIN Stochast AS s USING(PN_ID) " + + "JOIN Materials AS mat " + + "WHERE pv.MA_ID = mat.MA_ID OR s.MA_ID = mat.MA_ID " + + "GROUP BY mat.MA_ID "; string subQueryGetLayerPropertiesOfLayer1D = - string.Format( - "SELECT " + - "SL1D_ID, " + - "PV_Value as {0} " + - "FROM ParameterNames " + - "JOIN LayerParameterValues USING(PN_ID) " + - "WHERE PN_NAME = '{0}'", - SoilProfileTableColumns.IsAquifer); + "SELECT " + + "SL1D_ID, " + + $"PV_Value as {SoilProfileTableColumns.IsAquifer} " + + "FROM ParameterNames " + + "JOIN LayerParameterValues USING(PN_ID) " + + $"WHERE PN_NAME = '{SoilProfileTableColumns.IsAquifer}'"; string subQueryGetLayerPropertiesOfLayer2D = - string.Format( - "SELECT " + - "SL2D_ID, " + - "PV_Value as {0} " + - "FROM ParameterNames " + - "JOIN LayerParameterValues USING(PN_ID) " + - "WHERE PN_NAME = '{0}'", - SoilProfileTableColumns.IsAquifer); + "SELECT " + + "SL2D_ID, " + + $"PV_Value as {SoilProfileTableColumns.IsAquifer} " + + "FROM ParameterNames " + + "JOIN LayerParameterValues USING(PN_ID) " + + $"WHERE PN_NAME = '{SoilProfileTableColumns.IsAquifer}'"; - var query1D = string.Format( + string query1D = "SELECT " + - "1 AS {0}, " + - "sp1d.SP1D_Name AS {1}, " + - "layerCount.{2}, " + - "sp1d.BottomLevel AS {3}, " + - "sl1d.TopLevel AS {4}, " + - "{5}, " + - "{6}, " + - "{7}, " + - "{8}, " + - "{9}, " + - "{10}, " + - "{11}, " + - "{12}, " + - "{13}, " + - "{14}, " + - "{15}, " + - "{16}, " + - "{17}, " + - "{18}, " + - "{19}, " + - "sp1d.SP1D_ID AS {20} " + + $"1 AS {SoilProfileTableColumns.Dimension}, " + + $"sp1d.SP1D_Name AS {SoilProfileTableColumns.ProfileName}, " + + $"layerCount.{SoilProfileTableColumns.LayerCount}, " + + $"sp1d.BottomLevel AS {SoilProfileTableColumns.Bottom}, " + + $"sl1d.TopLevel AS {SoilProfileTableColumns.Top}, " + + $"{SoilProfileTableColumns.MaterialName}, " + + $"{SoilProfileTableColumns.IsAquifer}, " + + $"{SoilProfileTableColumns.Color}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelDistribution}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelShift}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelMean}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelDeviation}, " + + $"{SoilProfileTableColumns.DiameterD70Distribution}, " + + $"{SoilProfileTableColumns.DiameterD70Shift}, " + + $"{SoilProfileTableColumns.DiameterD70Mean}, " + + $"{SoilProfileTableColumns.DiameterD70Deviation}, " + + $"{SoilProfileTableColumns.PermeabilityDistribution}, " + + $"{SoilProfileTableColumns.PermeabilityShift}, " + + $"{SoilProfileTableColumns.PermeabilityMean}, " + + $"{SoilProfileTableColumns.PermeabilityDeviation}, " + + $"sp1d.SP1D_ID AS {SoilProfileTableColumns.SoilProfileId} " + "FROM Mechanism AS m " + "JOIN Segment AS segment USING(ME_ID) " + "JOIN (SELECT SSM_ID, SP1D_ID, SP2D_ID FROM StochasticSoilProfile GROUP BY SSM_ID, SP1D_ID, SP2D_ID) ssp USING(SSM_ID) " + @@ -334,91 +307,49 @@ "LEFT JOIN (" + subQueryGetLayerPropertiesOfLayer1D + ") layerProperties USING(SL1D_ID) " + - "WHERE m.{21} = @{21};", - SoilProfileTableColumns.Dimension, - SoilProfileTableColumns.ProfileName, - SoilProfileTableColumns.LayerCount, - SoilProfileTableColumns.Bottom, - SoilProfileTableColumns.Top, - SoilProfileTableColumns.MaterialName, - SoilProfileTableColumns.IsAquifer, - SoilProfileTableColumns.Color, - SoilProfileTableColumns.BelowPhreaticLevelDistribution, - SoilProfileTableColumns.BelowPhreaticLevelShift, - SoilProfileTableColumns.BelowPhreaticLevelMean, - SoilProfileTableColumns.BelowPhreaticLevelDeviation, - SoilProfileTableColumns.DiameterD70Distribution, - SoilProfileTableColumns.DiameterD70Shift, - SoilProfileTableColumns.DiameterD70Mean, - SoilProfileTableColumns.DiameterD70Deviation, - SoilProfileTableColumns.PermeabilityDistribution, - SoilProfileTableColumns.PermeabilityShift, - SoilProfileTableColumns.PermeabilityMean, - SoilProfileTableColumns.PermeabilityDeviation, - SoilProfileTableColumns.SoilProfileId, - MechanismTableColumns.MechanismName); + $"WHERE m.{MechanismTableColumns.MechanismName} = @{MechanismTableColumns.MechanismName} " + + "GROUP BY sp1d.SP1D_ID, sl1d.SL1D_ID;"; - var query2D = string.Format( - "SELECT " + - "2 as {0}, " + - "sp2d.SP2D_Name as {1}, " + - "layerCount.{2}, " + - "sl2d.GeometrySurface as {3}, " + - "mpl.X as {4}, " + - "{5}, " + - "{6}, " + - "{7}, " + - "{8}, " + - "{9}, " + - "{10}, " + - "{11}, " + - "{12}, " + - "{13}, " + - "{14}, " + - "{15}, " + - "{16}, " + - "{17}, " + - "{18}, " + - "{19}, " + - "sp2d.SP2D_ID as {20} " + - "FROM Mechanism AS m " + - "JOIN Segment AS segment USING(ME_ID) " + - "JOIN (SELECT SSM_ID, SP1D_ID, SP2D_ID FROM StochasticSoilProfile GROUP BY SSM_ID, SP1D_ID, SP2D_ID) ssp USING(SSM_ID) " + - "JOIN SoilProfile2D sp2d USING (SP2D_ID) " + - "JOIN (" + - subQueryGetNumberOfLayerProfile2D + - ") layerCount USING (SP2D_ID) " + - "JOIN SoilLayer2D sl2d USING (SP2D_ID) " + - "JOIN MechanismPointLocation mpl USING(ME_ID, SP2D_ID) " + - "LEFT JOIN (" + - subQueryGetMaterialPropertiesOfLayer + - ") materialProperties USING(MA_ID) " + - "LEFT JOIN (" + - subQueryGetLayerPropertiesOfLayer2D + - ") layerProperties USING(SL2D_ID) " + - "WHERE m.{21} = @{21};", - SoilProfileTableColumns.Dimension, - SoilProfileTableColumns.ProfileName, - SoilProfileTableColumns.LayerCount, - SoilProfileTableColumns.LayerGeometry, - SoilProfileTableColumns.IntersectionX, - SoilProfileTableColumns.MaterialName, - SoilProfileTableColumns.IsAquifer, - SoilProfileTableColumns.Color, - SoilProfileTableColumns.BelowPhreaticLevelDistribution, - SoilProfileTableColumns.BelowPhreaticLevelShift, - SoilProfileTableColumns.BelowPhreaticLevelMean, - SoilProfileTableColumns.BelowPhreaticLevelDeviation, - SoilProfileTableColumns.DiameterD70Distribution, - SoilProfileTableColumns.DiameterD70Shift, - SoilProfileTableColumns.DiameterD70Mean, - SoilProfileTableColumns.DiameterD70Deviation, - SoilProfileTableColumns.PermeabilityDistribution, - SoilProfileTableColumns.PermeabilityShift, - SoilProfileTableColumns.PermeabilityMean, - SoilProfileTableColumns.PermeabilityDeviation, - SoilProfileTableColumns.SoilProfileId, - MechanismTableColumns.MechanismName); + string query2D = + "SELECT " + + $"2 as {SoilProfileTableColumns.Dimension}, " + + $"sp2d.SP2D_Name as {SoilProfileTableColumns.ProfileName}, " + + $"layerCount.{SoilProfileTableColumns.LayerCount}, " + + $"sl2d.GeometrySurface as {SoilProfileTableColumns.LayerGeometry}, " + + $"mpl.X as {SoilProfileTableColumns.IntersectionX}, " + + $"{SoilProfileTableColumns.MaterialName}, " + + $"{SoilProfileTableColumns.IsAquifer}, " + + $"{SoilProfileTableColumns.Color}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelDistribution}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelShift}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelMean}, " + + $"{SoilProfileTableColumns.BelowPhreaticLevelDeviation}, " + + $"{SoilProfileTableColumns.DiameterD70Distribution}, " + + $"{SoilProfileTableColumns.DiameterD70Shift}, " + + $"{SoilProfileTableColumns.DiameterD70Mean}, " + + $"{SoilProfileTableColumns.DiameterD70Deviation}, " + + $"{SoilProfileTableColumns.PermeabilityDistribution}, " + + $"{SoilProfileTableColumns.PermeabilityShift}, " + + $"{SoilProfileTableColumns.PermeabilityMean}, " + + $"{SoilProfileTableColumns.PermeabilityDeviation}, " + + $"sp2d.SP2D_ID as {SoilProfileTableColumns.SoilProfileId} " + + "FROM Mechanism AS m " + + "JOIN Segment AS segment USING(ME_ID) " + + "JOIN (SELECT SSM_ID, SP1D_ID, SP2D_ID FROM StochasticSoilProfile GROUP BY SSM_ID, SP1D_ID, SP2D_ID) ssp USING(SSM_ID) " + + "JOIN SoilProfile2D sp2d USING (SP2D_ID) " + + "JOIN (" + + subQueryGetNumberOfLayerProfile2D + + ") layerCount USING (SP2D_ID) " + + "JOIN SoilLayer2D sl2d USING (SP2D_ID) " + + "LEFT JOIN MechanismPointLocation mpl USING(ME_ID, SP2D_ID) " + + "LEFT JOIN (" + + subQueryGetMaterialPropertiesOfLayer + + ") materialProperties USING(MA_ID) " + + "LEFT JOIN (" + + subQueryGetLayerPropertiesOfLayer2D + + ") layerProperties USING(SL2D_ID) " + + $"WHERE m.{MechanismTableColumns.MechanismName} = @{MechanismTableColumns.MechanismName} " + + "GROUP BY sp2d.SP2D_ID, sl2d.SL2D_ID;"; dataReader = CreateDataReader(countQuery + query2D + query1D, new SQLiteParameter { @@ -428,7 +359,7 @@ }, new SQLiteParameter { DbType = DbType.String, - ParameterName = string.Format("@{0}", MechanismTableColumns.MechanismName), + ParameterName = $"@{MechanismTableColumns.MechanismName}", Value = pipingMechanismName }); } Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs =================================================================== diff -u -r1b9445050ddc7786014349d7014c7c4d85242a5d -r61da7f609eef63a149d27eb1c52b2bd908af33b3 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 1b9445050ddc7786014349d7014c7c4d85242a5d) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 61da7f609eef63a149d27eb1c52b2bd908af33b3) @@ -25,7 +25,6 @@ using System.IO; using System.Linq; using Core.Common.Base.IO; -using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; using Core.Common.TestUtil; using Core.Common.Utils.Builders; @@ -50,11 +49,14 @@ string testFile = Path.Combine(testDataPath, "none.soil"); // Call - TestDelegate test = () => { using (new PipingSoilProfileReader(testFile)) {} }; + TestDelegate test = () => + { + using (new PipingSoilProfileReader(testFile)) {} + }; // Assert var exception = Assert.Throws(test); - var expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(UtilsResources.Error_File_does_not_exist); + string expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(UtilsResources.Error_File_does_not_exist); Assert.AreEqual(expectedMessage, exception.Message); } @@ -64,12 +66,14 @@ public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string fileName) { // Call - TestDelegate test = () => { using (new PipingSoilProfileReader(fileName)) {} }; + TestDelegate test = () => + { + using (new PipingSoilProfileReader(fileName)) {} + }; // Assert CriticalFileReadException exception = Assert.Throws(test); - string expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': {1}", - fileName, "bestandspad mag niet leeg of ongedefinieerd zijn."); + string expectedMessage = $"Fout bij het lezen van bestand '{fileName}': bestandspad mag niet leeg of ongedefinieerd zijn."; Assert.AreEqual(expectedMessage, exception.Message); } @@ -87,7 +91,10 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); // Call - TestDelegate test = () => { using (new PipingSoilProfileReader(dbFile)) {} }; + TestDelegate test = () => + { + using (new PipingSoilProfileReader(dbFile)) {} + }; // Assert CriticalFileReadException exception = Assert.Throws(test); @@ -99,7 +106,7 @@ public void ParameteredConstructor_PathToExistingFile_ExpectedValues() { // Setup - string dbName = "emptyschema.soil"; + const string dbName = "emptyschema.soil"; string dbFile = Path.Combine(testDataPath, dbName); // Call @@ -115,7 +122,7 @@ public void Constructor_EmptyDatabase_HasNextFalse() { // Setup - string dbName = "emptyschema.soil"; + const string dbName = "emptyschema.soil"; string dbFile = Path.Combine(testDataPath, dbName); // Call @@ -131,15 +138,18 @@ public void Constructor_IncorrectVersion_ThrowsCriticalFileReadException() { // Setup - var version = "15.0.6.0"; - var dbName = "incorrectversion.soil"; + const string version = "15.0.6.0"; + const string dbName = "incorrectversion.soil"; string dbFile = Path.Combine(testDataPath, dbName); // Precondition Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); // Call - TestDelegate test = () => { using (new PipingSoilProfileReader(dbFile)) {} }; + TestDelegate test = () => + { + using (new PipingSoilProfileReader(dbFile)) {} + }; // Assert CriticalFileReadException exception = Assert.Throws(test); @@ -151,7 +161,7 @@ public void ReadProfile_AfterDatabaseHasBeenRead_ReturnsNull() { // Setup - var testFile = "1dprofile.soil"; + const string testFile = "1dprofile.soil"; string dbFile = Path.Combine(testDataPath, testFile); using (var pipingSoilProfileReader = new PipingSoilProfileReader(dbFile)) @@ -170,7 +180,7 @@ public void ReadProfile_DatabaseWith1DAnd2DProfilesWithSameName_ReturnTwoProfilesWithSameName() { // Setup - var testFile = "combined1d2d.soil"; + const string testFile = "combined1d2d.soil"; string dbFile = Path.Combine(testDataPath, testFile); using (var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile)) @@ -197,9 +207,8 @@ public void ReadProfile_DatabaseWith1DAnd1DSoilProfileWithoutSoilLayers_ReturnOneProfile() { // Setup - var testFile = "1dprofileWithEmpty1d.soil"; + const string testFile = "1dprofileWithEmpty1d.soil"; string dbFile = Path.Combine(testDataPath, testFile); - var expextedProfileName = "Profile"; using (var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile)) { @@ -214,6 +223,7 @@ // Assert Assert.AreEqual(1, pipingSoilProfilesReader.Count); Assert.AreEqual(1, result.Count); + const string expextedProfileName = "Profile"; Assert.AreEqual(expextedProfileName, result[0].Name); } } @@ -222,7 +232,7 @@ public void ReadProfile_DatabaseProfileWithInvalid2dLayerGeometry_SkipsTheProfile() { // Setup - var testFile = "invalid2dGeometry.soil"; + const string testFile = "invalid2dGeometry.soil"; string databaseFilePath = Path.Combine(testDataPath, testFile); using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { @@ -251,7 +261,7 @@ public void ReadProfile_DatabaseProfileWithVerticalSegmentAtX_SkipsTheProfile() { // Setup - var testFile = "vertical2dGeometry.soil"; + const string testFile = "vertical2dGeometry.soil"; string databaseFilePath = Path.Combine(testDataPath, testFile); using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { @@ -280,7 +290,7 @@ public void ReadProfile_DatabaseProfileWithoutValuesForLayerProperties_ReturnsProfileWithAllLayers() { // Setup - var testFile = "1dprofileNoValues.soil"; + const string testFile = "1dprofileNoValues.soil"; using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) { // Call @@ -327,7 +337,7 @@ public void ReadProfile_DatabaseWith1DProfile3Layers_ReturnsProfile() { // Setup - var testFile = "1dprofile.soil"; + const string testFile = "1dprofile.soil"; string dbFile = Path.Combine(testDataPath, testFile); using (var reader = new PipingSoilProfileReader(dbFile)) { @@ -396,7 +406,7 @@ public void ReadProfile_DatabaseWith2DProfile3Layers_ReturnsProfile() { // Setup - var testFile = "2dprofile.soil"; + const string testFile = "2dprofile.soil"; string dbFile = Path.Combine(testDataPath, testFile); using (var reader = new PipingSoilProfileReader(dbFile)) { @@ -462,10 +472,81 @@ } [Test] + public void ReadProfile_DatabaseWith1DProfileInTwoSegments_ReturnsOne1DProfile() + { + // Setup + const string testFile = "1dProfileUsedInTwoSegments.soil"; + string dbFile = Path.Combine(testDataPath, testFile); + + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile)) + { + var result = new Collection(); + + // Call + while (pipingSoilProfilesReader.HasNext) + { + result.Add(pipingSoilProfilesReader.ReadProfile()); + } + + // Assert + Assert.AreEqual(1, pipingSoilProfilesReader.Count); + Assert.AreEqual(1, result.Count); + PipingSoilProfile pipingSoilProfile = result[0]; + Assert.AreEqual("SoilProfile1D", pipingSoilProfile.Name); + Assert.AreEqual(SoilProfileType.SoilProfile1D, pipingSoilProfile.SoilProfileType); + } + } + + [Test] + public void ReadProfile_DatabaseWith2DProfileInTwoSegments_ReturnsOne2DProfile() + { + // Setup + const string testFile = "2dProfileUsedInTwoSegments.soil"; + string dbFile = Path.Combine(testDataPath, testFile); + + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile)) + { + var result = new Collection(); + + // Call + while (pipingSoilProfilesReader.HasNext) + { + result.Add(pipingSoilProfilesReader.ReadProfile()); + } + + // Assert + Assert.AreEqual(1, pipingSoilProfilesReader.Count); + Assert.AreEqual(1, result.Count); + PipingSoilProfile pipingSoilProfile = result[0]; + Assert.AreEqual("SoilProfile2D", pipingSoilProfile.Name); + Assert.AreEqual(SoilProfileType.SoilProfile2D, pipingSoilProfile.SoilProfileType); + } + } + + [Test] + public void Dispose_CalledMultipleTimes_DoesNotThrow() + { + const string testFile = "1dprofile.soil"; + string dbFile = Path.Combine(testDataPath, testFile); + + // Call + TestDelegate call = () => + { + using (var reader = new PipingSoilProfileReader(dbFile)) + { + reader.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] public void Dispose_AfterConstruction_CorrectlyReleasesFile() { // Setup - var testFile = "1dprofile.soil"; + const string testFile = "1dprofile.soil"; string dbFile = Path.Combine(testDataPath, testFile); // Precondition @@ -482,7 +563,7 @@ public void Dispose_WhenReadProfile_CorrectlyReleasesFile() { // Setup - var testFile = "1dprofile.soil"; + const string testFile = "1dprofile.soil"; string dbFile = Path.Combine(testDataPath, testFile); // Precondition @@ -540,7 +621,7 @@ private void GivenDatabaseWith1DProfile_WhenReadingTheCompleteDatabase_ReturnsCompleteSoilProfile() { // Given - var testFile = "1dprofile.soil"; + const string testFile = "1dprofile.soil"; using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) { // When @@ -576,7 +657,7 @@ private void GivenACompleteDatabase_WhenReadingTheCompleteDatabase_ReturnsProfilesWithLayersAndGeometries() { // Given - var testFile = "complete.soil"; + const string testFile = "complete.soil"; using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) { // When @@ -689,7 +770,7 @@ 3 }, result.Select(p => p.Layers.Count()).ToArray()); - var firstProfile = result.FirstOrDefault(l => l.Name == "Segment_36005_1D1"); + PipingSoilProfile firstProfile = result.FirstOrDefault(l => l.Name == "Segment_36005_1D1"); Assert.NotNull(firstProfile); var expectedFirstProfileLayersTops = new[] { @@ -702,11 +783,11 @@ -17.0, -25.0 }; - var layerTops = firstProfile.Layers.Select(l => l.Top).ToArray(); + double[] layerTops = firstProfile.Layers.Select(l => l.Top).ToArray(); CollectionAssert.AllItemsAreUnique(layerTops); CollectionAssert.AreEqual(expectedFirstProfileLayersTops, layerTops, new DoubleWithToleranceComparer(1e-6)); - var secondProfile = result.FirstOrDefault(l => l.Name == "AD640M00_Segment_36005_1D1"); + PipingSoilProfile secondProfile = result.FirstOrDefault(l => l.Name == "AD640M00_Segment_36005_1D1"); Assert.NotNull(secondProfile); var expectedSecondProfileLayersTops = new[] { @@ -720,7 +801,7 @@ -17, -25, }; - var layer2Tops = secondProfile.Layers.Select(l => l.Top).ToArray(); + double[] layer2Tops = secondProfile.Layers.Select(l => l.Top).ToArray(); CollectionAssert.AllItemsAreUnique(layer2Tops); CollectionAssert.AreEqual(expectedSecondProfileLayersTops, layer2Tops, new DoubleWithToleranceComparer(1e-6)); } Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/1dProfileUsedInTwoSegments.soil =================================================================== diff -u Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/PipingSoilProfilesReader/2dProfileUsedInTwoSegments.soil =================================================================== diff -u Binary files differ