Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs =================================================================== diff -u -r10685fa0f0a169f861957361448c4cd51ddb6784 -r9af4c0af1efc736f7052449c0afed47233ae8523 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 10685fa0f0a169f861957361448c4cd51ddb6784) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 9af4c0af1efc736f7052449c0afed47233ae8523) @@ -1,4 +1,6 @@ using System; +using System.Data; +using System.Data.SQLite; using System.IO; using Core.Common.Base.Data; using Core.Common.Base.Storage; @@ -73,6 +75,29 @@ } [Test] + [TestCase("corruptRingtoetsDatabase.rtd")] + public void LoadProject_CorruptRingtoetsFileThatPassesValidation_ThrowsStorageExceptionWithFullStackTrace(string validPath) + { + // Setup + var tempFile = Path.Combine(testDataPath, validPath); + string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': ", tempFile); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempFile); + + // Assert + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + string expectedInnerExceptionMessage = "An error occurred while executing the command definition. See the inner exception for details."; + Assert.AreEqual(expectedInnerExceptionMessage, exception.InnerException.Message); + Assert.IsInstanceOf(exception.InnerException.InnerException); + string expectedInnerExceptionInnerExceptionMessage = "SQL logic error or missing database\r\nno such table: ProjectEntity"; + Assert.AreEqual(expectedInnerExceptionInnerExceptionMessage, exception.InnerException.InnerException.Message); + } + + [Test] [TestCase("ValidRingtoetsDatabase.rtd")] public void LoadProject_ValidDatabase_ReturnsProject(string validPath) { @@ -268,6 +293,33 @@ } [Test] + [TestCase("corruptRingtoetsDatabase.rtd")] + public void SaveProject_CorruptRingtoetsFileThatPassesValidation_ThrowsStorageExceptionWithFullStackTrace(string validPath) + { + // Setup + var project = new Project + { + StorageId = 1234L + }; + var tempFile = Path.Combine(testDataPath, validPath); + var storage = new StorageSqLite(); + + // Call + TestDelegate test = () => storage.SaveProject(tempFile, project); + + // Assert + StorageException exception = Assert.Throws(test); + string expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}'{1}: {2}", tempFile, "", "Een fout is opgetreden met het updaten van het Ringtoets bestand."); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + string expectedInnerExceptionMessage = "An error occurred while executing the command definition. See the inner exception for details."; + Assert.AreEqual(expectedInnerExceptionMessage, exception.InnerException.Message); + Assert.IsInstanceOf(exception.InnerException.InnerException); + string expectedInnerExceptionInnerExceptionMessage = "SQL logic error or missing database\r\nno such table: ProjectEntity"; + Assert.AreEqual(expectedInnerExceptionInnerExceptionMessage, exception.InnerException.InnerException.Message); + } + + [Test] public void SaveProject_ValidPathToSetFilePath_DoesNotThrowException() { // Setup @@ -327,7 +379,7 @@ TearDownTempRingtoetsFile(tempFile); } - private void SetUpTempRingtoetsFile(string filePath) + private static void SetUpTempRingtoetsFile(string filePath) { if (File.Exists(filePath)) { @@ -336,7 +388,7 @@ using (File.Create(filePath)) {} } - private void TearDownTempRingtoetsFile(string filePath) + private static void TearDownTempRingtoetsFile(string filePath) { GC.Collect(); GC.WaitForPendingFinalizers();