Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs =================================================================== diff -u -rfc22f4b149d07797f0526f04ca58595bb9446786 -ra77cd7f471b813c6a7218b42844d017fc10fb4ec --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision fc22f4b149d07797f0526f04ca58595bb9446786) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision a77cd7f471b813c6a7218b42844d017fc10fb4ec) @@ -23,21 +23,16 @@ using System.Collections.Generic; using System.IO; using System.Linq; - using Core.Common.Base; using Core.Common.IO.Exceptions; using Core.Common.TestUtil; - +using Core.Common.Utils.Builders; using NUnit.Framework; - using Rhino.Mocks; - using Ringtoets.Common.Data; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin.FileImporters; - using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -115,6 +110,21 @@ } [Test] + public void ValidateAndConnectTo_ExistingFileWithoutHlcd_ThrowCriticalFileReadException() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "withoutHLCD", "empty.sqlite"); + string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath).Build("Het bijbehorende HLCD bestand is niet gevonden in de folder."); + + // Call + TestDelegate test = () => importer.ValidateAndConnectTo(validFilePath); + + // Assert + CriticalFileReadException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] public void GetHydraulicBoundaryDatabaseVersion_ValidFile_GetDatabaseVersion() { // Setup @@ -146,6 +156,7 @@ // Assert var exception = Assert.Throws(call); Assert.AreEqual(expectedMessage, exception.Message); + mocks.VerifyAll(); } [Test] @@ -180,6 +191,7 @@ Assert.AreEqual(18, importedLocations.Count); CollectionAssert.AllItemsAreNotNull(importedLocations); CollectionAssert.AllItemsAreUnique(importedLocations); + mocks.VerifyAll(); } [Test] @@ -212,5 +224,32 @@ mocks.VerifyAll(); // Expect no calls on 'observer' } + + [Test] + public void Import_CorruptSchemaFile_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.StrictMock(); + var importTarget = mocks.StrictMock(assessmentSectionMock); + mocks.ReplayAll(); + + string validFilePath = Path.Combine(testDataPath, "corruptschema.sqlite"); + string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath) + .Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database. Het bestand wordt overgeslagen."); + var importResult = true; + + // Precondition + TestDelegate precondition = () => importer.ValidateAndConnectTo(validFilePath); + Assert.DoesNotThrow(precondition, "Precodition failed: ValidateAndConnectTo failed"); + + // Call + Action call = () => importResult = importer.Import(importTarget); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsFalse(importResult); + mocks.VerifyAll(); + } } } \ No newline at end of file