Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs =================================================================== diff -u -r003c0b0d85b08cd50c56f29ec9539e973a5bd7c1 -r8262d1ecd40be168162bbd8c6331126885f280ed --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 003c0b0d85b08cd50c56f29ec9539e973a5bd7c1) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 8262d1ecd40be168162bbd8c6331126885f280ed) @@ -38,7 +38,7 @@ [TestFixture] public class StorageSqLiteTest { - private const int currentDatabaseVersoin = 1; + private const int currentDatabaseVersion = 1; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Storage, "DatabaseFiles"); private readonly string tempRingtoetsFile = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Storage, "DatabaseFiles"), "tempProjectFile.rtd"); @@ -214,8 +214,8 @@ TestDelegate precondition = () => { SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(tempRingtoetsFile); - SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersoin); - SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersoin); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersion); + SqLiteDatabaseHelper.AddVersionEntity(tempRingtoetsFile, currentDatabaseVersion); }; Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); @@ -236,8 +236,8 @@ } [Test] - [TestCase(currentDatabaseVersoin + 1)] - [TestCase(currentDatabaseVersoin + 500)] + [TestCase(currentDatabaseVersion + 1)] + [TestCase(currentDatabaseVersion + 500)] public void LoadProject_DatabaseFromFutureVersion_ThrowStorageValidationException(int versionCode) { // Setup @@ -462,6 +462,40 @@ } [Test] + public void SaveProkectAs_NoStagedProject_ThrowInvalidOperationException() + { + // Setup + var storage = new StorageSqLite(); + + // Precondition + Assert.IsFalse(storage.HasStagedProject); + + // Call + TestDelegate call = () => storage.SaveProjectAs(tempRingtoetsFile); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Call 'StageProject(IProject)' first before calling this method.", message); + } + + [Test] + public void HasStagedProjectChanges_NoProjectStaged_ThrowInvalidOperationException() + { + // Setup + var storage = new StorageSqLite(); + + // Precondition + Assert.IsFalse(storage.HasStagedProject); + + // Call + TestDelegate call = () => storage.HasStagedProjectChanges(); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Call 'StageProject(IProject)' first before calling this method.", message); + } + + [Test] public void HasStagedProjectChanges_NoConnectionSet_ReturnsTrue() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs =================================================================== diff -u -r003c0b0d85b08cd50c56f29ec9539e973a5bd7c1 -r8262d1ecd40be168162bbd8c6331126885f280ed --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs (.../SqLiteDatabaseHelperTest.cs) (revision 003c0b0d85b08cd50c56f29ec9539e973a5bd7c1) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs (.../SqLiteDatabaseHelperTest.cs) (revision 8262d1ecd40be168162bbd8c6331126885f280ed) @@ -34,6 +34,114 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Storage, "DatabaseFiles"); [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void CreateCorruptDatabaseFile_InvalidPath_ThrowArgumentNullException(string invalidFilePath) + { + // Call + TestDelegate call = () => SqLiteDatabaseHelper.CreateCorruptDatabaseFile(invalidFilePath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void CreateCorruptDatabaseFile_ValidArguments_CreatedDatabaseFile() + { + // Setup + string validPath = Path.Combine(testDataPath, "tempFile.rtd"); + + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(validPath); + try + { + // Call + TestDelegate test = () => SqLiteDatabaseHelper.CreateCorruptDatabaseFile(validPath); + + // Assert + Assert.DoesNotThrow(test); + Assert.IsTrue(File.Exists(validPath)); + } + finally + { + CallGarbageCollector(); + fileDisposeHelper.Dispose(); + } + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void CreateCompleteDatabaseFileWithoutProjectData_InvalidPath_ThrowsArgumentNullException(string invalidFilePath) + { + // Call + TestDelegate call = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileWithoutProjectData(invalidFilePath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void CreateCompleteDatabaseFileWithoutProjectData_ValidArguments_CreatedDatabaseFile() + { + // Setup + string validPath = Path.Combine(testDataPath, "tempFile.rtd"); + + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(validPath); + try + { + // Call + TestDelegate test = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileWithoutProjectData(validPath); + + // Assert + Assert.DoesNotThrow(test); + Assert.IsTrue(File.Exists(validPath)); + } + finally + { + CallGarbageCollector(); + fileDisposeHelper.Dispose(); + } + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void CreateCompleteDatabaseFileEmpty_InvalidPath_ThrowsArgumentNullException(string invalidFilePath) + { + // Call + TestDelegate call = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(invalidFilePath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void CreateCompleteDatabaseFileEmpty_ValidArguments_CreatedDatabaseFile() + { + // Setup + string validPath = Path.Combine(testDataPath, "tempFile.rtd"); + + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(validPath); + try + { + // Call + TestDelegate test = () => SqLiteDatabaseHelper.CreateCompleteDatabaseFileEmpty(validPath); + + // Assert + Assert.DoesNotThrow(test); + Assert.IsTrue(File.Exists(validPath)); + } + finally + { + CallGarbageCollector(); + fileDisposeHelper.Dispose(); + } + } + + [Test] public void CreateDatabaseFile_NullPath_ThrowsArgumentNullException() { // Setup @@ -175,6 +283,19 @@ Assert.IsFalse(query.Contains(notExpectedCreateProjectEntityTable)); } + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void AddVersionEntity_InvalidPath_ThrowsArgumentNullException(string invalidFilePath) + { + // Call + TestDelegate call = () => SqLiteDatabaseHelper.AddVersionEntity(invalidFilePath, 1); + + // Assert + Assert.Throws(call); + } + private static void CallGarbageCollector() { GC.Collect(); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs =================================================================== diff -u -r003c0b0d85b08cd50c56f29ec9539e973a5bd7c1 -r8262d1ecd40be168162bbd8c6331126885f280ed --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision 003c0b0d85b08cd50c56f29ec9539e973a5bd7c1) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision 8262d1ecd40be168162bbd8c6331126885f280ed) @@ -39,6 +39,7 @@ /// Creates a corrupt database file based on . /// /// The database file path. + /// When is null or whitespace. public static void CreateCorruptDatabaseFile(string databaseFilePath) { CreateDatabaseFile(databaseFilePath, GetCorruptSchema()); @@ -49,6 +50,7 @@ /// Creates the complete database file with a VersionEntity row but no project data. /// /// The database file path. + /// When is null or whitespace. public static void CreateCompleteDatabaseFileWithoutProjectData(string databaseFilePath) { CreateCompleteDatabaseFileEmpty(databaseFilePath); @@ -69,6 +71,7 @@ /// /// The database file path. /// The database version. + /// When is null or whitespace. public static void AddVersionEntity(string databaseFilePath, int databaseVersion) { string addVersionRowCommand = GetAddVersionRowCommandText(databaseVersion); @@ -81,12 +84,18 @@ /// Path to database file. /// Script that contains the schema to execute on the database. /// Thrown when executing failed. + /// When + /// or is null or whitespace. public static void CreateDatabaseFile(string databaseFilePath, string databaseSchemaQuery) { - if (databaseSchemaQuery == null) + if (string.IsNullOrWhiteSpace(databaseSchemaQuery)) { throw new ArgumentNullException("databaseSchemaQuery"); } + if (string.IsNullOrWhiteSpace(databaseFilePath)) + { + throw new ArgumentNullException("databaseFilePath"); + } SQLiteConnection.CreateFile(databaseFilePath); PerformCommandOnDatabase(databaseFilePath, databaseSchemaQuery); @@ -131,6 +140,12 @@ return Resources.DatabaseStructure; } + /// + /// Performs the command on a database. + /// + /// The file path to the database. + /// The command text/query. + /// When is null or whitespace. private static void PerformCommandOnDatabase(string databaseFilePath, string commandText) { var connectionString = SqLiteConnectionStringBuilder.BuildSqLiteConnectionString(databaseFilePath);