Index: Application/Ringtoets/src/Application.Ringtoets.Storage/BackedUpFileWriter.cs =================================================================== diff -u -rbdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc -r6218e4d55d2f0806b03380316dd0a9c4e0871fc8 --- Application/Ringtoets/src/Application.Ringtoets.Storage/BackedUpFileWriter.cs (.../BackedUpFileWriter.cs) (revision bdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/BackedUpFileWriter.cs (.../BackedUpFileWriter.cs) (revision 6218e4d55d2f0806b03380316dd0a9c4e0871fc8) @@ -24,6 +24,7 @@ using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.Properties; + using Core.Common.Utils; namespace Application.Ringtoets.Storage @@ -144,10 +145,10 @@ } catch (Exception e) { - if (e is ArgumentException || e is IOException || e is SystemException) + if (e is ArgumentException || e is IOException || e is NotSupportedException || e is UnauthorizedAccessException) { var message = string.Format( - Resources.SafeOverwriteFileHelper_RemoveAlreadyExistingTemporaryFile_Already_existing_temporary_file_at_FilePath_0_could_not_be_removed, + Resources.SafeOverwriteFileHelper_RemoveAlreadyExistingTemporaryFile_Already_existing_temporary_file_at_FilePath_0_could_not_be_removed, temporaryFilePath); throw new IOException(message, e); } @@ -168,7 +169,7 @@ } catch (Exception e) { - if (e is ArgumentException || e is IOException || e is SystemException) + if (e is ArgumentException || e is IOException || e is UnauthorizedAccessException || e is NotSupportedException) { var message = string.Format( Resources.SafeOverwriteFileHelper_CreateNewTemporaryFile_Cannot_create_temporary_FilePath_0_Try_change_save_location, @@ -197,10 +198,10 @@ } catch (Exception e) { - if (e is ArgumentException || e is IOException || e is SystemException) + if (e is ArgumentException || e is IOException || e is NotSupportedException || e is UnauthorizedAccessException) { var message = string.Format( - Resources.SafeOverwriteFileHelper_RestoreOriginalFile_Cannot_revert_to_original_FilePath_0_Try_reverting_manually, + Resources.SafeOverwriteFileHelper_RestoreOriginalFile_Cannot_revert_to_original_FilePath_0_Try_reverting_manually, targetFilePath); throw new IOException(message, e); } @@ -220,10 +221,10 @@ } catch (Exception e) { - if (e is ArgumentException || e is IOException || e is SystemException) + if (e is ArgumentException || e is IOException || e is NotSupportedException || e is UnauthorizedAccessException) { var message = string.Format( - Resources.SafeOverwriteFileHelper_DeleteTemporaryFile_Cannot_remove_temporary_FilePath_0_Try_removing_manually, + Resources.SafeOverwriteFileHelper_DeleteTemporaryFile_Cannot_remove_temporary_FilePath_0_Try_removing_manually, temporaryFilePath); throw new CannotDeleteBackupFileException(message, e); } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs =================================================================== diff -u -rbdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc -r6218e4d55d2f0806b03380316dd0a9c4e0871fc8 --- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision bdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 6218e4d55d2f0806b03380316dd0a9c4e0871fc8) @@ -24,12 +24,14 @@ using System.Data.Entity; using System.IO; using System.Linq; + using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.Properties; using Application.Ringtoets.Storage.Read; using Application.Ringtoets.Storage.Update; + using Core.Common.Base.Data; using Core.Common.Base.Storage; using Core.Common.Utils; @@ -38,6 +40,7 @@ using log4net; using Ringtoets.Integration.Data; + using UtilsResources = Core.Common.Utils.Properties.Resources; namespace Application.Ringtoets.Storage @@ -47,7 +50,7 @@ /// public class StorageSqLite : IStoreProject { - private static ILog log = LogManager.GetLogger(typeof(StorageSqLite)); + private static readonly ILog log = LogManager.GetLogger(typeof(StorageSqLite)); private string connectionString; @@ -97,7 +100,7 @@ } catch (CannotDeleteBackupFileException e) { - log.Warn(e.Message); + log.Warn(e.Message, e); } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/BackedUpFileWriterTest.cs =================================================================== diff -u -rbdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc -r6218e4d55d2f0806b03380316dd0a9c4e0871fc8 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/BackedUpFileWriterTest.cs (.../BackedUpFileWriterTest.cs) (revision bdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/BackedUpFileWriterTest.cs (.../BackedUpFileWriterTest.cs) (revision 6218e4d55d2f0806b03380316dd0a9c4e0871fc8) @@ -33,7 +33,7 @@ [TestFixture] public class BackedUpFileWriterTest { - private string testWorkDir = Path.Combine(".", "SafeOverwriteFileHelperTest"); + private readonly string testWorkDir = Path.Combine(".", "SafeOverwriteFileHelperTest"); [TestFixtureSetUp] public void SetUpFixture() @@ -117,10 +117,7 @@ try { // Call - TestDelegate test = () => writer.Perform(() => - { - throw exception; - }); + TestDelegate test = () => writer.Perform(() => { throw exception; }); var actualException = Assert.Throws(exception.GetType(), test); Assert.AreSame(exception, actualException); @@ -142,27 +139,24 @@ var filePath = Path.Combine(testWorkDir, "iDoExist.txt"); var temporaryFilePath = filePath + "~"; - using (File.Create(filePath)) { } + using (File.Create(filePath)) {} var temporaryFileStream = File.Create(temporaryFilePath); var writer = new BackedUpFileWriter(filePath); // Precondition Assert.IsTrue(File.Exists(filePath)); Assert.IsTrue(File.Exists(temporaryFilePath)); - + // Call - TestDelegate test = () => - { - writer.Perform(() => { }); - }; + TestDelegate test = () => { writer.Perform(() => { }); }; try { // Assert var message = Assert.Throws(test).Message; var expectedMessage = string.Format( - "Er bestaat al een tijdelijk bestand ({0}) dat niet verwijderd kan worden. Het bestaande tijdelijke bestand dient handmatig verwijderd te worden.", + "Er bestaat al een tijdelijk bestand ({0}) dat niet verwijderd kan worden. Het bestaande tijdelijke bestand dient handmatig verwijderd te worden.", temporaryFilePath); Assert.AreEqual(message, expectedMessage); temporaryFileStream.Dispose(); @@ -183,24 +177,21 @@ Directory.CreateDirectory(notWritableDirectory); using (File.Create(filePath)) {} - DenyDirectoryRight(notWritableDirectory, FileSystemRights.Write); + DenyDirectoryRight(notWritableDirectory, FileSystemRights.Write); var writer = new BackedUpFileWriter(filePath); // Precondition Assert.IsTrue(File.Exists(filePath)); // Call - TestDelegate test = () => - { - writer.Perform(() => { }); - }; + TestDelegate test = () => { writer.Perform(() => { }); }; try { // Assert var expectedMessage = string.Format( - "Kan geen tijdelijk bestand maken van het originele bestand ({0}).", + "Kan geen tijdelijk bestand maken van het originele bestand ({0}).", filePath); var message = Assert.Throws(test).Message; Assert.AreEqual(expectedMessage, message); @@ -240,7 +231,7 @@ } [Test] - public void Perform_TargetFileExistsCannotDeleteFile_ThrowsIOException() + public void Perform_TargetFileExistsCannotDeleteFile_ThrowsCannotDeleteBackupFileException() { // Setup var noAccessDirectory = Path.Combine(testWorkDir, "Access"); @@ -257,14 +248,11 @@ try { // Call - TestDelegate test = () => helper.Perform(() => - { - fileStream = File.Open(temporaryFilePath, FileMode.Open); - }); + TestDelegate test = () => helper.Perform(() => { fileStream = File.Open(temporaryFilePath, FileMode.Open); }); // Assert var expectedMessage = string.Format( - "Kan het tijdelijke bestand ({0}) niet opruimen. Het tijdelijke bestand dient handmatig verwijderd te worden.", + "Kan het tijdelijke bestand ({0}) niet opruimen. Het tijdelijke bestand dient handmatig verwijderd te worden.", temporaryFilePath); var message = Assert.Throws(test).Message; Assert.AreEqual(expectedMessage, message); @@ -345,7 +333,7 @@ // Assert var expectedMessage = string.Format( - "Kan het originele bestand ({0}) niet herstellen. Het tijdelijke bestand dient handmatig hersteld te worden.", + "Kan het originele bestand ({0}) niet herstellen. Het tijdelijke bestand dient handmatig hersteld te worden.", filePath); var message = Assert.Throws(test).Message; Assert.AreEqual(expectedMessage, message); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs =================================================================== diff -u -rbdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc -r6218e4d55d2f0806b03380316dd0a9c4e0871fc8 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (.../CannotDeleteBackupFileExceptionTest.cs) (revision bdc1bbd84aa923749a80dfb0cf20f5bbcb54b3fc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (.../CannotDeleteBackupFileExceptionTest.cs) (revision 6218e4d55d2f0806b03380316dd0a9c4e0871fc8) @@ -34,7 +34,7 @@ public void DefaultConstructor_InnerExceptionNullAndMessageDefault() { // Setup - string expectedMessage = String.Format("Exception of type '{0}' was thrown.", typeof(EntityNotFoundException).FullName); + string expectedMessage = String.Format("Exception of type '{0}' was thrown.", typeof(CannotDeleteBackupFileException).FullName); // Call var exception = new CannotDeleteBackupFileException();