Skip to content

Commit

Permalink
Also move the File-sharing exception with filename to the CommonExcep…
Browse files Browse the repository at this point in the history
…tions class
  • Loading branch information
erenes authored and fgreinacher committed Mar 10, 2019
1 parent 880a334 commit 28e0170
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions System.IO.Abstractions.TestingHelpers/CommonExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
2 changes: 1 addition & 1 deletion System.IO.Abstractions.TestingHelpers/MockFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion System.IO.Abstractions.TestingHelpers/MockFileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,7 @@
<data name="PROCESS_CANNOT_ACCESS_FILE_IN_USE" xml:space="preserve">
<value>The process cannot access the file because it is being used by another process.</value>
</data>
<data name="PROCESS_CANNOT_ACCESS_FILE_IN_USE_WITH_FILENAME" xml:space="preserve">
<value>The process cannot access the file '{0}' because it is being used by another process.</value>
</data>
</root>

0 comments on commit 28e0170

Please sign in to comment.