public void ReadTrackId_ValidFile_ReturnsReadVersion()
        {
            // Setup
            string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite");

            using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile))
            {
                // Call
                long trackId = reader.ReadTrackId();

                // Assert
                Assert.AreEqual(13, trackId);
            }
        }
        public void ReadTrackId_EmptyDatabase_ThrowsCriticalFileReadException()
        {
            // Setup
            string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "emptyGeneral.sqlite");

            using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile))
            {
                // Call
                TestDelegate test = () => reader.ReadTrackId();

                // Assert
                string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.";
                var    exception       = Assert.Throws <CriticalFileReadException>(test);
                Assert.AreEqual(expectedMessage, exception.Message);
            }
        }
        public void ReadTrackId_InvalidTrackIdColumn_ThrowsLineParseException()
        {
            // Setup
            string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "corruptSchema.sqlite");

            using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile))
            {
                // Call
                TestDelegate test = () => reader.ReadTrackId();

                // Assert
                var    exception       = Assert.Throws <LineParseException>(test);
                string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.";
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <InvalidCastException>(exception.InnerException);
            }
        }
        public void ReadTrackId_InvalidDatabaseWithoutGeneralTable_ThrowsCriticalFileReadException()
        {
            // Setup
            string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "empty.sqlite");

            using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile))
            {
                // Call
                TestDelegate test = () => reader.ReadTrackId();

                // Assert
                var    exception       = Assert.Throws <CriticalFileReadException>(test);
                string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kon geen locaties verkrijgen van de database.";
                Assert.AreEqual(expectedMessage, exception.Message);
                Assert.IsInstanceOf <SQLiteException>(exception.InnerException);
            }
        }
 private ReadResult <long> ReadTrackId()
 {
     NotifyProgress(Resources.HydraulicBoundaryDatabaseImporter_ProgressText_Reading_HRD_file, 1, numberOfSteps);
     try
     {
         using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabase.FilePath))
         {
             return(new ReadResult <long>(false)
             {
                 Items = new[]
                 {
                     reader.ReadTrackId()
                 }
             });
         }
     }
     catch (Exception e) when(e is CriticalFileReadException || e is LineParseException)
     {
         return(HandleCriticalFileReadError <long>(e));
     }
 }