diff --git a/TestHelpers.Tests/MockDirectoryTests.cs b/TestHelpers.Tests/MockDirectoryTests.cs index f9db03a76..c29a8aa94 100644 --- a/TestHelpers.Tests/MockDirectoryTests.cs +++ b/TestHelpers.Tests/MockDirectoryTests.cs @@ -542,7 +542,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectory() }); // Act - fileSystem.Directory.Delete(@"c:\bar"); + fileSystem.Directory.Delete(@"c:\bar", true); // Assert Assert.IsFalse(fileSystem.Directory.Exists(@"c:\bar")); @@ -558,7 +558,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryCaseInsensitively() }); // Act - fileSystem.Directory.Delete(@"c:\BAR"); + fileSystem.Directory.Delete(@"c:\BAR", true); // Assert Assert.IsFalse(fileSystem.Directory.Exists(@"c:\bar")); @@ -630,7 +630,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryRecursively() public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories() { const string testPath = @"c:\foo\bar.txt"; - const string testDir = @"c:\foo\bar"; + const string testDir = @"c:\foo\bar\"; var fileSystem = new MockFileSystem(new Dictionary { { testPath, new MockFileData("Demo text content") }, @@ -639,8 +639,28 @@ public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories() var entries = fileSystem.Directory.GetFileSystemEntries(@"c:\foo").OrderBy(k => k); Assert.AreEqual(2, entries.Count()); - Assert.AreEqual(testDir, entries.First()); - Assert.AreEqual(testPath, entries.Last()); + Assert.AreEqual(testDir, entries.Last()); + Assert.AreEqual(testPath, entries.First()); + } + + [Test] + public void MockDirectory_GetDirectories_Returns_Child_Directories() + { + var fileSystem = new MockFileSystem(new Dictionary + { + { @"A:\folder1\folder2\folder3\file.txt", new MockFileData("Demo text content") }, + { @"A:\folder1\folder4\file2.txt", new MockFileData("Demo text content 2") }, + }); + + var directories = fileSystem.Directory.GetDirectories(@"A:\folder1").ToArray(); + + //Check that it does not returns itself + Assert.IsFalse(directories.Contains(@"A:\folder1\")); + + //Check that it correctly returns all child directories + Assert.AreEqual(2, directories.Count()); + Assert.IsTrue(directories.Contains(@"A:\folder1\folder2\")); + Assert.IsTrue(directories.Contains(@"A:\folder1\folder4\")); } } } \ No newline at end of file diff --git a/TestHelpers.Tests/MockFileTests.cs b/TestHelpers.Tests/MockFileTests.cs index 43a51a9ca..ae24c28dd 100644 --- a/TestHelpers.Tests/MockFileTests.cs +++ b/TestHelpers.Tests/MockFileTests.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using NUnit.Framework; +using System.Linq; namespace System.IO.Abstractions.TestingHelpers.Tests { @@ -570,19 +571,70 @@ public void MockFile_Copy_ShouldThrowExceptionWhenFileExistsAtDestination() Assert.Throws(() => fileSystem.File.Copy(sourceFileName, destFileName), @"The file c:\destination\demo.txt already exists."); } + [Test] + public void MockFile_Delete_ShouldRemoveFileFromFileSystem() + { + const string fullPath = @"c:\something\demo.txt"; + var fileSystem = new MockFileSystem(new Dictionary + { + { fullPath, new MockFileData("Demo text content") } + }); + + var file = new MockFile(fileSystem); + + file.Delete(fullPath); + + Assert.That(fileSystem.FileExists(fullPath), Is.False); + } + + [Test] + public void Mockfile_Create_ShouldCreateNewStream() + { + const string fullPath = @"c:\something\demo.txt"; + var fileSystem = new MockFileSystem(new Dictionary()); + + var sut = new MockFile(fileSystem); + + Assert.That(fileSystem.FileExists(fullPath), Is.False); + + sut.Create(fullPath).Close(); + + Assert.That(fileSystem.FileExists(fullPath), Is.True); + } + + [Test] + public void Mockfile_Create_CanWriteToNewStream() + { + const string fullPath = @"c:\something\demo.txt"; + var fileSystem = new MockFileSystem(new Dictionary()); + var data = new UTF8Encoding(false).GetBytes("Test string"); + + var sut = new MockFile(fileSystem); + using (var stream = sut.Create(fullPath)) + { + stream.Write(data, 0, data.Length); + } + + var mockFileData = fileSystem.GetFile(fullPath); + var fileData = mockFileData.Contents; + + Assert.That(fileData, Is.EqualTo(data)); + } + [Test] public void MockFile_Delete_Should_RemoveFiles() { const string filePath = @"c:\something\demo.txt"; const string fileContent = "this is some content"; - var fileSystem = new MockFileSystem(new Dictionary{{filePath, new MockFileData(fileContent) }}); + var fileSystem = new MockFileSystem(new Dictionary { { filePath, new MockFileData(fileContent) } }); Assert.AreEqual(1, fileSystem.AllFiles.Count()); fileSystem.File.Delete(filePath); Assert.AreEqual(0, fileSystem.AllFiles.Count()); } [Test] - public void MockFile_Delete_No_File_Does_Nothing() { + public void MockFile_Delete_No_File_Does_Nothing() + { const string filePath = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary()); fileSystem.File.Delete(filePath); diff --git a/TestHelpers.Tests/TestHelpers.Tests.csproj b/TestHelpers.Tests/TestHelpers.Tests.csproj index 61ef2205c..1a7647545 100644 --- a/TestHelpers.Tests/TestHelpers.Tests.csproj +++ b/TestHelpers.Tests/TestHelpers.Tests.csproj @@ -59,14 +59,9 @@ ..\StrongName.pfx - - ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll - - - ..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll - - - ..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll + + False + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll diff --git a/TestHelpers.Tests/packages.config b/TestHelpers.Tests/packages.config index 27a381975..617647af2 100644 --- a/TestHelpers.Tests/packages.config +++ b/TestHelpers.Tests/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/TestingHelpers/MockDirectory.cs b/TestingHelpers/MockDirectory.cs index 78404d8ee..ec3f788f1 100644 --- a/TestingHelpers/MockDirectory.cs +++ b/TestingHelpers/MockDirectory.cs @@ -25,8 +25,15 @@ public override DirectoryInfoBase CreateDirectory(string path) public override DirectoryInfoBase CreateDirectory(string path, DirectorySecurity directorySecurity) { path = EnsurePathEndsWithDirectorySeparator(path); - mockFileDataAccessor.AddFile(path, new MockDirectoryData()); - return new MockDirectoryInfo(mockFileDataAccessor, path); + if (!Exists(path)) + mockFileDataAccessor.AddFile(path, new MockDirectoryData()); + var created = new MockDirectoryInfo(mockFileDataAccessor, path); + + var parent = GetParent(path); + if (parent != null) + CreateDirectory(GetParent(path).FullName, directorySecurity); + + return created; } public override void Delete(string path) @@ -55,8 +62,10 @@ public override void Delete(string path, bool recursive) public override bool Exists(string path) { - path = EnsurePathEndsWithDirectorySeparator(path); - return mockFileDataAccessor.AllPaths.Any(p => p.StartsWith(path)); + if (!path.EndsWith(Path.DirectorySeparatorChar.ToString())) + path += Path.DirectorySeparatorChar; + + return mockFileDataAccessor.AllDirectories.Any(p => p.Equals(path, StringComparison.InvariantCultureIgnoreCase)); } public override DirectorySecurity GetAccessControl(string path) @@ -96,7 +105,11 @@ public override string[] GetDirectories(string path, string searchPattern) public override string[] GetDirectories(string path, string searchPattern, SearchOption searchOption) { - return getFilesInternal(mockFileDataAccessor.AllDirectories, path, searchPattern, searchOption); + if (!path.EndsWith(Path.DirectorySeparatorChar.ToString())) + path += Path.DirectorySeparatorChar; + + var dirs = getFilesInternal(mockFileDataAccessor.AllDirectories, path, searchPattern, searchOption); + return dirs.Where(p => p != path).ToArray(); } public override string GetDirectoryRoot(string path) @@ -129,7 +142,7 @@ public string[] getFilesInternal(IEnumerable files, string path, string const string allDirectoriesPattern = @"([\w\d\s-\.]*\\)*"; var fileNamePattern = searchPattern == "*" - ? @"[^\\]*?" + ? @"[^\\]*?\\?" : Regex.Escape(searchPattern) .Replace(@"\*", @"[\w\d\s-\.]*?") .Replace(@"\?", @"[\w\d\s-\.]?"); @@ -152,7 +165,10 @@ public override string[] GetFileSystemEntries(string path) public override string[] GetFileSystemEntries(string path, string searchPattern) { - return GetDirectories(path, searchPattern).Union(GetFiles(path, searchPattern)).ToArray(); + var dirs = GetDirectories(path, searchPattern); + var files = GetFiles(path, searchPattern); + + return dirs.Union(files).ToArray(); } public override DateTime GetLastAccessTime(string path) @@ -182,7 +198,11 @@ public override string[] GetLogicalDrives() public override DirectoryInfoBase GetParent(string path) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + var parent = new DirectoryInfo(path).Parent; + if (parent == null) + return null; + + return new MockDirectoryInfo(mockFileDataAccessor, parent.FullName); } public override void Move(string sourceDirName, string destDirName) { diff --git a/TestingHelpers/MockDirectoryInfo.cs b/TestingHelpers/MockDirectoryInfo.cs index f62d38944..f7b4425e3 100644 --- a/TestingHelpers/MockDirectoryInfo.cs +++ b/TestingHelpers/MockDirectoryInfo.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Security.AccessControl; namespace System.IO.Abstractions.TestingHelpers @@ -11,6 +12,9 @@ public class MockDirectoryInfo : DirectoryInfoBase public MockDirectoryInfo(IMockFileDataAccessor mockFileDataAccessor, string directoryPath) { + if (!directoryPath.EndsWith(Path.DirectorySeparatorChar.ToString())) + directoryPath += Path.DirectorySeparatorChar; + this.mockFileDataAccessor = mockFileDataAccessor; this.directoryPath = directoryPath; } @@ -26,13 +30,12 @@ public override void Delete() public override void Refresh() { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } public override FileAttributes Attributes { - get { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } - set { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } + get { return MockFileData.Attributes; } + set { MockFileData.Attributes = value; } } public override DateTime CreationTime @@ -49,7 +52,7 @@ public override DateTime CreationTimeUtc public override bool Exists { - get { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } + get { return mockFileDataAccessor.Directory.Exists(FullName); } } public override string Extension @@ -96,68 +99,82 @@ public override string Name public override void Create() { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.Directory.CreateDirectory(FullName); } public override void Create(DirectorySecurity directorySecurity) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.Directory.CreateDirectory(FullName, directorySecurity); } public override DirectoryInfoBase CreateSubdirectory(string path) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return mockFileDataAccessor.Directory.CreateDirectory(Path.Combine(FullName, path)); } public override DirectoryInfoBase CreateSubdirectory(string path, DirectorySecurity directorySecurity) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return mockFileDataAccessor.Directory.CreateDirectory(Path.Combine(FullName, path), directorySecurity); } public override void Delete(bool recursive) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.Directory.Delete(directoryPath, recursive); } public override DirectorySecurity GetAccessControl() { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return mockFileDataAccessor.Directory.GetAccessControl(directoryPath); } public override DirectorySecurity GetAccessControl(AccessControlSections includeSections) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return mockFileDataAccessor.Directory.GetAccessControl(directoryPath, includeSections); } public override DirectoryInfoBase[] GetDirectories() { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return ConvertStringsToDirectories(mockFileDataAccessor.Directory.GetDirectories(directoryPath)); } public override DirectoryInfoBase[] GetDirectories(string searchPattern) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return ConvertStringsToDirectories(mockFileDataAccessor.Directory.GetDirectories(directoryPath, searchPattern)); } public override DirectoryInfoBase[] GetDirectories(string searchPattern, SearchOption searchOption) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return ConvertStringsToDirectories(mockFileDataAccessor.Directory.GetDirectories(directoryPath, searchPattern, searchOption)); } - public override FileInfoBase[] GetFiles() { - return - this.mockFileDataAccessor.Directory.GetFiles(directoryPath) - .Select(this.mockFileDataAccessor.FileInfo.FromFileName).ToArray(); + private DirectoryInfoBase[] ConvertStringsToDirectories(IEnumerable paths) + { + return paths + .Select(path => new MockDirectoryInfo(mockFileDataAccessor, path)) + .Cast() + .ToArray(); + } + + public override FileInfoBase[] GetFiles() + { + return ConvertStringsToFiles(mockFileDataAccessor.Directory.GetFiles(FullName)); } public override FileInfoBase[] GetFiles(string searchPattern) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return ConvertStringsToFiles(mockFileDataAccessor.Directory.GetFiles(FullName, searchPattern)); } public override FileInfoBase[] GetFiles(string searchPattern, SearchOption searchOption) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + return ConvertStringsToFiles(mockFileDataAccessor.Directory.GetFiles(FullName, searchPattern, searchOption)); + } + + FileInfoBase[] ConvertStringsToFiles(IEnumerable paths) + { + return paths + .Select(mockFileDataAccessor.FileInfo.FromFileName) + .ToArray(); } public override FileSystemInfoBase[] GetFileSystemInfos() @@ -172,17 +189,20 @@ public override FileSystemInfoBase[] GetFileSystemInfos(string searchPattern) public override void MoveTo(string destDirName) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.Directory.Move(directoryPath, destDirName); } public override void SetAccessControl(DirectorySecurity directorySecurity) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.Directory.SetAccessControl(directoryPath, directorySecurity); } public override DirectoryInfoBase Parent { - get { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } + get + { + return mockFileDataAccessor.Directory.GetParent(directoryPath); + } } public override DirectoryInfoBase Root diff --git a/TestingHelpers/MockFile.cs b/TestingHelpers/MockFile.cs index df4b3f22e..6ce028ae4 100644 --- a/TestingHelpers/MockFile.cs +++ b/TestingHelpers/MockFile.cs @@ -59,7 +59,9 @@ public override void Copy(string sourceFileName, string destFileName, bool overw public override Stream Create(string path) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileDataAccessor.AddFile(path, new MockFileData(new byte[0])); + var stream = OpenWrite(path); + return stream; } public override Stream Create(string path, int bufferSize) @@ -89,7 +91,7 @@ public override void Decrypt(string path) public override void Delete(string path) { - mockFileDataAccessor.RemoveFile(path); + mockFileDataAccessor.RemoveFile(path); } public override void Encrypt(string path) diff --git a/TestingHelpers/MockFileData.cs b/TestingHelpers/MockFileData.cs index 8388bd820..628294638 100644 --- a/TestingHelpers/MockFileData.cs +++ b/TestingHelpers/MockFileData.cs @@ -13,6 +13,8 @@ public class MockFileData DateTimeOffset lastAccessTime = new DateTimeOffset(2010, 02, 04, 00, 00, 00, TimeSpan.FromHours(4)); DateTimeOffset lastWriteTime = new DateTimeOffset(2010, 01, 04, 00, 00, 00, TimeSpan.FromHours(4)); + private FileAttributes attributes = FileAttributes.Normal; + public virtual bool IsDirectory { get { return false; } } public MockFileData(string textContents) @@ -58,8 +60,15 @@ public DateTimeOffset LastWriteTime { return new MockFileData(s); } + + public FileAttributes Attributes + { + get { return attributes; } + set { attributes = value; } + } } + [Serializable] public class MockDirectoryData : MockFileData { public override bool IsDirectory { get { return true; } } diff --git a/TestingHelpers/MockFileInfo.cs b/TestingHelpers/MockFileInfo.cs index 2db85306d..1f881e986 100644 --- a/TestingHelpers/MockFileInfo.cs +++ b/TestingHelpers/MockFileInfo.cs @@ -21,7 +21,7 @@ MockFileData MockFileData public override void Delete() { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + mockFileSystem.RemoveFile(path); } public override void Refresh() @@ -30,8 +30,13 @@ public override void Refresh() public override FileAttributes Attributes { - get { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } - set { throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); } + get + { + if (MockFileData == null) + throw new FileNotFoundException("File not found", path); + return MockFileData.Attributes; + } + set { MockFileData.Attributes = value; } } public override DateTime CreationTime @@ -108,12 +113,14 @@ public override StreamWriter AppendText() public override FileInfoBase CopyTo(string destFileName) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + new MockFile(mockFileSystem).Copy(FullName, destFileName); + return mockFileSystem.FileInfo.FromFileName(destFileName); } - + public override FileInfoBase CopyTo(string destFileName, bool overwrite) { - throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all."); + new MockFile(mockFileSystem).Copy(FullName, destFileName, overwrite); + return mockFileSystem.FileInfo.FromFileName(destFileName); } public override Stream Create() diff --git a/TestingHelpers/MockFileSystem.cs b/TestingHelpers/MockFileSystem.cs index a66fc55a4..a631cdb84 100644 --- a/TestingHelpers/MockFileSystem.cs +++ b/TestingHelpers/MockFileSystem.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace System.IO.Abstractions.TestingHelpers @@ -15,15 +16,24 @@ public class MockFileSystem : IFileSystem, IMockFileDataAccessor public MockFileSystem(IDictionary files) { - this.files = new Dictionary( - files, - StringComparer.InvariantCultureIgnoreCase); - 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(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 FileBase File diff --git a/TestingHelpers/TestingHelpers.csproj b/TestingHelpers/TestingHelpers.csproj index db95f4fb7..3eb5b66d9 100644 --- a/TestingHelpers/TestingHelpers.csproj +++ b/TestingHelpers/TestingHelpers.csproj @@ -31,6 +31,8 @@ false false true + ..\ + true true @@ -112,6 +114,7 @@ +