Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -711,6 +711,15 @@ } /// + /// Looks up a localized string similar to Valideren van ingelezen data.. + /// + public static string Importer_ProgressText_Validating_imported_data { + get { + return ResourceManager.GetString("Importer_ProgressText_Validating_imported_data", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kon geen punten vinden in dit bestand.. /// public static string PointShapefileReader_File_can_only_contain_points { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -510,4 +510,7 @@ Bijwerken data in het toetsspoor. + + Valideren van ingelezen data. + \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/StochasticSoilModelImporter.cs (.../StochasticSoilModelImporter.cs) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -102,8 +102,15 @@ return false; } - UpdatedInstances = modelUpdateStrategy.UpdateModelWithImportedData(ImportTarget, GetValidStochasticSoilModels(importStochasticSoilModelResult), FilePath); + StochasticSoilModel[] validStochasticSoilModels = GetValidStochasticSoilModels(importStochasticSoilModelResult).ToArray(); + if (Canceled) + { + return false; + } + NotifyProgress(messageProvider.GetAddDataToModelProgressText(), 1, 1); + UpdatedInstances = modelUpdateStrategy.UpdateModelWithImportedData(ImportTarget, validStochasticSoilModels, FilePath); + return true; } @@ -147,10 +154,14 @@ { var currentStep = 1; StochasticSoilModel[] importedModels = importStochasticSoilModelResult.Items.ToArray(); - string addDataToModelProgressText = messageProvider.GetAddDataToModelProgressText(); foreach (StochasticSoilModel importedModel in importedModels) { - NotifyProgress(addDataToModelProgressText, currentStep, importedModels.Length); + NotifyProgress(RingtoestCommonIOResources.Importer_ProgressText_Validating_imported_data, currentStep, importedModels.Length); + if (Canceled) + { + yield break; + } + if (ValidateStochasticSoilModel(importedModel)) { yield return importedModel; Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -111,13 +111,14 @@ return false; } - RingtoetsPipingSurfaceLine[] importResults = ProcessImportedDataToModel(importSurfaceLinesResult.Items, + RingtoetsPipingSurfaceLine[] importResults = GetProcessedImportedData(importSurfaceLinesResult.Items, importCharacteristicPointsResult.Items).ToArray(); if (Canceled) { return false; } + NotifyProgress(messageProvider.GetAddDataToModelProgressText(), 1, 1); UpdatedInstances = surfaceLineUpdateStrategy.UpdateSurfaceLinesWithImportedData(ImportTarget, importResults, FilePath); return true; } @@ -144,10 +145,10 @@ return new ReadResult(true); } - private IEnumerable ProcessImportedDataToModel(ICollection readSurfaceLines, + private IEnumerable GetProcessedImportedData(ICollection readSurfaceLines, ICollection readCharacteristicPointsLocations) { - string progressText = messageProvider.GetAddDataToModelProgressText(); + string progressText = RingtoetsCommonIOResources.Importer_ProgressText_Validating_imported_data; NotifyProgress(progressText, 0, readSurfaceLines.Count); List readCharacteristicPointsLocationNames = readCharacteristicPointsLocations.Select(cpl => cpl.Name).ToList(); Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/StochasticSoilModelImporterTest.cs =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/StochasticSoilModelImporterTest.cs (.../StochasticSoilModelImporterTest.cs) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/StochasticSoilModelImporterTest.cs (.../StochasticSoilModelImporterTest.cs) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -251,8 +251,9 @@ expectedProgressMessages.Add(new ProgressNotification("Controleren van ondergrondschematisaties.", 1, 1)); for (var i = 1; i <= expectedModels; i++) { - expectedProgressMessages.Add(new ProgressNotification(expectedAddDataText, i, expectedModels)); + expectedProgressMessages.Add(new ProgressNotification("Valideren van ingelezen data.", i, expectedModels)); } + expectedProgressMessages.Add(new ProgressNotification(expectedAddDataText, 1, 1)); Assert.AreEqual(expectedProgressMessages.Count, progressChangeNotifications.Count); for (var i = 0; i < expectedProgressMessages.Count; i++) { @@ -290,7 +291,7 @@ // Assert TestHelper.AssertLogMessagesCount(call, 0); - Assert.AreEqual(35 * 2, progress); + Assert.AreEqual(36 * 2, progress); StochasticSoilModel[] readModels = AssertSuccessfulImport(validFilePath, importResult, updateStrategy); Assert.AreEqual(3, readModels.Length); @@ -399,6 +400,40 @@ } [Test] + public void Import_CancelOfImportWhenValidatingStochasticSoilModels_CancelsImportAndLogs() + { + // Setup + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + + string validFilePath = Path.Combine(testDataPath, "complete.soil"); + + var failureMechanism = new PipingFailureMechanism(); + var updateStrategy = new TestStochasticSoilModelUpdateModelStrategy(); + var importer = new StochasticSoilModelImporter( + failureMechanism.StochasticSoilModels, + validFilePath, + messageProvider, + updateStrategy); + importer.SetProgressChanged((description, step, steps) => + { + if (description.Contains("Valideren van ingelezen data.")) + { + importer.Cancel(); + } + }); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "Stochastische ondergrondmodellen importeren afgebroken. Geen data ingelezen.", 1); + AssertUnsuccessfulImport(importResult, updateStrategy); + } + + [Test] public void Import_CancelOfImportWhenAddingDataToModel_ImportCompletedSuccessfullyNonetheless() { // Setup @@ -500,7 +535,7 @@ "Het stochastische ondergrondmodel \'Name\' heeft een ongespecificeerde ondergrondschematisatie. Dit model wordt overgeslagen." }; TestHelper.AssertLogMessagesAreGenerated(call, expectedLogMessages, 2); - Assert.AreEqual(7, progress); + Assert.AreEqual(8, progress); StochasticSoilModel[] readModels = AssertSuccessfulImport(pathToCorruptFile, importResult, updateStrategy); CollectionAssert.IsEmpty(readModels); @@ -831,7 +866,7 @@ CollectionAssert.AreEqual(Enumerable.Repeat(double.NaN, expectedNumberOfLayers), profile.Layers.Select(l => l.BelowPhreaticLevelMean)); - Assert.AreEqual(6, progress); + Assert.AreEqual(7, progress); } [Test] @@ -913,7 +948,7 @@ CollectionAssert.AreEqual(expectedBelowPhreaticLevelValues, profile.Layers.Select(l => l.BelowPhreaticLevelMean)); - Assert.AreEqual(6, progress); + Assert.AreEqual(7, progress); } [Test] Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs =================================================================== diff -u -r2ab087c5f7b254eb7ea6d167b122afaea10b0ff6 -r7be65c58634423d5f4e0fb5272158c716d9d3753 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 2ab087c5f7b254eb7ea6d167b122afaea10b0ff6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 7be65c58634423d5f4e0fb5272158c716d9d3753) @@ -218,14 +218,18 @@ } else if (callCount <= expectedNumberOfSurfaceLines + 1 + expectedNumberOfSurfaceLines) { + Assert.AreEqual("Valideren van ingelezen data.", currentStepName); + Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); + } + else if (callCount <= expectedNumberOfSurfaceLines + expectedNumberOfSurfaceLines + 2) + { Assert.AreEqual(expectedAddDataToModelProgressText, currentStepName); } else { Assert.Fail("Not expecting progress: \"{0}: {1} out of {2}\".", currentStepName, currentStep, totalNumberOfSteps); } - Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); callCount++; }); @@ -252,7 +256,7 @@ Assert.AreEqual(5.7, secondSurfaceLine.EndingWorldPoint.X); AssertAreEqualPoint2D(new Point2D(3.3, 0), secondSurfaceLine.ReferenceLineIntersectionWorldPoint); - Assert.AreEqual(6, callCount); + Assert.AreEqual(7, callCount); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); } @@ -390,12 +394,10 @@ } [Test] - public void Import_CancelOfImportDuringAddingDataToModel_CancelsImportAndLogs() + public void Import_CancelOfImportDuringProcessImportDataToModel_CancelsImportAndLogs() { // Setup - const string expectedAddDataToModelProgressText = "Adding data"; - var messageProvider = mocks.StrictMock(); - messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText); + var messageProvider = mocks.Stub(); mocks.ReplayAll(); string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); @@ -415,7 +417,7 @@ importer.SetProgressChanged((description, step, steps) => { if (step < steps - && description.Contains(expectedAddDataToModelProgressText)) + && description.Contains("Valideren van ingelezen data.")) { importer.Cancel(); } @@ -436,6 +438,52 @@ } [Test] + public void Import_CancelOfImportWhenAddingDataToModel_ImportCompletedSuccessfullyNonetheless() + { + // Setup + const string expectedAddDataToModelProgressText = "Adding data"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText); + mocks.ReplayAll(); + + const int expectedNumberOfSurfaceLines = 2; + string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv"); + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(3.3, -1), + new Point2D(3.3, 1), + new Point2D(94270, 427775.65), + new Point2D(94270, 427812.08) + }); + + var failureMechanism = new PipingFailureMechanism(); + var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); + var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath, messageProvider, surfaceLineUpdateStrategy); + importer.SetProgressChanged((description, step, steps) => + { + if (description.Contains(expectedAddDataToModelProgressText)) + { + importer.Cancel(); + } + }); + + // Precondition + CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); + Assert.IsTrue(File.Exists(validFilePath)); + + bool importResult = false; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 4); + AssertSuccessfulImport(importResult, expectedNumberOfSurfaceLines, validFilePath, surfaceLineUpdateStrategy); + } + + [Test] public void Import_ReuseOfCanceledImportToValidTargetWithValidFile_ImportSurfaceLinesToCollection() { // Setup @@ -759,16 +807,17 @@ Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "Rotterdam1")); Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - Assert.AreEqual(9, progressCallCount, + Assert.AreEqual(10, progressCallCount, new StringBuilder() .AppendLine("Expected number of calls:") .AppendLine("1 : Start reading surface lines file.") .AppendLine("4 : 1 call for each read surface line, +1 for index 0.") .AppendLine("1 : Start reading characteristic points file.") + .AppendLine("1 : 1 call to process the imported surface lines.") .AppendLine("1 : Start adding data to failure mechanism.") .AppendLine("2 : 1 call for each valid surfaceline checked against reference line.") .AppendLine("-- +") - .AppendLine("9") + .AppendLine("10") .ToString()); } @@ -1174,17 +1223,18 @@ Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - Assert.AreEqual(11, progressCallCount, + Assert.AreEqual(12, progressCallCount, new StringBuilder() .AppendLine("Expected number of calls:") .AppendLine("1 : Start reading surface lines file.") .AppendLine("3 : 1 call for each read surface line, +1 for index 0.") .AppendLine("1 : Start reading characteristic points file.") .AppendLine("3 : 1 call for each set of characteristic points for a locations being read, +1 for index 0.") + .AppendLine("1 : 1 call to process the imported surface lines.") .AppendLine("1 : Start adding data to failure mechanism.") .AppendLine("2 : 1 call for each surfaceline checked against reference line.") .AppendLine("-- +") - .AppendLine("11") + .AppendLine("12") .ToString()); } @@ -1240,17 +1290,18 @@ Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "Rotterdam1")); Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - Assert.AreEqual(10, progressCallCount, + Assert.AreEqual(11, progressCallCount, new StringBuilder() .AppendLine("Expected number of calls:") .AppendLine("1 : Start reading surface lines file.") .AppendLine("3 : 1 call for each read surface line, +1 for index 0.") .AppendLine("1 : Start reading characteristic points file.") .AppendLine("2 : 1 call for each set of characteristic points for a locations being read, +1 for index 0.") + .AppendLine("1 : 1 call to process the imported surface lines.") .AppendLine("1 : Start adding data to failure mechanism.") .AppendLine("2 : 1 call for each surfaceline checked against reference line.") .AppendLine("-- +") - .AppendLine("10") + .AppendLine("11") .ToString()); } @@ -1306,17 +1357,18 @@ Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "Rotterdam1")); Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - Assert.AreEqual(12, progressCallCount, + Assert.AreEqual(13, progressCallCount, new StringBuilder() .AppendLine("Expected number of calls:") .AppendLine("1 : Start reading surface lines file.") .AppendLine("3 : 1 call for each read surface line, +1 for index 0.") .AppendLine("1 : Start reading characteristic points file.") .AppendLine("4 : 1 call for each set of characteristic points for a locations being read, +1 for index 0.") + .AppendLine("1 : 1 call to process the imported surface lines.") .AppendLine("1 : Start adding data to failure mechanism.") .AppendLine("2 : 1 call for each surfaceline checked against reference line.") .AppendLine("-- +") - .AppendLine("12") + .AppendLine("13") .ToString()); } @@ -1381,17 +1433,18 @@ Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "Rotterdam1Invalid")); Assert.AreEqual(1, importedSurfaceLines.Count(sl => sl.Name == "ArtifcialLocal")); - Assert.AreEqual(11, progressCallCount, + Assert.AreEqual(12, progressCallCount, new StringBuilder() .AppendLine("Expected number of calls:") .AppendLine("1 : Start reading surface lines file.") .AppendLine("3 : 1 call for each read surface line, +1 for index 0.") .AppendLine("1 : Start reading characteristic points file.") .AppendLine("3 : 1 call for each set of characteristic points for a locations being read, +1 for index 0.") + .AppendLine("1 : 1 call to process the imported surface lines.") .AppendLine("1 : Start adding data to failure mechanism.") .AppendLine("2 : 1 call for each surfaceline checked against reference line.") .AppendLine("-- +") - .AppendLine("11") + .AppendLine("12") .ToString()); } @@ -1456,14 +1509,18 @@ } else if (callCount <= expectedNumberOfSurfaceLines + expectedNumberOfCharacteristicPointsDefinitions + 2 + expectedNumberOfSurfaceLines) { + Assert.AreEqual("Valideren van ingelezen data.", currentStepName); + Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); + } + else if (callCount <= expectedNumberOfSurfaceLines + expectedNumberOfCharacteristicPointsDefinitions + 2 + expectedNumberOfSurfaceLines + 1) + { Assert.AreEqual(expectedAddDataToModelProgressText, currentStepName); } else { Assert.Fail("Not expecting progress: \"{0}: {1} out of {2}\".", currentStepName, currentStep, totalNumberOfSteps); } - Assert.AreEqual(expectedNumberOfSurfaceLines, totalNumberOfSteps); callCount++; }); @@ -1501,7 +1558,7 @@ Assert.AreEqual(new Point3D(2.3, 0, 1.0), secondSurfaceLine.DikeToeAtRiver); Assert.AreEqual(new Point3D(5.7, 0, 1.1), secondSurfaceLine.DikeToeAtPolder); - Assert.AreEqual(9, callCount); + Assert.AreEqual(10, callCount); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validSurfaceLinesFilePath)); Assert.IsTrue(TestHelper.CanOpenFileForWrite(validCharacteristicPointsFilePath));