Issue
When creating a MockFileSystem with initial files using UNC paths (Windows format) on Unix-like systems, the error handling can be contradictory to the code and inaccurate, as the error message is fixed/hardcoded to Windows paths. For example, when running the below on a Unix-like system
varfilesystem=newMockFileSystem(newDictionary<string,MockFileData>{{@"\\server\share\file","content"}});The error reads System.ArgumentException: The UNC path should be of the form \\server\share. (Parameter 'path'), despite the path being in that exact form, and actually requiring the form //server/share on Unix-like systems.
Cause
It seems there is handling of UNC paths with forward-slash separation following this standard in the MockFileSystem class, from this line:
varisUnc=StringOperations.StartsWith(fixedPath,@"\\")||StringOperations.StartsWith(fixedPath,@"//");
The next line uses the platform-specific separator:
lastIndex=StringOperations.IndexOf(fixedPath,separator,2)
Which will then lead to errors if trying to use backslash-separated UNC paths on Unix-like systems, or presumably forwardslash-separated UNC paths on Windows systems (untested). The error message however, as above, is hardcoded/fixed to the Windows paths:
// In MockFileSystem.csif(lastIndex<0){throwCommonExceptions.InvalidUncPath(nameof(path));}// In CommonExceptions.cspublicstaticArgumentExceptionInvalidUncPath(stringparamName)=>newArgumentException(@"The UNC path should be of the form \\server\share.",paramName);
Issue
When creating a
MockFileSystemwith initial files using UNC paths (Windows format) on Unix-like systems, the error handling can be contradictory to the code and inaccurate, as the error message is fixed/hardcoded to Windows paths. For example, when running the below on a Unix-like systemThe error reads
System.ArgumentException: The UNC path should be of the form \\server\share. (Parameter 'path'), despite the path being in that exact form, and actually requiring the form//server/shareon Unix-like systems.Cause
It seems there is handling of UNC paths with forward-slash separation following this standard in the
MockFileSystemclass, from this line:The next line uses the platform-specific separator:
Which will then lead to errors if trying to use backslash-separated UNC paths on Unix-like systems, or presumably forwardslash-separated UNC paths on Windows systems (untested). The error message however, as above, is hardcoded/fixed to the Windows paths: