public MockFileSystem(IDictionary<string, MockFileData> files) { this.files = new Dictionary<string, MockFileData>( files, StringComparer.InvariantCultureIgnoreCase); file = new MockFile(this); directory = new MockDirectory(this, file); fileInfoFactory = new MockFileInfoFactory(this); path = new MockPath(); directoryInfoFactory = new MockDirectoryInfoFactory(this); }
public MockFileSystem(IDictionary<string, MockFileData> files, string currentDirectory = @"C:\Foo\Bar") { this.files = new Dictionary<string, MockFileData>(StringComparer.OrdinalIgnoreCase); pathField = new MockPath(this); file = new MockFile(this); directory = new MockDirectory(this, file, FixPath(currentDirectory)); fileInfoFactory = new MockFileInfoFactory(this); directoryInfoFactory = new MockDirectoryInfoFactory(this); if (files == null) return; foreach (var entry in files) AddFile(entry.Key, entry.Value); }
public MockFileSystem(IDictionary<string, MockFileData> files, string currentDirectory = "") { if (String.IsNullOrEmpty(currentDirectory)) currentDirectory = IO.Path.GetTempPath(); this.files = new Dictionary<string, MockFileData>(StringComparer.OrdinalIgnoreCase); pathField = new MockPath(this); file = new MockFile(this); directory = new MockDirectory(this, file, currentDirectory); fileInfoFactory = new MockFileInfoFactory(this); directoryInfoFactory = new MockDirectoryInfoFactory(this); if (files == null) return; foreach (var entry in files) AddFileWithCreate(entry.Key, entry.Value); }
public MockFileSystem(IDictionary<string, MockFileData> files) { file = new MockFile(this); directory = new MockDirectory(this, file); fileInfoFactory = new MockFileInfoFactory(this); path = new MockPath(); directoryInfoFactory = new MockDirectoryInfoFactory(this); //For each mock file add a file to the files dictionary //Also add a file entry for all directories leading up to this file this.files = new Dictionary<string, MockFileData>(StringComparer.InvariantCultureIgnoreCase); foreach (var entry in files) { var directoryPath = Path.GetDirectoryName(entry.Key); if (!directory.Exists(directoryPath)) directory.CreateDirectory(directoryPath); if (!file.Exists(entry.Key)) this.files.Add(entry.Key, entry.Value); } }
public MockFileData GetFile(string path) { path = FixPath(path); return FileExists(path) ? files[path] : null; }
#pragma warning restore 649 /// <inheritdoc /> public Task <FileExistenceResult> CheckFileExistsAsync(PathBase path, TimeSpan timeout, CancellationToken cancellationToken) => Task.FromResult(CheckFileExistsAsyncResult);
/// <inheritdoc /> public byte[] GetPathLocation(PathBase path) => new byte[] { };
public void ReturnsFalseIfOtherIsNull() { const PathBase nullPath = null; Assert.False(new AbsolutePath(Constants.ValidAbsoluteLocalRootPath + @"dir").Equals(nullPath)); }
public bool FileExists(string path) { path = FixPath(path); return files.ContainsKey(path); }
public Directory(PathBase Base) : this(new Path(Base)) { }
public override int GetHashCode() => Method.GetHashCode() ^ Host.GetHashCode() ^ PathBase.GetHashCode() ^ Path.GetHashCode() ^ QueryString.GetHashCode();
#pragma warning restore 649 /// <inheritdoc /> public Task <CopyFileResult> CopyToAsync(PathBase sourcePath, Stream destinationStream, long expectedContentSize, CancellationToken cancellationToken) => Task.FromResult(CopyToAsyncResult);
/// <inheritdoc /> public Task <CopyFileResult> CopyFileAsync(PathBase path, AbsolutePath destinationPath, long contentSize, bool overwrite, CancellationToken cancellationToken) => Task.FromResult(CopyFileAsyncResult);
public override string ToString() { if (IsUnixPipe) { if (String.IsNullOrEmpty(PathBase)) { return(Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant()); } else { return(Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + PathBase.ToLowerInvariant()); } } else { return(Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant()); } }
/// <summary> /// Build a string from the path with special characters removed/replaced. /// </summary> /// <remarks> /// The result can be used to name system-wide resources like mutexes, pipes, etc. /// </remarks> public static string ToGlobalResourceName(this PathBase path) { // Names for Mutexs can not have any slashes - need to skip "/" for unix return(@"Global\" + path.Path.ToUpperInvariant().Replace(":", string.Empty).Replace('\\', '_').Replace('/', '_')); }
public void AddFile(string path, MockFileData mockFile) { path = FixPath(path); files.Add(path, mockFile); }
public void RemoveFile(string path) { path = FixPath(path); files.Remove(path); }
public override string ToString() { return(Scheme.ToLowerInvariant() + "://" + Host.ToLowerInvariant() + ":" + Port.ToString(CultureInfo.InvariantCulture) + PathBase.ToLowerInvariant()); }
public void ReturnsFalseIfOtherIsNull() { const PathBase nullPath = null; Assert.False(new RelativePath(Constants.ValidLevelTwoRelativePath).Equals(nullPath)); }
public void Serialize(PathBase path) { Serialize(path.Path); }