Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs =================================================================== diff -u -rfc38d18fc6ff1749476da0ea43281d5d80568283 -r2cf2214c4069c98c3cb21708729fcbc2ca964ab6 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision 2cf2214c4069c98c3cb21708729fcbc2ca964ab6) @@ -28,13 +28,12 @@ using Core.Common.Utils.Builders; using NUnit.Framework; using Rhino.Mocks; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.HydraRing.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; +using UtilsResources = Core.Common.Utils.Properties.Resources; namespace Ringtoets.Integration.Plugin.Test.FileImporters { @@ -66,94 +65,128 @@ } [Test] - public void ValidateAndConnectTo_ExistingFile_DoesNotThrowException() + public void GetHydraulicBoundaryDatabaseVersion_ValidFile_GetDatabaseVersion() { // Setup string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); // Call - TestDelegate test = () => importer.ValidateAndConnectTo(validFilePath); + string version = importer.GetHydraulicBoundaryDatabaseVersion(validFilePath); // Assert - Assert.DoesNotThrow(test); + Assert.IsNotNullOrEmpty(version); } [Test] - public void ValidateAndConnectTo_NonExistingFile_ThrowsCriticalFileReadException() + public void Import_ExistingFile_DoesNotThrowException() { // Setup - string filePath = Path.Combine(testDataPath, "nonexisting.sqlite"); - var expectedExceptionMessage = String.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", filePath); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Expect(section => section.NotifyObservers()); + mocks.ReplayAll(); + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + // Call - TestDelegate test = () => importer.ValidateAndConnectTo(filePath); + TestDelegate test = () => importer.Import(assessmentSection, validFilePath); // Assert - CriticalFileReadException exception = Assert.Throws(test); - Assert.AreEqual(expectedExceptionMessage, exception.Message); + Assert.DoesNotThrow(test); + + mocks.VerifyAll(); } [Test] - public void ValidateAndConnectTo_InvalidFile_ThrowsCriticalFileReadException() + public void Import_NonExistingFile_ThrowsCriticalFileReadException() { // Setup - string filePath = Path.Combine(testDataPath, "/"); - var expectedExceptionMessage = String.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet naar een map verwijzen.", filePath); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); + mocks.ReplayAll(); + string filePath = Path.Combine(testDataPath, "nonexisting.sqlite"); + var expectedExceptionMessage = String.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", filePath); + // Call - TestDelegate test = () => importer.ValidateAndConnectTo(filePath); + TestDelegate test = () => importer.Import(assessmentSection, filePath); // Assert CriticalFileReadException exception = Assert.Throws(test); Assert.AreEqual(expectedExceptionMessage, exception.Message); - Assert.IsInstanceOf(exception.InnerException); + + mocks.VerifyAll(); } [Test] - public void ValidateAndConnectTo_ExistingFileWithoutHlcd_ThrowCriticalFileReadException() + public void Import_InvalidFile_ThrowsCriticalFileReadException() { // Setup - string validFilePath = Path.Combine(testDataPath, "withoutHLCD", "empty.sqlite"); - string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath).Build("Het bijbehorende HLCD bestand is niet gevonden in dezelfde map als het HRD bestand."); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); + mocks.ReplayAll(); + var invalidPath = Path.Combine(testDataPath, "complete.sqlite"); + invalidPath = invalidPath.Replace('c', Path.GetInvalidPathChars()[0]); + // Call - TestDelegate test = () => importer.ValidateAndConnectTo(validFilePath); + TestDelegate test = () => importer.Import(assessmentSection, invalidPath); // Assert + var expectedMessage = new FileReaderErrorMessageBuilder(invalidPath) + .Build(String.Format(UtilsResources.Error_Path_cannot_contain_Characters_0_, + String.Join(", ", Path.GetInvalidFileNameChars()))); CriticalFileReadException exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + + mocks.VerifyAll(); } [Test] - public void GetHydraulicBoundaryDatabaseVersion_ValidFile_GetDatabaseVersion() + public void Import_FileIsDirectory_ThrowsCriticalFileReadException() { // Setup - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); - importer.ValidateAndConnectTo(validFilePath); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); + mocks.ReplayAll(); + string filePath = Path.Combine(testDataPath, "/"); + var expectedExceptionMessage = String.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet naar een map verwijzen.", filePath); + // Call - string version = importer.GetHydraulicBoundaryDatabaseVersion(); + TestDelegate test = () => importer.Import(assessmentSection, filePath); // Assert - Assert.IsNotNullOrEmpty(version); + CriticalFileReadException exception = Assert.Throws(test); + Assert.AreEqual(expectedExceptionMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + + mocks.VerifyAll(); } [Test] - public void Import_ConnectionNotOpened_ThrowsInValidOperationException() + public void Import_ExistingFileWithoutHlcd_ThrowCriticalFileReadException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); mocks.ReplayAll(); + string validFilePath = Path.Combine(testDataPath, "withoutHLCD", "empty.sqlite"); + // Call - TestDelegate call = () => importer.Import(assessmentSection); + TestDelegate test = () => importer.Import(assessmentSection, validFilePath); // Assert - var exception = Assert.Throws(call); - var expectedMessage = "Er is nog geen bestand geopend."; + string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath).Build("Het bijbehorende HLCD bestand is niet gevonden in dezelfde map als het HRD bestand."); + CriticalFileReadException exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); + mocks.VerifyAll(); } @@ -171,11 +204,9 @@ // Precondition Assert.IsTrue(File.Exists(validFilePath), string.Format("Precodition failed. File does not exist: {0}", validFilePath)); - importer.ValidateAndConnectTo(validFilePath); - // Call var importResult = false; - Action call = () => importResult = importer.Import(assessmentSection); + Action call = () => importResult = importer.Import(assessmentSection, validFilePath); // Assert TestHelper.AssertLogMessages(call, messages => @@ -205,10 +236,8 @@ var importResult = true; - importer.ValidateAndConnectTo(corruptPath); - // Call - Action call = () => importResult = importer.Import(assessmentSection); + Action call = () => importResult = importer.Import(assessmentSection, corruptPath); // Assert TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); @@ -230,12 +259,8 @@ string validFilePath = Path.Combine(testDataPath, "corruptschema.sqlite"); var importResult = true; - // Precondition - TestDelegate precondition = () => importer.ValidateAndConnectTo(validFilePath); - Assert.DoesNotThrow(precondition, "Precodition failed: ValidateAndConnectTo failed"); - // Call - Action call = () => importResult = importer.Import(assessmentSection); + Action call = () => importResult = importer.Import(assessmentSection, validFilePath); // Assert string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath)