Skip to content

Commit 28e0170

Browse files
erenesfgreinacher
authored andcommitted
Also move the File-sharing exception with filename to the CommonExceptions class
1 parent 880a334 commit 28e0170

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

System.IO.Abstractions.TestingHelpers/CommonExceptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public static ArgumentException IllegalCharactersInPath(string paramName = null)
5555
public static Exception InvalidUncPath(string paramName) =>
5656
new ArgumentException(@"The UNC path should be of the form \\server\share.", paramName);
5757

58-
public static IOException ProcessCannotAccessFileInUse() =>
59-
new IOException(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE"));
58+
public static IOException ProcessCannotAccessFileInUse(string paramName = null) =>
59+
paramName != null
60+
? new IOException(string.Format(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE_WITH_FILENAME"), paramName))
61+
: new IOException(StringResources.Manager.GetString("PROCESS_CANNOT_ACCESS_FILE_IN_USE"));
6062
}
6163
}

System.IO.Abstractions.TestingHelpers/MockFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public override void Delete(string path)
180180
var file = mockFileDataAccessor.GetFile(path);
181181
if (file != null && !file.AllowedFileShare.HasFlag(FileShare.Delete))
182182
{
183-
throw new IOException($"The process cannot access the file '{path}' because it is being used by another process.");
183+
throw CommonExceptions.ProcessCannotAccessFileInUse(path);
184184
}
185185

186186
mockFileDataAccessor.RemoveFile(path);

System.IO.Abstractions.TestingHelpers/MockFileData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public FileSecurity AccessControl
177177
internal void CheckFileAccess(string path, FileAccess access)
178178
{
179179
if (!AllowedFileShare.HasFlag((FileShare)access))
180-
throw new IOException($"The process cannot access the file '{path}' because it is being used by another process.");
180+
throw CommonExceptions.ProcessCannotAccessFileInUse(path);
181181
}
182182
}
183183
}

System.IO.Abstractions.TestingHelpers/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,7 @@
150150
<data name="PROCESS_CANNOT_ACCESS_FILE_IN_USE" xml:space="preserve">
151151
<value>The process cannot access the file because it is being used by another process.</value>
152152
</data>
153+
<data name="PROCESS_CANNOT_ACCESS_FILE_IN_USE_WITH_FILENAME" xml:space="preserve">
154+
<value>The process cannot access the file '{0}' because it is being used by another process.</value>
155+
</data>
153156
</root>

0 commit comments

Comments
 (0)