Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs =================================================================== diff -u -r24396275ce37cc1519c2df4d41e390bd8d0103bb -r43aaedc15ee45c14645d300e75953bf550ab5ed4 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs (.../HydraulicLocationConfigurationDatabaseImporter.cs) (revision 24396275ce37cc1519c2df4d41e390bd8d0103bb) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs (.../HydraulicLocationConfigurationDatabaseImporter.cs) (revision 43aaedc15ee45c14645d300e75953bf550ab5ed4) @@ -27,6 +27,7 @@ using Core.Common.IO.Readers; using Core.Common.Util.Builders; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; using Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabase; using Ringtoets.Integration.IO.Handlers; using Ringtoets.Integration.IO.Properties; @@ -75,8 +76,15 @@ return false; } + ReadResult readTrackIdResult = ReadTrackId(); + + if (readTrackIdResult.CriticalErrorOccurred) + { + return false; + } + ReadResult readHydraulicLocationConfigurationDatabaseResult = ReadHydraulicLocationConfigurationDatabase( - hydraulicBoundaryDatabase.TrackId); + readTrackIdResult.Items.Single()); if (readHydraulicLocationConfigurationDatabaseResult.CriticalErrorOccurred) { @@ -99,6 +107,27 @@ throw new NotImplementedException(); } + private ReadResult ReadTrackId() + { + try + { + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabase.FilePath)) + { + return new ReadResult(false) + { + Items = new[] + { + reader.ReadTrackId() + } + }; + } + } + catch (Exception e) when (e is CriticalFileReadException || e is LineParseException) + { + return HandleCriticalFileReadError(e); + } + } + private ReadResult ReadHydraulicLocationConfigurationDatabase(long trackId) { try Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs =================================================================== diff -u -r7f9914406799f37e7969a4c0061693772788d0ec -r43aaedc15ee45c14645d300e75953bf550ab5ed4 --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs (.../HydraulicLocationConfigurationDatabaseImporterTest.cs) (revision 7f9914406799f37e7969a4c0061693772788d0ec) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs (.../HydraulicLocationConfigurationDatabaseImporterTest.cs) (revision 43aaedc15ee45c14645d300e75953bf550ab5ed4) @@ -37,6 +37,8 @@ private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.IO, nameof(HydraulicLocationConfigurationDatabaseImporter)); + private readonly string validHrdFilePath = Path.Combine(testDataPath, "completeHrd.sqlite"); + [Test] public void Constructor_UpdateHandlerNull_ThrowsArgumentNullException() { @@ -110,8 +112,64 @@ AssertImportFailed(call, expectedMessage, ref importSuccessful); mocks.VerifyAll(); } + + [Test] + public void Import_HrdInvalidSchema_CancelImportWithErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.StrictMock(); + mocks.ReplayAll(); + string path = Path.Combine(testDataPath, "CorruptHrd"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = Path.Combine(path, "corruptschema.sqlite") + }; + + var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, + hydraulicBoundaryDatabase, Path.Combine(path, "HLCD.sqlite")); + + // Call + var importSuccessful = true; + Action call = () => importSuccessful = importer.Import(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabase.FilePath}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + AssertImportFailed(call, expectedMessage, ref importSuccessful); + mocks.VerifyAll(); + } + [Test] + public void Import_HrdEmptySchema_CancelImportWithErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.StrictMock(); + mocks.ReplayAll(); + + string path = Path.Combine(testDataPath, "EmptyHrd"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = Path.Combine(path, "empty.sqlite") + }; + + var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, + hydraulicBoundaryDatabase, Path.Combine(path, "HLCD.sqlite")); + + // Call + var importSuccessful = true; + Action call = () => importSuccessful = importer.Import(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabase.FilePath}': kon geen locaties verkrijgen van de database."; + AssertImportFailed(call, expectedMessage, ref importSuccessful); + mocks.VerifyAll(); + } + + [Test] public void Import_EmptySchema_CancelImportWithErrorMessage() { // Setup @@ -123,7 +181,7 @@ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - FilePath = path + FilePath = validHrdFilePath }; var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); @@ -150,8 +208,7 @@ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - FilePath = path, - TrackId = 13 + FilePath = validHrdFilePath }; var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); @@ -180,8 +237,7 @@ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - FilePath = path, - TrackId = 13 + FilePath = validHrdFilePath }; var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/CorruptHrd/HLCD.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/CorruptHrd/corruptschema.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/EmptyHrd/HLCD.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/EmptyHrd/empty.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/HLCD.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/test-data/HydraulicLocationConfigurationDatabaseImporter/completeHrd.sqlite =================================================================== diff -u Binary files differ