From 28e0170992b82e68f672dacb88850448ed53bed0 Mon Sep 17 00:00:00 2001 From: erenes Date: Sat, 9 Mar 2019 21:10:41 +0100 Subject: [PATCH] Also move the File-sharing exception with filename to the CommonExceptions class --- System.IO.Abstractions.TestingHelpers/CommonExceptions.cs | 6 ++++-- System.IO.Abstractions.TestingHelpers/MockFile.cs | 2 +- System.IO.Abstractions.TestingHelpers/MockFileData.cs | 2 +- .../Properties/Resources.resx | 3 +++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/System.IO.Abstractions.TestingHelpers/CommonExceptions.cs b/System.IO.Abstractions.TestingHelpers/CommonExceptions.cs index a65be57fc..c42acc894 100644 --- a/System.IO.Abstractions.TestingHelpers/CommonExceptions.cs +++ b/System.IO.Abstractions.TestingHelpers/CommonExceptions.cs @@ -55,7 +55,9 @@ public static ArgumentException IllegalCharactersInPath(string paramName = null) public static Exception InvalidUncPath(string paramName) => new ArgumentException(@"The UNC path should be of the form \\server\share.", paramName); - public static IOException ProcessCannotAccessFileInUse() => - new IOException(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE")); + public static IOException ProcessCannotAccessFileInUse(string paramName = null) => + paramName != null + ? new IOException(string.Format(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE_WITH_FILENAME"), paramName)) + : new IOException(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE")); } } \ No newline at end of file diff --git a/System.IO.Abstractions.TestingHelpers/MockFile.cs b/System.IO.Abstractions.TestingHelpers/MockFile.cs index 52ce256c4..27ecbe2da 100644 --- a/System.IO.Abstractions.TestingHelpers/MockFile.cs +++ b/System.IO.Abstractions.TestingHelpers/MockFile.cs @@ -180,7 +180,7 @@ public override void Delete(string path) var file = mockFileDataAccessor.GetFile(path); if (file != null && !file.AllowedFileShare.HasFlag(FileShare.Delete)) { - throw new IOException($"The process cannot access the file '{path}' because it is being used by another process."); + throw CommonExceptions.ProcessCannotAccessFileInUse(path); } mockFileDataAccessor.RemoveFile(path); diff --git a/System.IO.Abstractions.TestingHelpers/MockFileData.cs b/System.IO.Abstractions.TestingHelpers/MockFileData.cs index 55e4c687d..7aae029ab 100644 --- a/System.IO.Abstractions.TestingHelpers/MockFileData.cs +++ b/System.IO.Abstractions.TestingHelpers/MockFileData.cs @@ -177,7 +177,7 @@ public FileSecurity AccessControl internal void CheckFileAccess(string path, FileAccess access) { if (!AllowedFileShare.HasFlag((FileShare)access)) - throw new IOException($"The process cannot access the file '{path}' because it is being used by another process."); + throw CommonExceptions.ProcessCannotAccessFileInUse(path); } } } diff --git a/System.IO.Abstractions.TestingHelpers/Properties/Resources.resx b/System.IO.Abstractions.TestingHelpers/Properties/Resources.resx index b22ade6cf..76b81e948 100644 --- a/System.IO.Abstractions.TestingHelpers/Properties/Resources.resx +++ b/System.IO.Abstractions.TestingHelpers/Properties/Resources.resx @@ -150,4 +150,7 @@ The process cannot access the file because it is being used by another process. + + The process cannot access the file '{0}' because it is being used by another process. +