本文整理汇总了C#中MockFileSystem类的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem类的具体用法?C# MockFileSystem怎么用?C# MockFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockFileSystem类属于命名空间,在下文中一共展示了MockFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Directories_On_Different_FileSystems_Are_Not_Equal
public void Directories_On_Different_FileSystems_Are_Not_Equal()
{
var dirA = FileSystem.DirectoryDescribing(@"c:\path\to");
var dirB = new MockFileSystem().DirectoryDescribing(@"c:\path\to");
AssertEqualityNotEquals(dirA, dirB);
AssertOperatorNotEquals(dirA, dirB);
}
示例2: Mockfile_Create_OverwritesExistingFile
public void Mockfile_Create_OverwritesExistingFile()
{
string path = XFS.Path(@"c:\some\file.txt");
var fileSystem = new MockFileSystem();
var mockFile = new MockFile(fileSystem);
fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(path));
// Create a file
using (var stream = mockFile.Create(path))
{
var contents = new UTF8Encoding(false).GetBytes("Test 1");
stream.Write(contents, 0, contents.Length);
}
// Create new file that should overwrite existing file
var expectedContents = new UTF8Encoding(false).GetBytes("Test 2");
using (var stream = mockFile.Create(path))
{
stream.Write(expectedContents, 0, expectedContents.Length);
}
var actualContents = fileSystem.GetFile(path).Contents;
Assert.That(actualContents, Is.EqualTo(expectedContents));
}
示例3: MockFileInfo_Length_ShouldThrowFileNotFoundExcpetionIfFileDoesNotExistInMemoryFileSystem
public void MockFileInfo_Length_ShouldThrowFileNotFoundExcpetionIfFileDoesNotExistInMemoryFileSystem()
{
// Arrange
const string fileContent = "Demo text content";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\a.txt", new MockFileData(fileContent) },
{ @"c:\a\b\c.txt", new MockFileData(fileContent) },
});
var fileInfo = new MockFileInfo(fileSystem, @"c:\foo.txt");
try
{
// Act
fileInfo.Length.ToString();
// Assert
Assert.Fail("Expected exception was not thrown");
}
catch (FileNotFoundException ex)
{
// Assert
Assert.AreEqual(@"c:\foo.txt", ex.FileName);
}
}
示例4: MockFileSystem
public void MockDirectory_GetFiles_ShouldReturnFilesDirectlyBelowPathWhenPatternIsWildcardAndSearchOptionIsTopDirectoryOnly()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\a.txt", new MockFileData("Demo text content") },
{ @"c:\b.txt", new MockFileData("Demo text content") },
{ @"c:\c.txt", new MockFileData("Demo text content") },
{ @"c:\a\a.txt", new MockFileData("Demo text content") },
{ @"c:\a\b.txt", new MockFileData("Demo text content") },
{ @"c:\a\c.txt", new MockFileData("Demo text content") },
{ @"c:\a\a\a.txt", new MockFileData("Demo text content") },
{ @"c:\a\a\b.txt", new MockFileData("Demo text content") },
{ @"c:\a\a\c.txt", new MockFileData("Demo text content") },
});
// Act
var result = fileSystem.Directory.GetFiles(@"c:\a", "*", SearchOption.TopDirectoryOnly);
// Assert
CollectionAssert.AreEqual
(
new[]
{
@"c:\a\a.txt",
@"c:\a\b.txt",
@"c:\a\c.txt"
},
result
);
}
示例5: Files_On_Different_FileSystems_Are_Not_Equal
public void Files_On_Different_FileSystems_Are_Not_Equal()
{
var fileA = FileSystem.FileDescribing(@"c:\path\to\file.txt");
var fileB = new MockFileSystem().FileDescribing(@"c:\path\to\file.txt");
AssertEqualityNotEquals(fileA, fileB);
AssertOperatorNotEquals(fileA, fileB);
}
示例6: MyTestInitialize
public void MyTestInitialize()
{
_fileSystem = new MockFileSystem();
var mockExifReader = new MockExifReader(_fileSystem);
_directoryFactory = new PictureDirectoryFactory(_fileSystem, mockExifReader);
_fileHandlerFactory = new FileHandlerFactory(_fileSystem);
}
示例7: MockFile_Open_ThrowsOnTruncateWithMissingFile
public void MockFile_Open_ThrowsOnTruncateWithMissingFile()
{
string filepath = XFS.Path(@"c:\something\doesnt\exist.txt");
var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());
Assert.Throws<FileNotFoundException>(() => filesystem.File.Open(filepath, FileMode.Truncate));
}
示例8: MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding
public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding()
{
// Arrange
const string path = @"c:\something\demo.txt";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ path, new MockFileData("Demo text content") }
});
var file = new MockFile(fileSystem);
// Act
file.AppendAllText(path, "+ some text", Encoding.BigEndianUnicode);
// Assert
var expected = new byte[]
{
68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116,
101, 110, 255, 253, 0, 43, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101,
0, 32, 0, 116, 0, 101, 0, 120, 0, 116
};
CollectionAssert.AreEqual(
expected,
file.ReadAllBytes(path));
}
示例9: MockFile_Move_ShouldThrowArgumentNullExceptionWhenSourceIsNull_ParamName
public void MockFile_Move_ShouldThrowArgumentNullExceptionWhenSourceIsNull_ParamName() {
string destFilePath = XFS.Path(@"c:\something\demo.txt");
var fileSystem = new MockFileSystem();
var exception = Assert.Throws<ArgumentNullException>(() => fileSystem.File.Move(null, destFilePath));
Assert.That(exception.ParamName, Is.EqualTo("sourceFileName"));
}
示例10: MockFile_Copy_ShouldThrowArgumentNullExceptionWhenSourceIsNull_Message
public void MockFile_Copy_ShouldThrowArgumentNullExceptionWhenSourceIsNull_Message()
{
string destFilePath = XFS.Path(@"c:\something\demo.txt");
var fileSystem = new MockFileSystem();
var exception = Assert.Throws<ArgumentNullException>(() => fileSystem.File.Copy(null, destFilePath));
Assert.That(exception.Message, Is.StringStarting("File name cannot be null."));
}
示例11: MockFile_Open_ThrowsOnCreateNewWithExistingFile
public void MockFile_Open_ThrowsOnCreateNewWithExistingFile()
{
string filepath = XFS.Path(@"c:\something\already\exists.txt");
var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ filepath, new MockFileData("I'm here") }
});
Assert.Throws<IOException>(() => filesystem.File.Open(filepath, FileMode.CreateNew));
}
示例12: CreateNewDirectoryWithRenameAttemptsDateTest
public void CreateNewDirectoryWithRenameAttemptsDateTest()
{
MockFileSystem mockFileSystem = new MockFileSystem();
FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
Assert.AreEqual(1, mockFileSystem.DirectoryCount);
Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012"));
FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
Assert.AreEqual(2, mockFileSystem.DirectoryCount);
Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012 (2)"));
}
示例13: MockFile_WriteAllText_ShouldThrowAnArgumentExceptionIfThePathIsEmpty
public void MockFile_WriteAllText_ShouldThrowAnArgumentExceptionIfThePathIsEmpty()
{
// Arrange
var fileSystem = new MockFileSystem();
// Act
TestDelegate action = () => fileSystem.File.WriteAllText(string.Empty, "hello world");
// Assert
Assert.Throws<ArgumentException>(action);
}
示例14: MockFile_Open_CreatesNewFileFileOnCreateNew
public void MockFile_Open_CreatesNewFileFileOnCreateNew()
{
string filepath = XFS.Path(@"c:\something\doesnt\exist.txt");
var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());
var stream = filesystem.File.Open(filepath, FileMode.CreateNew);
Assert.That(filesystem.File.Exists(filepath), Is.True);
Assert.That(stream.Position, Is.EqualTo(0));
Assert.That(stream.Length, Is.EqualTo(0));
}
示例15: MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath
public void MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath(string driveName)
{
// Arrange
var fileSystem = new MockFileSystem();
// Act
TestDelegate action = () => new MockDriveInfo(fileSystem, XFS.Path(driveName));
// Assert
Assert.Throws<ArgumentException>(action);
}