Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabaseContext/HydraulicLocationConfigurationSqLiteDatabaseReaderTest.cs =================================================================== diff -u -r64d60335b1deab4bafd37f78f3514660cc4afb27 -rf8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabaseContext/HydraulicLocationConfigurationSqLiteDatabaseReaderTest.cs (.../HydraulicLocationConfigurationSqLiteDatabaseReaderTest.cs) (revision 64d60335b1deab4bafd37f78f3514660cc4afb27) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabaseContext/HydraulicLocationConfigurationSqLiteDatabaseReaderTest.cs (.../HydraulicLocationConfigurationSqLiteDatabaseReaderTest.cs) (revision f8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e) @@ -41,16 +41,19 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicLocationConfigurationDatabase"); [Test] - public void Constructor_ValidFile_ThrowsCriticalFileReadException() + public void Constructor_InvalidFile_ThrowsCriticalFileReadException() { // Setup string testFile = Path.Combine(testDataPath, "none.sqlite"); - string expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(UtilsResources.Error_File_does_not_exist); // Call - TestDelegate test = () => new HydraulicLocationConfigurationSqLiteDatabaseReader(testFile).Dispose(); + TestDelegate test = () => + { + using (new HydraulicLocationConfigurationSqLiteDatabaseReader(testFile)) {} + }; // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build(UtilsResources.Error_File_does_not_exist); var exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); } @@ -67,12 +70,10 @@ // Assert Assert.IsInstanceOf(hydraulicBoundarySqLiteDatabaseReader); } - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } [Test] - [TestCase(1, 1, 100001)] - [TestCase(18, 1000, 1801000)] + [TestCase(18169, 1000, 1801000)] [TestCase(6, 1000, 0)] public void GetLocationsIdByTrackId_ValidFile_ExpectedValues(int trackId, int hrdLocationId, int expectedLocationId) { @@ -89,7 +90,6 @@ locationIdDictionary.TryGetValue(hrdLocationId, out locationId); Assert.AreEqual(expectedLocationId, locationId); } - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } [Test] @@ -99,8 +99,6 @@ string dbFile = Path.Combine(testDataPath, "ambigousLocation.sqlite"); const int trackId = 18; const int hrdLocationId = 1; - const int expectedLocationId = 1800001; - const string expectedMessage = "Er zijn meerdere resultaten gevonden, wat niet voor zou mogen komen. Neem contact op met de leverancier. Het eerste resultaat zal worden gebruikt."; var locationIdDictionary = new Dictionary(); using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) @@ -109,60 +107,148 @@ Action call = () => locationIdDictionary = hydraulicBoundarySqLiteDatabaseReader.GetLocationsIdByTrackId(trackId); // Assert + const int expectedLocationId = 1800001; + const string expectedMessage = "Er zijn meerdere resultaten gevonden, wat niet voor zou mogen komen. Neem contact op met de leverancier. Het eerste resultaat zal worden gebruikt."; TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); long locationId; locationIdDictionary.TryGetValue(hrdLocationId, out locationId); Assert.AreEqual(expectedLocationId, locationId); } - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } [Test] public void GetLocationsIdByTrackId_InvalidColumns_ThrowsLineParseException() { // Setup string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); - string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); const int trackId = 1; - // Precondition - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); - using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) { // Call TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetLocationsIdByTrackId(trackId); // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); var exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf(exception.InnerException); } - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } [Test] public void GetLocationsIdByTrackId_EmptyFile_ThrowsCriticalFileReadException() { // Setup string dbFile = Path.Combine(testDataPath, "empty.sqlite"); - string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicLocationConfigurationSqLiteDatabaseReader_Critical_Unexpected_Exception); const int trackId = 1; - // Precondition - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); - using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) { // Call TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetLocationsIdByTrackId(trackId); // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicLocationConfigurationSqLiteDatabaseReader_Critical_Unexpected_Exception); var exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf(exception.InnerException); } - Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } + + [Test] + [TestCase(1000, true)] + [TestCase(11, false)] + public void GetCanUsePreprocessorByTrackId_ValidFile_ExpectedValues(long trackId, bool expectedUsePreprocessor) + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) + { + // Call + bool usePreprocessor = hydraulicBoundarySqLiteDatabaseReader.GetCanUsePreprocessorByTrackId(trackId); + + // Assert + Assert.AreEqual(expectedUsePreprocessor, usePreprocessor); + } + } + + [Test] + public void GetCanUsePreprocessorByTrackId_ValidFileWithoutUsePreprocessorColumn_ReturnFalse() + { + // Setup + string dbFile = Path.Combine(testDataPath, "noUsePreprocessorColumn.sqlite"); + const int trackId = 1000; + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) + { + // Call + bool usePreprocessor = hydraulicBoundarySqLiteDatabaseReader.GetCanUsePreprocessorByTrackId(trackId); + + // Assert + Assert.IsFalse(usePreprocessor); + } + } + + [Test] + public void GetCanUsePreprocessorByTrackId_UnknownRegionIdForTrackId_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + const int trackId = 1; + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetCanUsePreprocessorByTrackId(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicLocationConfigurationSqLiteDatabaseReader_Critical_Unexpected_Exception); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsNull(exception.InnerException); + } + } + + [Test] + public void GetCanUsePreprocessorByTrackId_EmptyFile_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "empty.sqlite"); + const int trackId = 1; + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetCanUsePreprocessorByTrackId(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicLocationConfigurationSqLiteDatabaseReader_Critical_Unexpected_Exception); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void GetCanUsePreprocessorByTrackId_InvalidColumns_ThrowsLineParseException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + const int trackId = 1000; + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicLocationConfigurationSqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetCanUsePreprocessorByTrackId(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } } } \ No newline at end of file