Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs =================================================================== diff -u -r9af4c0af1efc736f7052449c0afed47233ae8523 -r4adf3910b91fba2fe6e7f7766836082046ab769a --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 9af4c0af1efc736f7052449c0afed47233ae8523) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 4adf3910b91fba2fe6e7f7766836082046ab769a) @@ -103,6 +103,7 @@ { // Setup var dbFile = Path.Combine(testDataPath, validPath); + var projectName = Path.GetFileNameWithoutExtension(validPath); var storage = new StorageSqLite(); // Precondition @@ -114,7 +115,7 @@ // Assert Assert.IsInstanceOf(loadedProject); Assert.AreEqual(1, loadedProject.StorageId); - Assert.AreEqual("TestProject", loadedProject.Name); + Assert.AreEqual(projectName, loadedProject.Name); Assert.AreEqual("Test description", loadedProject.Description); } @@ -140,70 +141,66 @@ public void SaveProjectAs_InvalidProject_ThrowsArgumentNullException() { // Setup - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); var storage = new StorageSqLite(); // Call - TestDelegate test = () => storage.SaveProjectAs(tempFile, null); + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, null); // Assert Assert.Throws(test); // Tear Down - TearDownTempRingtoetsFile(tempFile); + TearDownTempRingtoetsFile(tempRingtoetsFile); } [Test] public void SaveProjectAs_ValidPathToNonExistingFile_DoesNotThrowException() { // Setup - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); var project = new Project(); var storage = new StorageSqLite(); // Call - TestDelegate test = () => storage.SaveProjectAs(tempFile, project); + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, project); // Assert Assert.DoesNotThrow(test); // Tear Down - TearDownTempRingtoetsFile(tempFile); + TearDownTempRingtoetsFile(tempRingtoetsFile); } [Test] public void SaveProjectAs_ValidPathToExistingFile_DoesNotThrowException() { // Setup - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); - SetUpTempRingtoetsFile(tempFile); + SetUpTempRingtoetsFile(tempRingtoetsFile); var project = new Project(); var storage = new StorageSqLite(); // Call - TestDelegate test = () => storage.SaveProjectAs(tempFile, project); + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, project); // Assert Assert.DoesNotThrow(test); // Tear Down - TearDownTempRingtoetsFile(tempFile); + TearDownTempRingtoetsFile(tempRingtoetsFile); } [Test] public void SaveProjectAs_ValidPathToLockedFile_ThrowsUpdateStorageException() { // Setup - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); - string expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}': Een fout is opgetreden met schrijven naar het nieuwe Ringtoets bestand.", tempFile); + string expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}': Een fout is opgetreden met schrijven naar het nieuwe Ringtoets bestand.", tempRingtoetsFile); var project = new Project(); var storage = new StorageSqLite(); // Call - TestDelegate test = () => storage.SaveProjectAs(tempFile, project); + TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, project); StorageException exception; - using (File.Create(tempFile)) // Locks file + using (File.Create(tempRingtoetsFile)) // Locks file { exception = Assert.Throws(test); } @@ -214,7 +211,7 @@ Assert.AreEqual(expectedMessage, exception.Message); // Tear Down - TearDownTempRingtoetsFile(tempFile); + TearDownTempRingtoetsFile(tempRingtoetsFile); } [Test] @@ -250,16 +247,20 @@ } [Test] - public void SaveProject_InvalidProject_ThrowsStorageExceptionAndCouldNotConnectException() + public void SaveProject_ValidProjectNonExistingPath_ThrowsStorageExceptionAndCouldNotConnectException() { // Setup - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); + var project = new Project + { + StorageId = 1234L + }; + var tempFile = Path.Combine(testDataPath, "DoesNotExist.rtd"); string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': ", tempFile); string expectedInnerMessage = "Het bestand bestaat niet."; var storage = new StorageSqLite(); // Call - TestDelegate test = () => storage.SaveProject(tempFile, null); + TestDelegate test = () => storage.SaveProject(tempFile, project); // Assert StorageException exception = Assert.Throws(test); @@ -324,61 +325,27 @@ { // Setup long projectId = 1234L; - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); + var projectName = Path.GetFileNameWithoutExtension(tempRingtoetsFile); + var project = new Project() { StorageId = projectId }; var storage = new StorageSqLite(); - TestDelegate precondition = () => storage.SaveProjectAs(tempFile, project); - Assert.DoesNotThrow(precondition, String.Format("Precondition: file '{0}' must be a valid Ringtoets database file.", tempFile)); + TestDelegate precondition = () => storage.SaveProjectAs(tempRingtoetsFile, project); + Assert.DoesNotThrow(precondition, String.Format("Precondition: file '{0}' must be a valid Ringtoets database file.", tempRingtoetsFile)); // Call - TestDelegate test = () => storage.SaveProject(tempFile, project); + TestDelegate test = () => storage.SaveProject(tempRingtoetsFile, project); // Assert Assert.DoesNotThrow(test); + Assert.AreEqual(projectName, project.Name); // TearDown - TearDownTempRingtoetsFile(tempFile); + TearDownTempRingtoetsFile(tempRingtoetsFile); } - [Test] - public void SaveProjectLoadProject_ValidPathToSetFilePath_ValidContentsFromDatabase() - { - // Setup - long projectId = 1234L; - var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd"); - var project = new Project() - { - StorageId = projectId, - Name = "test", - Description = "description" - }; - var storage = new StorageSqLite(); - TestDelegate precondition = () => storage.SaveProjectAs(tempFile, project); - Assert.DoesNotThrow(precondition, String.Format("Precondition: file '{0}' must be a valid Ringtoets database file.", tempFile)); - - // Call - TestDelegate test = () => storage.SaveProject(tempFile, project); - - // Assert - Assert.DoesNotThrow(test, String.Format("Precondition: failed to save project to file '{0}'.", tempFile)); - - // Call - Project loadedProject = storage.LoadProject(tempFile); - - // Assert - Assert.IsInstanceOf(loadedProject); - Assert.AreNotEqual(project, loadedProject); - Assert.AreEqual(project.StorageId, loadedProject.StorageId); - Assert.AreEqual(project.Name, loadedProject.Name); - Assert.AreEqual(project.Description, loadedProject.Description); - - // TearDown - TearDownTempRingtoetsFile(tempFile); - } - private static void SetUpTempRingtoetsFile(string filePath) { if (File.Exists(filePath))