Exemple #1
0
        public void LoadProject_DatabaseFromFutureVersion_ThrowStorageValidationException(int additionalVersionNumber)
        {
            // Setup
            string tempProjectFilePath    = Path.Combine(workingDirectory, $"{nameof(LoadProject_DatabaseFromFutureVersion_ThrowStorageValidationException)}_{Path.GetRandomFileName()}");
            string currentDatabaseVersion = ProjectVersionHelper.GetCurrentDatabaseVersion();
            string versionCode            = additionalVersionNumber + currentDatabaseVersion;

            void Precondition()
            {
                SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempProjectFilePath);
                SqLiteDatabaseHelper.AddVersionEntity(tempProjectFilePath, versionCode);
            }

            Assert.DoesNotThrow(Precondition, "Precondition failed: creating future database file failed");

            // Call
            void Call() => new StorageSqLite().LoadProject(tempProjectFilePath);

            // Assert
            StorageException exception = Assert.Throws <StorageValidationException>(Call);

            Assert.IsInstanceOf <Exception>(exception);
            Assert.AreEqual($@"Fout bij het lezen van bestand '{tempProjectFilePath}': riskeer "
                            + $"bestand versie '{versionCode}' is hoger dan de huidig ondersteunde versie "
                            + $"('{currentDatabaseVersion}'). Update Riskeer naar een nieuwere versie.",
                            exception.Message);
        }
Exemple #2
0
        public void LoadProject_DatabaseWithMultipleVersionEntities_ThrowStorageValidationException()
        {
            // Setup
            string projectFilePath        = Path.Combine(workingDirectory, nameof(LoadProject_DatabaseWithMultipleVersionEntities_ThrowStorageValidationException));
            string currentDatabaseVersion = ProjectVersionHelper.GetCurrentDatabaseVersion();

            void Precondition()
            {
                SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(projectFilePath);
                SqLiteDatabaseHelper.AddVersionEntity(projectFilePath, currentDatabaseVersion);
                SqLiteDatabaseHelper.AddVersionEntity(projectFilePath, currentDatabaseVersion);
            }

            Assert.DoesNotThrow(Precondition, "Precondition failed: creating corrupt database file failed");

            // Call
            void Call() => new StorageSqLite().LoadProject(projectFilePath);

            // Assert
            StorageException exception = Assert.Throws <StorageValidationException>(Call);

            Assert.IsInstanceOf <Exception>(exception);
            Assert.AreEqual($@"Fout bij het lezen van bestand '{projectFilePath}': database moet één rij in de VersionEntity tabel hebben.",
                            exception.Message);
            Assert.IsInstanceOf <InvalidOperationException>(exception.InnerException);
        }
Exemple #3
0
        public void LoadProject_DatabaseWithInvalidVersionCode_ThrowStorageValidationException(string versionCode)
        {
            // Setup
            string tempProjectFilePath = Path.Combine(workingDirectory, $"{nameof(LoadProject_DatabaseWithInvalidVersionCode_ThrowStorageValidationException)}_{Path.GetRandomFileName()}");

            void Precondition()
            {
                SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempProjectFilePath);
                SqLiteDatabaseHelper.AddVersionEntity(tempProjectFilePath, versionCode);
            }

            Assert.DoesNotThrow(Precondition, "Precondition failed: creating future database file failed");

            // Call
            void Call() => new StorageSqLite().LoadProject(tempProjectFilePath);

            // Assert
            StorageException exception = Assert.Throws <StorageValidationException>(Call);

            Assert.IsInstanceOf <Exception>(exception);
            Assert.AreEqual($@"Fout bij het lezen van bestand '{tempProjectFilePath}': riskeer "
                            + $"bestand versie '{versionCode}' is niet valide. De versie van het Riskeer projectbestand "
                            + "dient '16.4' of hoger te zijn.", exception.Message);
        }