Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs =================================================================== diff -u -r3485eb4a889b222fb4ee148d38b7916e96034482 -re2e1d9ca600ee1370b26d091469cca85142e10e2 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs (.../HydraulicLocationConfigurationDatabaseImporter.cs) (revision 3485eb4a889b222fb4ee148d38b7916e96034482) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Importers/HydraulicLocationConfigurationDatabaseImporter.cs (.../HydraulicLocationConfigurationDatabaseImporter.cs) (revision e2e1d9ca600ee1370b26d091469cca85142e10e2) @@ -20,9 +20,12 @@ // All rights reserved. using System; +using System.IO; using Core.Common.Base.IO; +using Core.Common.Util.Builders; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Integration.IO.Handlers; +using Ringtoets.Integration.IO.Properties; namespace Ringtoets.Integration.IO.Importers { @@ -31,6 +34,8 @@ /// public class HydraulicLocationConfigurationDatabaseImporter : FileImporterBase { + private readonly HydraulicBoundaryDatabase hydraulicBoundaryDatabase; + /// /// Creates a new instance of . /// @@ -54,16 +59,31 @@ { throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); } + + this.hydraulicBoundaryDatabase = hydraulicBoundaryDatabase; } protected override bool OnImport() { - throw new NotImplementedException(); + if (Path.GetDirectoryName(FilePath) != Path.GetDirectoryName(hydraulicBoundaryDatabase.FilePath)) + { + Log.Error(BuildErrorMessage(FilePath, Resources.HydraulicLocationConfigurationDatabaseImporter_HLCD_not_in_same_folder_as_HRD)); + return false; + } + + return true; } protected override void LogImportCanceledMessage() { throw new NotImplementedException(); } + + private static string BuildErrorMessage(string filePath, string message) + { + return new FileReaderErrorMessageBuilder(filePath).Build( + string.Format(Resources.HydraulicLocationConfigurationDatabaseImporter_HandleCriticalFileReadError_Error_0_No_HydraulicLocationConfigurationDatabase_imported, + message)); + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rb721e00f6b458f5ccc39b7b4dfb4a67e7c89e28f -re2e1d9ca600ee1370b26d091469cca85142e10e2 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b721e00f6b458f5ccc39b7b4dfb4a67e7c89e28f) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision e2e1d9ca600ee1370b26d091469cca85142e10e2) @@ -187,6 +187,26 @@ } /// + /// Looks up a localized string similar to {0} + ///Er is geen HLCD geïmporteerd.. + /// + internal static string HydraulicLocationConfigurationDatabaseImporter_HandleCriticalFileReadError_Error_0_No_HydraulicLocationConfigurationDatabase_imported { + get { + return ResourceManager.GetString("HydraulicLocationConfigurationDatabaseImporter_HandleCriticalFileReadError_Error_" + + "0_No_HydraulicLocationConfigurationDatabase_imported", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het HLCD bestand is niet gevonden in dezelfde map als het HRD bestand.. + /// + internal static string HydraulicLocationConfigurationDatabaseImporter_HLCD_not_in_same_folder_as_HRD { + get { + return ResourceManager.GetString("HydraulicLocationConfigurationDatabaseImporter_HLCD_not_in_same_folder_as_HRD", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Assemblage. /// internal static string SerializableAssembly_IdPrefix { Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.resx =================================================================== diff -u -rb721e00f6b458f5ccc39b7b4dfb4a67e7c89e28f -re2e1d9ca600ee1370b26d091469cca85142e10e2 --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.resx (.../Resources.resx) (revision b721e00f6b458f5ccc39b7b4dfb4a67e7c89e28f) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Properties/Resources.resx (.../Resources.resx) (revision e2e1d9ca600ee1370b26d091469cca85142e10e2) @@ -178,4 +178,11 @@ De tabel 'ScenarioInformation' in het HLCD bestand moet exact 1 rij bevatten. + + {0} +Er is geen HLCD geïmporteerd. + + + Het HLCD bestand is niet gevonden in dezelfde map als het HRD bestand. + \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs =================================================================== diff -u -r3485eb4a889b222fb4ee148d38b7916e96034482 -re2e1d9ca600ee1370b26d091469cca85142e10e2 --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs (.../HydraulicLocationConfigurationDatabaseImporterTest.cs) (revision 3485eb4a889b222fb4ee148d38b7916e96034482) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Importers/HydraulicLocationConfigurationDatabaseImporterTest.cs (.../HydraulicLocationConfigurationDatabaseImporterTest.cs) (revision e2e1d9ca600ee1370b26d091469cca85142e10e2) @@ -20,7 +20,9 @@ // All rights reserved. using System; +using System.IO; using Core.Common.Base.IO; +using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Hydraulics; @@ -32,6 +34,9 @@ [TestFixture] public class HydraulicLocationConfigurationDatabaseImporterTest { + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.IO, + nameof(HydraulicLocationConfigurationDatabaseImporter)); + [Test] public void Constructor_UpdateHandlerNull_ThrowsArgumentNullException() { @@ -76,5 +81,42 @@ Assert.IsInstanceOf>(importer); mocks.VerifyAll(); } + + [Test] + public void Import_FilePathIsDifferentFromHydraulicBoundaryDatabasesFilePath_CancelImportWithErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.StrictMock(); + mocks.ReplayAll(); + + string hydraulicBoundaryDatabasePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.IO, + nameof(HydraulicBoundaryDatabaseImporter)), "complete.sqlite"); + string path = Path.Combine(testDataPath, "hlcd.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = hydraulicBoundaryDatabasePath + }; + + var importer = new HydraulicLocationConfigurationDatabaseImporter(new HydraulicLocationConfigurationSettings(), handler, hydraulicBoundaryDatabase, path); + + // Call + var importSuccessful = true; + Action call = () => importSuccessful = importer.Import(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{path}': het HLCD bestand is niet gevonden in dezelfde map als het HRD bestand."; + AssertImportFailed(call, expectedMessage, ref importSuccessful); + mocks.VerifyAll(); + } + + private static void AssertImportFailed(Action call, string errorMessage, ref bool importSuccessful) + { + string expectedMessage = $"{errorMessage}" + + $"{Environment.NewLine}Er is geen HLCD geïmporteerd."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple(expectedMessage, LogLevelConstant.Error), 1); + Assert.IsFalse(importSuccessful); + } } } \ No newline at end of file