Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rf45d2d498e0354eb99e75191465d4cd5dc4dca13 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f45d2d498e0354eb99e75191465d4cd5dc4dca13) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -206,15 +206,24 @@ } /// - /// Looks up a localized string similar to Ondergrondschematisering '{0}' in database bevat geen geldige waarde in kolom '{1}'.. + /// Looks up a localized string similar to Ondergrondschematisering bevat geen geldige waarde in kolom '{0}'.. /// - public static string PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_ { + public static string PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_ { get { - return ResourceManager.GetString("PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_", resourceCulture); + return ResourceManager.GetString("PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_", resourceCulture); } } /// + /// Looks up a localized string similar to ondergrondschematisering '{0}'. + /// + public static string PipingSoilProfileReader_SoilProfileName_0_ { + get { + return ResourceManager.GetString("PipingSoilProfileReader_SoilProfileName_0_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het bestand is niet geschikt om profielmetingen uit te lezen (Verwachte header: locationid;X1;Y1;Z1).. /// public static string PipingSurfaceLinesCsvReader_File_invalid_header { Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx =================================================================== diff -u -rf45d2d498e0354eb99e75191465d4cd5dc4dca13 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision f45d2d498e0354eb99e75191465d4cd5dc4dca13) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -156,8 +156,8 @@ Kon geen ondergrond profielen verkrijgen van de database. - - Ondergrondschematisering '{0}' in database bevat geen geldige waarde in kolom '{1}'. + + Ondergrondschematisering bevat geen geldige waarde in kolom '{0}'. Het bestand is niet geschikt om profielmetingen uit te lezen (Verwachte header: locationid;X1;Y1;Z1). @@ -201,4 +201,7 @@ profielmeting '{0}' + + ondergrondschematisering '{0}' + \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/CriticalProfileProperties.cs =================================================================== diff -u -rd2b5b334c49948fa49297a1d24c13bc98aa6ee1e -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/CriticalProfileProperties.cs (.../CriticalProfileProperties.cs) (revision d2b5b334c49948fa49297a1d24c13bc98aa6ee1e) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/CriticalProfileProperties.cs (.../CriticalProfileProperties.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -1,4 +1,6 @@ using System; + +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; @@ -27,7 +29,13 @@ } catch (InvalidCastException e) { - throw new CriticalFileReadException(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column, e); + var messageBuilder = new FileReaderErrorMessageBuilder(reader.Path); + if (!string.IsNullOrEmpty(ProfileName)) + { + messageBuilder.WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, ProfileName)); + } + var message = messageBuilder.Build(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); + throw new CriticalFileReadException(message, e); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/IRowBasedDatabaseReader.cs =================================================================== diff -u -rd2b5b334c49948fa49297a1d24c13bc98aa6ee1e -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/IRowBasedDatabaseReader.cs (.../IRowBasedDatabaseReader.cs) (revision d2b5b334c49948fa49297a1d24c13bc98aa6ee1e) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/IRowBasedDatabaseReader.cs (.../IRowBasedDatabaseReader.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -31,5 +31,10 @@ /// The value in the column, or null if the value was . /// Thrown when the value in the column could not be casted to type . T? ReadOrNull(string columnName) where T : struct; + + /// + /// Gets the path of the database being read. + /// + string Path { get; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs =================================================================== diff -u -r458ef844024d216a682e09fe8193fd6188921bc2 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 458ef844024d216a682e09fe8193fd6188921bc2) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -3,6 +3,7 @@ using System.Data.SQLite; using System.IO; using Ringtoets.Piping.Data; +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; @@ -17,7 +18,7 @@ private const string pipingMechanismName = "Piping"; private const string mechanismParameterName = "mechanism"; - private readonly string databaseFileName; + private readonly string fullFilePath; private SQLiteConnection connection; private SQLiteDataReader dataReader; @@ -47,10 +48,11 @@ } if (!File.Exists(databaseFilePath)) { - throw new CriticalFileReadException(Resources.Error_File_does_not_exist); + var message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(Resources.Error_File_does_not_exist); + throw new CriticalFileReadException(message); } - databaseFileName = Path.GetFileName(databaseFilePath); + fullFilePath = databaseFilePath; OpenConnection(databaseFilePath); InitializeReader(); } @@ -86,7 +88,8 @@ } catch (InvalidCastException e) { - throw new CriticalFileReadException(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column, e); + var message = new FileReaderErrorMessageBuilder(fullFilePath).Build(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); + throw new CriticalFileReadException(message, e); } } @@ -126,6 +129,14 @@ return (T) valueObject; } + public string Path + { + get + { + return fullFilePath; + } + } + /// /// Reads a value at column from the database. /// @@ -371,8 +382,8 @@ catch (SQLiteException e) { Dispose(); - var exception = new CriticalFileReadException(string.Format(Resources.Error_SoilProfile_read_from_database, databaseFileName), e); - throw exception; + var message = new FileReaderErrorMessageBuilder(fullFilePath).Build(Resources.Error_SoilProfile_read_from_database); + throw new CriticalFileReadException(message, e); } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs =================================================================== diff -u -rc1e31ab57c197658d1c75750feef8856df7e9f6b -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision c1e31ab57c197658d1c75750feef8856df7e9f6b) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -36,22 +36,25 @@ reader.MoveNext(); } - return Build(soilProfileBuilder, profileName); + return Build(soilProfileBuilder, reader.Path, profileName); } /// /// Builds a from the given . /// /// Thrown when building the failed. - private static PipingSoilProfile Build(SoilProfileBuilder1D soilProfileBuilder, string profileName) + private static PipingSoilProfile Build(SoilProfileBuilder1D soilProfileBuilder, string path, string profileName) { try { return soilProfileBuilder.Build(); } catch (SoilProfileBuilderException e) { - throw new PipingSoilProfileReadException(profileName, e.Message, e); + var message = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) + .Build(e.Message); + throw new PipingSoilProfileReadException(profileName, message, e); } } @@ -95,7 +98,9 @@ } catch (InvalidCastException e) { - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, profileName, readColumn); + var message = new FileReaderErrorMessageBuilder(reader.Path) + .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) + .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn)); throw new PipingSoilProfileReadException(profileName, message, e); } } @@ -139,7 +144,9 @@ } catch (InvalidCastException e) { - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, profileName, readColumn); + var message = new FileReaderErrorMessageBuilder(reader.Path) + .WithSubject(String.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) + .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn)); throw new PipingSoilProfileReadException(profileName, message, e); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs =================================================================== diff -u -rc1e31ab57c197658d1c75750feef8856df7e9f6b -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs (.../SoilProfile2DReader.cs) (revision c1e31ab57c197658d1c75750feef8856df7e9f6b) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs (.../SoilProfile2DReader.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -1,7 +1,6 @@ using System; using System.Data.SQLite; -using System.IO; -using System.Xml; + using Ringtoets.Piping.Data; using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; @@ -49,11 +48,11 @@ } catch (SoilProfileBuilderException e) { - throw new PipingSoilProfileReadException(criticalProperties.ProfileName, e.Message, e); + throw CreatePipingSoilProfileReadException(reader.Path, criticalProperties.ProfileName, e); } catch (ArgumentException e) { - throw new PipingSoilProfileReadException(criticalProperties.ProfileName, e.Message, e); + throw CreatePipingSoilProfileReadException(reader.Path, criticalProperties.ProfileName, e); } } @@ -81,7 +80,7 @@ } catch (SoilLayer2DConversionException e) { - throw new PipingSoilProfileReadException(profileName, e.Message, e); + throw CreatePipingSoilProfileReadException(reader.Path, profileName, e); } if (pipingSoilLayer != null) @@ -108,42 +107,24 @@ } catch (InvalidCastException e) { - var message = string.Format( - Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, - profileName, - SoilProfileDatabaseColumns.LayerGeometry - ); - throw new PipingSoilProfileReadException(profileName, message, e); + throw CreatePipingSoilProfileReadException(reader.Path, profileName, e); } } - - private class RequiredProfileProperties + private static PipingSoilProfileReadException CreatePipingSoilProfileReadException(string filePath, string profileName, string errorMessage, Exception innerException) { - internal readonly double IntersectionX; + var message = new FileReaderErrorMessageBuilder(filePath) + .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) + .Build(errorMessage); + return new PipingSoilProfileReadException(profileName, message, innerException); + } - /// - /// Creates a new instance of , which contains properties - /// that are required to create a complete . If these properties - /// cannot be read, then the reader can proceed to the next profile. - /// - /// The to read the required profile property values from. - /// The profile name used in generating exceptions messages if casting failed. - /// Thrown when the values in the database could not be - /// casted to the expected column types. - internal RequiredProfileProperties(IRowBasedDatabaseReader reader, string profileName) - { - string readColumn = SoilProfileDatabaseColumns.IntersectionX; - try - { - IntersectionX = reader.Read(readColumn); - } - catch (InvalidCastException e) - { - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, profileName, readColumn); - throw new PipingSoilProfileReadException(profileName, message, e); - } - } + private static PipingSoilProfileReadException CreatePipingSoilProfileReadException(string filePath, string profileName, Exception innerException) + { + var message = new FileReaderErrorMessageBuilder(filePath) + .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) + .Build(innerException.Message); + return new PipingSoilProfileReadException(profileName, message, innerException); } private class LayerProperties @@ -180,10 +161,38 @@ } catch (InvalidCastException e) { - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, profileName, readColumn); - throw new PipingSoilProfileReadException(profileName, message, e); + var message = string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn); + throw CreatePipingSoilProfileReadException(reader.Path, profileName, message, e); } } } + + private class RequiredProfileProperties + { + internal readonly double IntersectionX; + + /// + /// Creates a new instance of , which contains properties + /// that are required to create a complete . If these properties + /// cannot be read, then the reader can proceed to the next profile. + /// + /// The to read the required profile property values from. + /// The profile name used in generating exceptions messages if casting failed. + /// Thrown when the values in the database could not be + /// casted to the expected column types. + internal RequiredProfileProperties(IRowBasedDatabaseReader reader, string profileName) + { + string readColumn = SoilProfileDatabaseColumns.IntersectionX; + try + { + IntersectionX = reader.Read(readColumn); + } + catch (InvalidCastException e) + { + var message = string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn); + throw CreatePipingSoilProfileReadException(reader.Path, profileName, message, e); + } + } + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/CriticalProfilePropertiesTest.cs =================================================================== diff -u -rd2b5b334c49948fa49297a1d24c13bc98aa6ee1e -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/CriticalProfilePropertiesTest.cs (.../CriticalProfilePropertiesTest.cs) (revision d2b5b334c49948fa49297a1d24c13bc98aa6ee1e) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/CriticalProfilePropertiesTest.cs (.../CriticalProfilePropertiesTest.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -1,6 +1,8 @@ using System; using NUnit.Framework; using Rhino.Mocks; + +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.IO.SoilProfile; @@ -47,10 +49,12 @@ // Setup var reader = mocks.StrictMock(); var layerCount = 1; + string path = "A"; var invalidCastException = new InvalidCastException(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).IgnoreArguments().Throw(invalidCastException); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).IgnoreArguments().Return(layerCount).Repeat.Any(); + reader.Expect(r => r.Path).Return(path); mocks.ReplayAll(); @@ -60,7 +64,9 @@ // Assert var exception = Assert.Throws(test); Assert.AreSame(invalidCastException, exception.InnerException); - Assert.AreSame(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column, exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .Build(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -71,10 +77,12 @@ // Setup var reader = mocks.StrictMock(); string profileName = "profile"; + string path = "A"; var invalidCastException = new InvalidCastException(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).IgnoreArguments().Return(profileName).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Throw(invalidCastException); + reader.Expect(r => r.Path).Return(path); mocks.ReplayAll(); @@ -84,7 +92,10 @@ // Assert var exception = Assert.Throws(test); Assert.AreSame(invalidCastException, exception.InnerException); - Assert.AreSame(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column, exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", profileName)) + .Build(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs =================================================================== diff -u -rf45d2d498e0354eb99e75191465d4cd5dc4dca13 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision f45d2d498e0354eb99e75191465d4cd5dc4dca13) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -6,6 +6,7 @@ using Core.Common.TestUtils; using NUnit.Framework; using Ringtoets.Piping.Data; +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.IO.SoilProfile; @@ -28,7 +29,8 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual(Resources.Error_File_does_not_exist, exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(Resources.Error_File_does_not_exist); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -62,11 +64,27 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual(String.Format(Resources.Error_SoilProfile_read_from_database, dbName), exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(String.Format(Resources.Error_SoilProfile_read_from_database, dbName)); + Assert.AreEqual(expectedMessage, exception.Message); Assert.IsTrue(FileHelper.CanOpenFileForWrite(dbFile)); } [Test] + public void ParameteredConstructor_PathToExistingFile_ExpectedValues() + { + // Setup + var dbName = "emptyschema.soil"; + string dbFile = Path.Combine(testDataPath, dbName); + + // Call + using (var pipingSoilProfileReader = new PipingSoilProfileReader(dbFile)) + { + // Assert + Assert.AreEqual(dbFile, pipingSoilProfileReader.Path); + } + } + + [Test] public void Constructor_EmptyDatabase_HasNextFalse() { // Setup @@ -149,14 +167,18 @@ { // Setup var testFile = "invalid2dGeometry.soil"; - using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) + string databaseFilePath = Path.Combine(testDataPath, testFile); + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { // Call TestDelegate profile = () => pipingSoilProfilesReader.ReadProfile(); // Assert var exception = Assert.Throws(profile); - Assert.AreEqual(Resources.SoilLayer2DReader_Geometry_contains_no_valid_xml, exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(databaseFilePath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(Resources.SoilLayer2DReader_Geometry_contains_no_valid_xml); + Assert.AreEqual(expectedMessage, exception.Message); // Call var pipingSoilProfile = pipingSoilProfilesReader.ReadProfile(); @@ -174,14 +196,17 @@ { // Setup var testFile = "vertical2dGeometry.soil"; - using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) + string databaseFilePath = Path.Combine(testDataPath, testFile); + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { // Call TestDelegate profile = () => pipingSoilProfilesReader.ReadProfile(); // Assert var exception = Assert.Throws(profile); - var message = String.Format(Resources.Error_Can_not_determine_1D_profile_with_vertical_segments_at_X_0_, 85.2); + var message = new FileReaderErrorMessageBuilder(databaseFilePath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(String.Format(Resources.Error_Can_not_determine_1D_profile_with_vertical_segments_at_X_0_, 85.2)); Assert.AreEqual(message, exception.Message); // Call @@ -220,14 +245,17 @@ { // Setup var testFile = "invalidBottom1dProfile.soil"; - using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) + string databaseFilePath = Path.Combine(testDataPath, testFile); + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { // Call TestDelegate profile = () => pipingSoilProfilesReader.ReadProfile(); // Assert var exceptionMessage = Assert.Throws(profile).Message; - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, "Profile", "Bottom"); + var message = new FileReaderErrorMessageBuilder(databaseFilePath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, "Bottom")); Assert.AreEqual(message, exceptionMessage); } } @@ -237,14 +265,17 @@ { // Setup var testFile = "invalidTop1dProfile.soil"; - using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) + string databaseFilePath = Path.Combine(testDataPath, testFile); + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { // Call TestDelegate profile = () => pipingSoilProfilesReader.ReadProfile(); // Assert var exceptionMessage = Assert.Throws(profile).Message; - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, "Profile", "Top"); + var message = new FileReaderErrorMessageBuilder(databaseFilePath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, "Top")); Assert.AreEqual(message, exceptionMessage); } } @@ -254,14 +285,17 @@ { // Setup var testFile = "incorrectValue2dProperty.soil"; - using (var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile))) + string databaseFilePath = Path.Combine(testDataPath, testFile); + using (var pipingSoilProfilesReader = new PipingSoilProfileReader(databaseFilePath)) { // Call TestDelegate profile = () => pipingSoilProfilesReader.ReadProfile(); // Assert var exceptionMessage = Assert.Throws(profile).Message; - var message = string.Format(Resources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, "Profile", "DryUnitWeight"); + var message = new FileReaderErrorMessageBuilder(databaseFilePath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, "DryUnitWeight")); Assert.AreEqual(message, exceptionMessage); } } @@ -333,7 +367,7 @@ Assert.IsTrue(FileHelper.CanOpenFileForWrite(dbFile), "Precondition failed: The file should be writable to begin with."); PipingSoilProfileReader pipingSoilProfilesReader = null; - PipingSoilProfile profile = null; + PipingSoilProfile profile; try { pipingSoilProfilesReader = new PipingSoilProfileReader(dbFile); Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs =================================================================== diff -u -r6b3d2269de35bec503bbd3965ae9b532e1c6f216 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs (.../SoilProfile1DReaderTest.cs) (revision 6b3d2269de35bec503bbd3965ae9b532e1c6f216) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile1DReaderTest.cs (.../SoilProfile1DReaderTest.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -2,6 +2,8 @@ using System.Linq; using NUnit.Framework; using Rhino.Mocks; + +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.SoilProfile; @@ -24,7 +26,12 @@ public void ReadFrom_InvalidCriticalProperty_ThrowsCriticalFileReadException() { // Setup + const string profileName = ""; + const string path = "A"; + + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(profileName); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Throw(new InvalidCastException()); + reader.Expect(r => r.Path).Return(path); mocks.ReplayAll(); @@ -33,7 +40,10 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.", exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", profileName)) + .Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -42,8 +52,12 @@ public void ReadFrom_InvalidRequiredProperty_ThrowsPipingSoilProfileReadException() { // Setup + const string profileName = ""; + const string path = "A"; + + reader.Expect(r => r.Path).Return(path); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Return(1).Repeat.Any(); - reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return("").Repeat.Any(); + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(profileName).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.Bottom)).Throw(new InvalidCastException()); mocks.ReplayAll(); @@ -53,7 +67,10 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ondergrondschematisering '' in database bevat geen geldige waarde in kolom 'Bottom'.", exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", profileName)) + .Build("Ondergrondschematisering bevat geen geldige waarde in kolom 'Bottom'."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -62,16 +79,23 @@ public void ReadFrom_ZeroLayerCount_ThrowsPipingSoilProfileReadException() { // Setup - SetExpectations(0, "", 0.0, 0.0, 1.0, 0.0, 0.0, 0.0); + const string profileName = ""; + const string path = "A"; + SetExpectations(0, profileName, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0); + reader.Expect(r => r.Path).Return(path); + mocks.ReplayAll(); // Call TestDelegate test = () => SoilProfile1DReader.ReadFrom(reader); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Geen lagen gevonden voor het profiel.", exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", profileName)) + .Build("Geen lagen gevonden voor het profiel."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -80,6 +104,11 @@ public void ReadFrom_InvalidIsAquifer_ReturnsProfileWithNullValuesOnLayer() { // Setup + const string path = "A"; + const string profileName = ""; + + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(profileName); + reader.Expect(r => r.Path).Return(path); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Return(1).Repeat.Any(); reader.Expect(r => r.ReadOrNull(SoilProfileDatabaseColumns.IsAquifer)).Throw(new InvalidCastException()); mocks.ReplayAll(); @@ -89,7 +118,10 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ondergrondschematisering '' in database bevat geen geldige waarde in kolom 'IsAquifer'.", exception.Message); + var expectedMessage = new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", profileName)) + .Build("Ondergrondschematisering bevat geen geldige waarde in kolom 'IsAquifer'."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile2DReaderTest.cs =================================================================== diff -u -r6b3d2269de35bec503bbd3965ae9b532e1c6f216 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile2DReaderTest.cs (.../SoilProfile2DReaderTest.cs) (revision 6b3d2269de35bec503bbd3965ae9b532e1c6f216) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfile/SoilProfile2DReaderTest.cs (.../SoilProfile2DReaderTest.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -1,8 +1,9 @@ using System; using System.Linq; -using System.Xml; using NUnit.Framework; using Rhino.Mocks; + +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Exceptions; using Ringtoets.Piping.IO.SoilProfile; using Ringtoets.Piping.IO.Test.TestHelpers; @@ -36,6 +37,11 @@ public void ReadFrom_InvalidCriticalProperty_ThrowsCriticalFileReadException() { // Setup + const string path = "A"; + const string name = "B"; + + reader.Expect(r => r.Path).Return(path); + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(name); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Throw(new InvalidCastException()); mocks.ReplayAll(); @@ -45,7 +51,8 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -54,8 +61,12 @@ public void ReadFrom_InvalidRequiredProperty_ThrowsPipingSoilProfileReadException() { // Setup + const string name = "A"; + const string path = "B"; + + reader.Expect(r => r.Path).Return(path); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Return(1).Repeat.Any(); - reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return("").Repeat.Any(); + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(name).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.IntersectionX)).Throw(new InvalidCastException()); mocks.ReplayAll(); @@ -65,7 +76,8 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ondergrondschematisering '' in database bevat geen geldige waarde in kolom 'IntersectionX'.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "Ondergrondschematisering bevat geen geldige waarde in kolom 'IntersectionX'."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -74,8 +86,10 @@ public void ReadFrom_DoubleNaNIntersectionX_ThrowsPipingSoilProfileReadException() { // Setup - string name = "profile"; + const string name = "profile"; + const string path = "A"; + reader.Expect(r => r.Path).Return(path); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Return(1).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(name).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.IntersectionX)).Return(double.NaN); @@ -87,7 +101,7 @@ // Assert var exception = Assert.Throws(test); - var expectedMessage = string.Format("Geen geldige X waarde gevonden om intersectie te maken uit 2D profiel '{0}'.", name); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, string.Format("Geen geldige X waarde gevonden om intersectie te maken uit 2D profiel '{0}'.", name)); Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); @@ -97,16 +111,21 @@ public void ReadFrom_ZeroLayerCount_ThrowsPipingSoilProfileReadException() { // Setup - SetExpectations(0, "", 0.0, 1.0, 0.0, 0.0, 0.0, new byte[0]); + const string name = "profile"; + const string path = "A"; + reader.Expect(r => r.Path).Return(path); + SetExpectations(0, name, 0.0, 1.0, 0.0, 0.0, 0.0, new byte[0]); + mocks.ReplayAll(); // Call TestDelegate test = () => SoilProfile2DReader.ReadFrom(reader); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Geen lagen gevonden voor het profiel.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "Geen lagen gevonden voor het profiel."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -115,16 +134,21 @@ public void ReadFrom_NullGeometry_ThrowsPipingSoilProfileReadException() { // Setup - SetExpectations(1, "", 0.0, 1.0, 0.0, 0.0, 0.0, null); + const string name = "profile"; + const string path = "A"; + reader.Expect(r => r.Path).Return(path); + SetExpectations(1, name, 0.0, 1.0, 0.0, 0.0, 0.0, null); + mocks.ReplayAll(); // Call TestDelegate test = () => SoilProfile2DReader.ReadFrom(reader); // Assert var exception = Assert.Throws(test); - StringAssert.StartsWith("De geometrie is leeg.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "De geometrie is leeg."); + StringAssert.StartsWith(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -133,16 +157,21 @@ public void ReadFrom_EmptyGeometry_ThrowsPipingSoilProfileReadException() { // Setup - SetExpectations(1, "", 0.0, 1.0, 0.0, 0.0, 0.0, new byte[0]); + const string name = "cool name"; + const string path = "A"; + SetExpectations(1, name, 0.0, 1.0, 0.0, 0.0, 0.0, new byte[0]); + reader.Expect(r => r.Path).Return(path); + mocks.ReplayAll(); // Call TestDelegate test = () => SoilProfile2DReader.ReadFrom(reader); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Het XML-document dat de geometrie beschrijft voor de laag is niet geldig.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "Het XML-document dat de geometrie beschrijft voor de laag is niet geldig."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -151,6 +180,11 @@ public void ReadFrom_InvalidIsAquifer_ReturnsProfileWithNullValuesOnLayer() { // Setup + const string name = "cool name"; + const string path = "A"; + + reader.Expect(r => r.Path).Return(path); + reader.Expect(r => r.Read(SoilProfileDatabaseColumns.ProfileName)).Return(name); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerCount)).Return(1).Repeat.Any(); reader.Expect(r => r.ReadOrNull(SoilProfileDatabaseColumns.IsAquifer)).Throw(new InvalidCastException()); mocks.ReplayAll(); @@ -160,7 +194,8 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("Ondergrondschematisering '' in database bevat geen geldige waarde in kolom 'IsAquifer'.", exception.Message); + var expectedMessage = GetExpectedSoilProfileReaderErrorMessage(path, name, "Ondergrondschematisering bevat geen geldige waarde in kolom 'IsAquifer'."); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -236,5 +271,12 @@ reader.Expect(r => r.ReadOrNull(SoilProfileDatabaseColumns.DryUnitWeight)).Return(dryUnitWeight).Repeat.Any(); reader.Expect(r => r.Read(SoilProfileDatabaseColumns.LayerGeometry)).Return(geometry).Repeat.Any(); } + + private static string GetExpectedSoilProfileReaderErrorMessage(string path, string name, string errorMessage) + { + return new FileReaderErrorMessageBuilder(path) + .WithSubject(string.Format("ondergrondschematisering '{0}'", name)) + .Build(errorMessage); + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -rd992a9538644381321f71d536c9ea85813d4c443 -rd082f5444ccd9571f4fabb4c47f1082fa5ece21e --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision d992a9538644381321f71d536c9ea85813d4c443) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision d082f5444ccd9571f4fabb4c47f1082fa5ece21e) @@ -9,6 +9,7 @@ using Rhino.Mocks; using Ringtoets.Piping.Data; +using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.Plugin.FileImporter; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; @@ -261,8 +262,7 @@ Action call = () => importedItem = importer.ImportItem(corruptPath, observableSoilProfileList); // Assert - var internalErrorMessage = string.Format(RingtoetsIOResources.Error_SoilProfile_read_from_database, - Path.GetFileName(corruptPath)); + var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath).Build(RingtoetsIOResources.Error_SoilProfile_read_from_database); var expectedLogMessage = string.Format(ApplicationResources.PipingSoilProfilesImporter_Critical_error_reading_File_0_Cause_1_, corruptPath, internalErrorMessage); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); @@ -299,8 +299,10 @@ Action call = () => importedItem = importer.ImportItem(corruptPath, observableSoilProfileList); // Assert - var internalErrorMessage = string.Format(RingtoetsIOResources.PipingSoilProfileReader_Profile_0_has_invalid_value_on_Column_1_, - "Profile","IntersectionX"); + var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) + .WithSubject("ondergrondschematisering 'Profile'") + .Build(string.Format(RingtoetsIOResources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, + "IntersectionX")); var expectedLogMessage = string.Format(ApplicationResources.PipingSoilProfilesImporter_ReadSoilProfiles_File_0_Message_1_, corruptPath, internalErrorMessage); TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1);