Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r99890512d1c7a9b99f05f0dd60ec638f16011080 -r80d15fa9ca554e01c854788dbae6e2409c78d282 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 99890512d1c7a9b99f05f0dd60ec638f16011080) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -209,10 +209,12 @@ if (!hasCharacteristicPointsFile) { - log.Info(string.Format(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, path)); + log.InfoFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, path); return new ReadResult(false); } + log.InfoFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_, path); + CharacteristicPointsCsvReader reader; try { @@ -296,17 +298,15 @@ private ReadResult HandleCriticalSurfaceLineReadError(Exception e) { - var message = string.Format(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); - log.Error(message); return new ReadResult(true); } private ReadResult HandleCriticalCharacteristicPointsReadError(Exception e) { - var message = string.Format(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, e.Message); - log.Error(message); return new ReadResult(true); } @@ -322,6 +322,10 @@ { SetCharacteristicPointsOnSurfaceLine(readSurfaceLine, characteristicPointsLocation); } + else if (readCharacteristicPointsLocations.Count > 0) + { + log.WarnFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for_SurfaceLine_0_, readSurfaceLine.Name); + } targetCollection.Add(readSurfaceLine); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r99890512d1c7a9b99f05f0dd60ec638f16011080 -r80d15fa9ca554e01c854788dbae6e2409c78d282 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 99890512d1c7a9b99f05f0dd60ec638f16011080) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -163,6 +163,16 @@ } /// + /// Looks up a localized string similar to Er konden geen karakteristieke punten gevonden worden voor profielmeting '{0}'.. + /// + public static string PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for_SurfaceLine_0_ { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_AddImportedDataToModel_No_characteristic_points_for" + + "_SurfaceLine_0_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Geïmporteerde data toevoegen aan faalmechanisme. /// public static string PipingSurfaceLinesCsvImporter_Adding_imported_data_to_model { @@ -240,6 +250,16 @@ } /// + /// Looks up a localized string similar to Beginnen met het inlezen van karakteristieke punten uit bestand '{0}'.. + /// + public static string PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_ { + get { + return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characterist" + + "ic_points_from_file_0_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to {0} ///Deze profielmeting wordt overgeslagen.. /// Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -r99890512d1c7a9b99f05f0dd60ec638f16011080 -r80d15fa9ca554e01c854788dbae6e2409c78d282 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 99890512d1c7a9b99f05f0dd60ec638f16011080) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -188,4 +188,10 @@ Karakteristiek punt '{0}' van profielmeting '{1}' is overgeslagen. {2} + + Er konden geen karakteristieke punten gevonden worden voor profielmeting '{0}'. + + + Beginnen met het inlezen van karakteristieke punten uit bestand '{0}'. + \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn;;;;;;;;;;;;;;;;; +Rotterdam1;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45;94305.3566362;427889.900123;1.65;94315.0957947;427913.908281;1.66;94325.0614453;427941.766804;1.55;94331.1767309;427960.112661;1.44 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;;;;;;;;;;;;;;; Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.krp.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.krp.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_EmptyCharacteristicPoints.krp.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1 @@ \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn;;;;;;;;;;;;;;;;; +Rotterdam1;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45;94305.3566362;427889.900123;1.65;94315.0957947;427913.908281;1.66;94325.0614453;427941.766804;1.55;94331.1767309;427960.112661;1.44 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;;;;;;;;;;;;;;; Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.krp.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.krp.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.krp.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,2 @@ +SomethingWrong;X_Maaiveld binnenwaarts;Y_Maaiveld binnenwaarts;Z_Maaiveld binnenwaarts;X_Insteek sloot polderzijde;Y_Insteek_sloot polderzijde;Z_Insteek sloot polderzijde;X_Slootbodem polderzijde;Y_Slootbodem polderzijde;Z_Slootbodem polderzijde;X_Slootbodem dijkzijde;Y_Slootbodem dijkzijde;Z_Slootbodem dijkzijde;X_Insteek sloot dijkzijde;Y_Insteek_sloot dijkzijde;Z_Insteek sloot dijkzijde;X_Teen dijk binnenwaarts;Y_Teen dijk binnenwaarts;Z_Teen dijk binnenwaarts;X_Kruin binnenberm;Y_Kruin binnenberm;Z_Kruin binnenberm;X_Insteek binnenberm;Y_Insteek binnenberm;Z_Insteek binnenberm;X_Kruin binnentalud;Y_Kruin binnentalud;Z_Kruin binnentalud;X_Verkeersbelasting kant binnenwaarts;Y_Verkeersbelasting kant binnenwaarts;Z_Verkeersbelasting kant binnenwaarts;X_Verkeersbelasting kant buitenwaarts;Y_Verkeersbelasting kant buitenwaarts;Z_Verkeersbelasting kant buitenwaarts;X_Kruin buitentalud;Y_Kruin buitentalud;Z_Kruin buitentalud;X_Insteek buitenberm;Y_Insteek buitenberm;Z_Insteek buitenberm;X_Kruin buitenberm;Y_Kruin buitenberm;Z_Kruin buitenberm;X_Teen dijk buitenwaarts;Y_Teen dijk buitenwaarts;Z_Teen dijk buitenwaarts;X_Maaiveld buitenwaarts;Y_Maaiveld buitenwaarts;Z_Maaiveld buitenwaarts;X_Dijktafelhoogte;Y_Dijktafelhoogte;Z_Dijktafelhoogte;Volgnummer +ValidLocation;100;0;0.74;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;43.71;0;0.18;-1;-1;-1;-1;-1;-1;36.17;0;2.89;36.17;0;2.89;33.67;0;2.986;32.72;0;2.96;-1;-1;-1;-1;-1;-1;24.72;0;0.52;0;0;0.47;12.96;0;-0.07;1 Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn;;;;;;;;;;;;;;;;; +Rotterdam1;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45;94305.3566362;427889.900123;1.65;94315.0957947;427913.908281;1.66;94325.0614453;427941.766804;1.55;94331.1767309;427960.112661;1.44 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;;;;;;;;;;;;;;; Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.krp.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.krp.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithCharacteristicPoints.krp.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X_insteek sloot polderzijde;Y_insteek sloot polderzijde;Z_insteek sloot polderzijde;X_slootbodem polderzijde;Y_slootbodem polderzijde;Z_slootbodem polderzijde;X_slootbodem dijkzijde;Y_slootbodem dijkzijde;Z_slootbodem dijkzijde;X_insteek sloot dijkzijde;Y_insteek sloot dijkzijde;Z_insteek sloot dijkzijde; +Rotterdam1;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;5.7;0;1.1 \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn;;;;;;;;;;;;;;;;; +Rotterdam1Invalid;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45;94305.3566362;427889.900123;1.65;94315.0957947;427913.908281;1.66;94325.0614453;427941.766804;1.55;94331.1767309;427960.112661;1.44 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;;;;;;;;;;;;;;; Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.krp.csv =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.krp.csv (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/test-data/SurfaceLines/TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.krp.csv (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -0,0 +1,3 @@ +Profielnaam;X_insteek sloot polderzijde;Y_insteek sloot polderzijde;Z_insteek sloot polderzijde;X_slootbodem polderzijde;Y_slootbodem polderzijde;Z_slootbodem polderzijde;X_slootbodem dijkzijde;Y_slootbodem dijkzijde;Z_slootbodem dijkzijde;X_insteek sloot dijkzijde;Y_insteek sloot dijkzijde;Z_insteek sloot dijkzijde; +Rotterdam1Invalid;94263.0026213;invalid;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45 +ArtifcialLocal;2.3;0;1.0;4.4;0;2.0;5.7;0;1.1;5.7;0;1.1 \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs =================================================================== diff -u -r99890512d1c7a9b99f05f0dd60ec638f16011080 -r80d15fa9ca554e01c854788dbae6e2409c78d282 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision 99890512d1c7a9b99f05f0dd60ec638f16011080) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision 80d15fa9ca554e01c854788dbae6e2409c78d282) @@ -504,9 +504,270 @@ mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } + [Test] + public void Import_CancelOfImportWithCharacteristicPointsAfterSurfaceLinesRead_CancelImportAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "TwoValidSurfaceLines.csv"); + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importer = new PipingSurfaceLinesCsvImporter(); + + // Precondition + CollectionAssert.IsEmpty(observableSurfaceLinesList); + Assert.IsTrue(File.Exists(validFilePath)); + + importer.Cancel(); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, validFilePath); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, ApplicationResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled, 1); + Assert.IsFalse(importResult); + CollectionAssert.IsEmpty(observableSurfaceLinesList); + + mocks.VerifyAll(); // 'observer' should not be notified + } + [Test] + public void Import_CharacteristicPointsFileDoesNotExist_Log() + { + // Setup + string surfaceLineFile = Path.Combine(testDataPath, "TwoValidSurfaceLines.csv"); + string nonExistingCharacteristicFile = Path.Combine(testDataPath, "TwoValidSurfaceLines.krp.csv"); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var importer = new PipingSurfaceLinesCsvImporter(); + + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importResult = true; + + // Precondition + Assert.IsTrue(File.Exists(surfaceLineFile)); + Assert.IsFalse(File.Exists(nonExistingCharacteristicFile)); + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, surfaceLineFile); + + // Assert + var expectedLogMessage = string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_Import_No_characteristic_points_file_for_surface_line_file_expecting_file_0_, + nonExistingCharacteristicFile); + TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); + Assert.IsTrue(importResult); + Assert.AreEqual(2, observableSurfaceLinesList.Count); + mocks.VerifyAll(); // Expect no calls on 'observer' + } + + [Test] + public void Import_CharacteristicPointsFileIsEmpty_AbortImportAndLog() + { + // Setup + string surfaceLineFile = Path.Combine(testDataPath, "TwoValidSurfaceLines_EmptyCharacteristicPoints.csv"); + string corruptPath = Path.Combine(testDataPath, "TwoValidSurfaceLines_EmptyCharacteristicPoints.krp.csv"); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var importer = new PipingSurfaceLinesCsvImporter(); + + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, surfaceLineFile); + + // Assert + var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) + .WithLocation("op regel 1") + .Build(UtilsResources.Error_File_empty); + + var expectedLogMessages = new[] + { + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_, + corruptPath), + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + internalErrorMessage) + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); + Assert.IsFalse(importResult); + CollectionAssert.IsEmpty(observableSurfaceLinesList, + "No items should be added to collection when import is aborted."); + mocks.VerifyAll(); // Expect no calls on 'observer' + } + + [Test] + public void Import_CharacteristicPointsFileHasInvalidHeader_AbortImportAndLog() + { + // Setup + string surfaceLineFile = Path.Combine(testDataPath, "TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.csv"); + string corruptPath = Path.Combine(testDataPath, "TwoValidSurfaceLines_InvalidHaderCharacteristicPoints.krp.csv"); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var importer = new PipingSurfaceLinesCsvImporter(); + + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, surfaceLineFile); + + // Assert + var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) + .WithLocation("op regel 1") + .Build(PipingIOResources.PipingCharacteristicPointsCsvReader_File_invalid_header); + + var expectedLogMessages = new[] + { + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_, + corruptPath), + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + internalErrorMessage) + }; + + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); + Assert.IsFalse(importResult); + CollectionAssert.IsEmpty(observableSurfaceLinesList, + "No items should be added to collection when import is aborted."); + mocks.VerifyAll(); // Expect no calls on 'observer' + } + + [Test] + public void Import_CharacteristicPointsFileDeletedDuringRead_AbortImportAndLog() + { + // Setup + var copyTargetPath = "Import_FileDeletedDuringRead_AbortImportAndLog.csv"; + var copyCharacteristicPointsTargetPath = "Import_FileDeletedDuringRead_AbortImportAndLog.krp.csv"; + string surfaceLines = Path.Combine(testDataPath, "TwoValidSurfaceLines_WithCharacteristicPoints.csv"); + string validFilePath = Path.Combine(testDataPath, "TwoValidSurfaceLines_WithCharacteristicPoints.krp.csv"); + File.Copy(surfaceLines, copyTargetPath); + File.Copy(validFilePath, copyCharacteristicPointsTargetPath); + + try + { + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var importer = new PipingSurfaceLinesCsvImporter(); + importer.ProgressChanged += (name, step, steps) => + { + // Delete the file being read by the import during the import itself: + if (name == string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_Read_PipingCharacteristicPoints_0_, + copyCharacteristicPointsTargetPath)) + { + File.Delete(copyCharacteristicPointsTargetPath); + } + }; + + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, copyTargetPath); + + // Assert + var internalErrorMessage = new FileReaderErrorMessageBuilder(copyCharacteristicPointsTargetPath).Build(UtilsResources.Error_File_does_not_exist); + var expectedLogMessages = new[] + { + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_, + copyCharacteristicPointsTargetPath), + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + internalErrorMessage) + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); + Assert.IsFalse(importResult); + CollectionAssert.IsEmpty(observableSurfaceLinesList, + "No items should be added to collection when import is aborted."); + mocks.VerifyAll(); // Expect no calls on 'observer' + } + finally + { + // Fallback delete in case progress event is not fired: + if (File.Exists(copyTargetPath)) + { + File.Delete(copyTargetPath); + } + // Fallback delete in case progress event is not fired: + if (File.Exists(copyCharacteristicPointsTargetPath)) + { + File.Delete(copyCharacteristicPointsTargetPath); + } + } + } + + [Test] + public void Import_FileWithTwoValidLinesAndOneInvalidCharacteristicPointsDefinitionDueToUnparsableNumber_SkipInvalidRowAndLog() + { + // Setup + string surfaceLines = Path.Combine(testDataPath, "TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.csv"); + string corruptPath = Path.Combine(testDataPath, "TwoValidSurfaceLines_WithOneInvalidCharacteristicPoints.krp.csv"); + + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var importer = new PipingSurfaceLinesCsvImporter(); + int progressCallCount = 0; + importer.ProgressChanged += (name, step, steps) => { progressCallCount++; }; + + var observableSurfaceLinesList = new ObservableList(); + observableSurfaceLinesList.Attach(observer); + + var importResult = false; + + // Call + Action call = () => importResult = importer.Import(observableSurfaceLinesList, surfaceLines); + + // Assert + var internalErrorMessage = new FileReaderErrorMessageBuilder(corruptPath) + .WithLocation("op regel 2") + .WithSubject("locatie 'Rotterdam1Invalid'") + .Build(PipingIOResources.Error_CharacteristicPoint_has_not_double); + var expectedLogMessages = new[] + { + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_Start_reading_characteristic_points_from_file_0_, + corruptPath), + string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadCharacteristicPoints_ParseErrorMessage_0_CharacteristicPoints_skipped, + internalErrorMessage) + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 3); + Assert.IsTrue(importResult); + + Assert.AreEqual(2, observableSurfaceLinesList.Count, + "Ensure only the two valid surfacelines have been imported."); + Assert.AreEqual(1, observableSurfaceLinesList.Count(sl => sl.Name == "Rotterdam1Invalid")); + Assert.AreEqual(1, observableSurfaceLinesList.Count(sl => sl.Name == "ArtifcialLocal")); + + Assert.AreEqual(7, progressCallCount, + "Expect 1 call for each surfaceline (2 in total) +1 for 0/N progress and for each characteristic point location (2 in total) +1 for 0/N progress, and 1 for putting data in model."); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver + } + + [Test] public void Import_ImportingToValidTargetWithValidFileWithCharacteristicPoints_ImportSurfaceLinesToCollection() { // Setup