Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqliteCreatorTest.cs =================================================================== diff -u -r9e5ed1951ee2cf1e00c8dc3bc367711600fa77e0 -rd9dc53b9a37d5f91e75d237acc7aa582597bef85 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqliteCreatorTest.cs (.../StorageSqliteCreatorTest.cs) (revision 9e5ed1951ee2cf1e00c8dc3bc367711600fa77e0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqliteCreatorTest.cs (.../StorageSqliteCreatorTest.cs) (revision d9dc53b9a37d5f91e75d237acc7aa582597bef85) @@ -21,6 +21,7 @@ using System; using System.IO; +using Core.Common.Base.Storage; using Core.Common.TestUtil; using NUnit.Framework; @@ -29,6 +30,7 @@ public class StorageSqliteCreatorTest { 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"); [Test] [TestCase(null)] @@ -49,20 +51,53 @@ { // Setup const string fileName = "DoesNotExist.sqlite"; - var fullPath = Path.GetFullPath(Path.Combine(testDataPath, fileName)); var uncPath = GetUncPath(fullPath); + // Precondition + Assert.IsFalse(File.Exists(fullPath)); + using (new FileDisposeHelper(fullPath)) { // Call TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(uncPath); // Assert Assert.DoesNotThrow(call); + + Assert.IsTrue(File.Exists(fullPath)); } } + [Test] + public void CreateDatabaseStructure_ValidPathToLockedFile_ThrowsUpdateStorageException() + { + // Setup + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try + { + // Call + TestDelegate call = () => StorageSqliteCreator.CreateDatabaseStructure(tempRingtoetsFile); + + StorageException exception; + using (File.Create(tempRingtoetsFile)) // Locks file + { + exception = Assert.Throws(call); + } + + // Assert + Assert.IsInstanceOf(exception.InnerException); + var expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}': "+ + "Een fout is opgetreden met schrijven naar het nieuwe Ringtoets bestand.", tempRingtoetsFile); + Assert.AreEqual(expectedMessage, exception.Message); + } + finally + { + CallGarbageCollector(); + fileDisposeHelper.Dispose(); + } + } + private static string GetUncPath(string fullPath) { var root = Path.GetPathRoot(fullPath); @@ -74,5 +109,11 @@ var uncPath = new Uri(Path.Combine(@"\\localhost", drive + "$", relativePath)); return uncPath.LocalPath; } + + private static void CallGarbageCollector() + { + //GC.Collect(); + //GC.WaitForPendingFinalizers(); + } } } \ No newline at end of file