public void Constructor_ValidFile_ExpectedValues()
        {
            // Setup
            string dbFile = Path.Combine(testDataPath, "hlcdWithoutScenarioInformation.sqlite");

            // Call
            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Assert
                Assert.IsInstanceOf <SqLiteDatabaseReaderBase>(hydraulicBoundaryDatabaseReader);
            }
        }
        public void Read_ValidFileWithUsePreprocessClosureColumn_ExpectedValues(int trackId, bool expectedUsePreprocessorClosure)
        {
            string dbFile = Path.Combine(testDataPath, "hlcdWithPreprocessorClosureColumn.sqlite");

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                Assert.AreEqual(expectedUsePreprocessorClosure, readHydraulicLocationConfigurationDatabase.UsePreprocessorClosure);
            }
        }
Ejemplo n.º 3
0
 private ReadResult <ReadHydraulicLocationConfigurationDatabase> ReadHydraulicLocationConfigurationDatabase(string hlcdFilePath, long trackId)
 {
     NotifyProgress(Resources.HydraulicBoundaryDatabaseImporter_ProgressText_Reading_HLCD_file, 2, numberOfSteps);
     try
     {
         using (var reader = new HydraulicLocationConfigurationDatabaseReader(hlcdFilePath))
         {
             return(ReadHydraulicLocationConfigurationDatabase(trackId, reader));
         }
     }
     catch (CriticalFileReadException)
     {
         return(HandleCriticalFileReadError <ReadHydraulicLocationConfigurationDatabase>(Resources.HydraulicBoundaryDatabaseImporter_HLCD_sqlite_Not_Found));
     }
 }
        public void Read_InvalidFileWithUsePreprocessClosureColumn_ThrowsLineParseException()
        {
            string dbFile = Path.Combine(testDataPath, "hlcdWithInvalidPreprocessorClosureColumn.sqlite");

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(1000);

                // Assert
                string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.");
                var    exception       = Assert.Throws <LineParseException>(test);
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <InvalidCastException>(exception.InnerException);
            }
        }
        public void Read_EmptyFile_ThrowsCriticalFileReadException()
        {
            // Setup
            string    dbFile  = Path.Combine(testDataPath, "empty.sqlite");
            const int trackId = 1;

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Het bevragen van de database is mislukt.");
                var    exception       = Assert.Throws <CriticalFileReadException>(test);
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <SQLiteException>(exception.InnerException);
            }
        }
        public void Read_InvalidColumns_ThrowsLineParseException()
        {
            // Setup
            string    dbFile  = Path.Combine(testDataPath, "corruptschema.sqlite");
            const int trackId = 1;

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.");
                var    exception       = Assert.Throws <LineParseException>(test);
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <InvalidCastException>(exception.InnerException);
            }
        }
        public void Read_FileWithScenarioInformationAndInvalidData_ThrowsLineParseException()
        {
            // Setup
            const int trackId = 18169;
            string    dbFile  = Path.Combine(testDataPath, "hlcdWithScenarioInformationInvalidData.sqlite");

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.");
                var    exception       = Assert.Throws <LineParseException>(test);
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <ConversionException>(exception.InnerException);
            }
        }
        public void Read_ValidFileWithoutScenarioInformation_ExpectedValues(int trackId, int hrdLocationId, int expectedLocationId)
        {
            // Setup
            string dbFile = Path.Combine(testDataPath, "hlcdWithoutScenarioInformation.sqlite");

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                long actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId)
                                        .Select(m => m.HlcdLocationId)
                                        .SingleOrDefault();
                Assert.AreEqual(expectedLocationId, actualLocationId);
                Assert.IsFalse(readHydraulicLocationConfigurationDatabase.UsePreprocessorClosure);
                Assert.IsNull(readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings);
            }
        }
 private ReadResult <ReadHydraulicLocationConfigurationDatabase> ReadHydraulicLocationConfigurationDatabase(long trackId)
 {
     NotifyProgress(Resources.HydraulicBoundaryDatabaseImporter_ProgressText_Reading_HLCD_file, 2, numberOfSteps);
     try
     {
         using (var reader = new HydraulicLocationConfigurationDatabaseReader(FilePath))
         {
             return(new ReadResult <ReadHydraulicLocationConfigurationDatabase>(false)
             {
                 Items = new[]
                 {
                     reader.Read(trackId)
                 }
             });
         }
     }
     catch (Exception e) when(e is CriticalFileReadException || e is LineParseException)
     {
         return(HandleCriticalFileReadError <ReadHydraulicLocationConfigurationDatabase>(e));
     }
 }
        public void Read_AmbiguousLocations_ReturnsFirstLocationIdAndLogsWarning()
        {
            // Setup
            string    dbFile        = Path.Combine(testDataPath, "ambigousLocation.sqlite");
            const int trackId       = 11;
            const int hrdLocationId = 1;
            ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = null;

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                Action call = () => readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(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 actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId)
                                        .Select(m => m.HlcdLocationId)
                                        .Single();
                Assert.AreEqual(expectedLocationId, actualLocationId);
            }
        }
Ejemplo n.º 11
0
 private ReadResult <ReadHydraulicLocationConfigurationDatabase> ReadHydraulicLocationConfigurationDatabase(long trackId, HydraulicLocationConfigurationDatabaseReader reader)
 {
     try
     {
         return(new ReadResult <ReadHydraulicLocationConfigurationDatabase>(false)
         {
             Items = new[]
             {
                 reader.Read(trackId)
             }
         });
     }
     catch (Exception e) when(e is CriticalFileReadException || e is LineParseException)
     {
         return(HandleCriticalFileReadError <ReadHydraulicLocationConfigurationDatabase>(e));
     }
 }
        public void Read_ValidFileWithScenarioInformation_ExpectedValues(int trackId, int hrdLocationId, int expectedLocationId)
        {
            // Setup
            string dbFile = Path.Combine(testDataPath, "hlcdWithScenarioInformation.sqlite");

            using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile))
            {
                // Call
                ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId);

                // Assert
                long actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId)
                                        .Select(m => m.HlcdLocationId)
                                        .SingleOrDefault();
                Assert.AreEqual(expectedLocationId, actualLocationId);
                Assert.IsFalse(readHydraulicLocationConfigurationDatabase.UsePreprocessorClosure);
                IEnumerable <ReadHydraulicLocationConfigurationDatabaseSettings> readHydraulicLocationConfigurationDatabaseSettings =
                    readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings;
                Assert.AreEqual(2, readHydraulicLocationConfigurationDatabaseSettings.Count());

                CollectionAssert.AreEqual(new[]
                {
                    "ScenarioName WBI2017",
                    "ScenarioName WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.ScenarioName));
                CollectionAssert.AreEqual(new[]
                {
                    2023,
                    2024
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Year));
                CollectionAssert.AreEqual(new[]
                {
                    "Scope WBI2017",
                    "Scope WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Scope));
                CollectionAssert.AreEqual(new[]
                {
                    "SeaLevel WBI2017",
                    "SeaLevel WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.SeaLevel));
                CollectionAssert.AreEqual(new[]
                {
                    "RiverDischarge WBI2017",
                    "RiverDischarge WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.RiverDischarge));
                CollectionAssert.AreEqual(new[]
                {
                    "LakeLevel WBI2017",
                    "LakeLevel WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.LakeLevel));
                CollectionAssert.AreEqual(new[]
                {
                    "WindDirection WBI2017",
                    "WindDirection WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.WindDirection));
                CollectionAssert.AreEqual(new[]
                {
                    "WindSpeed WBI2017",
                    "WindSpeed WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.WindSpeed));
                CollectionAssert.AreEqual(new[]
                {
                    "Comment WBI2017",
                    "Comment WBI2018"
                }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Comment));
            }
        }