Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r7fcfd2a51296e34e31b995e741e16da362ed745c --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision 7fcfd2a51296e34e31b995e741e16da362ed745c) @@ -222,7 +222,8 @@ } if (profileLocations.Any(dpl => dpl.Id.Equals(profileLocation.Id))) { - Log.WarnFormat(Resources.ProfilesImporter_AddNextProfileLocation_Location_with_id_0_already_read, profileLocation.Id); + string message = string.Format(Resources.ProfilesImporter_AddNextProfileLocation_Location_with_id_0_already_read, profileLocation.Id); + throw new CriticalFileReadException(message); } profileLocations.Add(profileLocation); } @@ -268,38 +269,33 @@ if (dikeProfileData.Any(d => d.Id.Equals(data.Id))) { - LogDuplicate(data, prflFilePath); + string errorMessage = string.Format( + Resources.ProfilesImporter_LogDuplicateDikeProfileData_Multiple_DikeProfileData_found_for_DikeProfile_0_File_1_skipped, + data.Id, + prflFilePath); + throw new CriticalFileReadException(errorMessage); } - else - { - dikeProfileData.Add(data); - } + + dikeProfileData.Add(data); } // No need to catch ArgumentException, as prflFilePaths are valid by construction. catch (CriticalFileReadException exception) { Log.Error(exception.Message); - errorOccured = true; + return new ReadResult(true); } catch (CriticalFileValidationException) { // Ignore file } } - return errorOccured && !dikeProfileData.Any() - ? new ReadResult(true) - : new ReadResult(false) - { - Items = dikeProfileData - }; + return new ReadResult(false) + { + Items = dikeProfileData + }; } - private void LogDuplicate(DikeProfileData data, string prflFilePath) - { - Log.WarnFormat(Resources.ProfilesImporter_LogDuplicateDikeProfileData_Multiple_DikeProfileData_found_for_DikeProfile_0_File_1_skipped, data.Id, prflFilePath); - } - private double GetDistanceToReferenceLine(Point2D point) { return GetLineSegments(referenceLine.Points).Min(segment => segment.GetEuclideanDistanceToPoint(point)); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r7fcfd2a51296e34e31b995e741e16da362ed745c --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision 7fcfd2a51296e34e31b995e741e16da362ed745c) @@ -424,8 +424,9 @@ var messageProvider = mocks.Stub(); mocks.ReplayAll(); - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, - Path.Combine("DikeProfiles", "InvalidDamType", "Voorlanden 12-2.shp")); + string testFileDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, + Path.Combine("DikeProfiles", "InvalidDamType")); + string filePath = Path.Combine(testFileDirectory, "Voorlanden 12-2.shp"); ReferenceLine referenceLine = CreateMatchingReferenceLine(); var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath, messageProvider); @@ -435,13 +436,10 @@ Action call = () => importResult = testProfilesImporter.Import(); // Assert - Action> asserts = messages => - { - bool found = messages.Any(message => message.EndsWith(": het ingelezen damtype ('4') moet 0, 1, 2 of 3 zijn.")); - Assert.IsTrue(found); - }; - TestHelper.AssertLogMessages(call, asserts); - Assert.IsTrue(importResult); + string erroneousProfileFile = Path.Combine(testFileDirectory, "profiel005 - Ringtoets.prfl"); + string expectedMessage = $"Fout bij het lezen van bestand '{erroneousProfileFile}' op regel 6: het ingelezen damtype ('4') moet 0, 1, 2 of 3 zijn."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1); + Assert.IsFalse(importResult); } [Test] @@ -451,8 +449,9 @@ var messageProvider = mocks.Stub(); mocks.ReplayAll(); - string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, - Path.Combine("DikeProfiles", "TwoPrflWithSameId", "profiel001.shp")); + string testFileDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin, + Path.Combine("DikeProfiles", "TwoPrflWithSameId")); + string filePath = Path.Combine(testFileDirectory, "profiel001.shp"); var referencePoints = new List { @@ -468,19 +467,14 @@ Action call = () => importResult = testProfilesImporter.Import(); // Assert - Action> asserts = messages => - { - const string start = "Meerdere definities gevonden voor profiel 'profiel001'. Bestand '"; - const string end = "' wordt overgeslagen."; - bool found = messages.Any(m => m.StartsWith(start) && m.EndsWith(end)); - Assert.IsTrue(found); - }; - TestHelper.AssertLogMessages(call, asserts); - Assert.IsTrue(importResult); + string erroneousProfileFile = Path.Combine(testFileDirectory, "profiel001_2.prfl"); + string expectedMessage = $"Meerdere definities gevonden voor profiel 'profiel001'. Bestand '{erroneousProfileFile}' wordt overgeslagen."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1); + Assert.IsFalse(importResult); } [Test] - public void Import_FromFileWithDupplicateId_TrueAndLogWarnings() + public void Import_FromFileWithDuplicateId_FalseAndLogErrors() { // Setup var messageProvider = mocks.Stub(); @@ -497,18 +491,13 @@ Action call = () => importResult = testProfilesImporter.Import(); // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] messageArray = messages.ToArray(); - const string expectedMessage = "Profiellocatie met ID 'profiel001' is opnieuw ingelezen."; - Assert.AreEqual(expectedMessage, messageArray[0]); - Assert.AreEqual(expectedMessage, messageArray[1]); - }); - Assert.IsTrue(importResult); + const string expectedMessage = "Profiellocatie met ID 'profiel001' is opnieuw ingelezen."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1); + Assert.IsFalse(importResult); } [Test] - public void Import_PrflWithProfileNotZero_TrueAndErrorLog() + public void Import_PrflWithProfileNotZero_FalseAndErrorLog() { // Setup var messageProvider = mocks.Stub();