本文整理汇总了C#中MockFileSystem.AddFileWithCreate方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.AddFileWithCreate方法的具体用法?C# MockFileSystem.AddFileWithCreate怎么用?C# MockFileSystem.AddFileWithCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFileSystem
的用法示例。
在下文中一共展示了MockFileSystem.AddFileWithCreate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MockFile_Delete_ShouldDeleteFile
public void MockFile_Delete_ShouldDeleteFile()
{
var fileSystem = new MockFileSystem();
var path = XFS.Path("C:\\test");
var directory = fileSystem.Path.GetDirectoryName(path);
fileSystem.AddFileWithCreate(path, new MockFileData("Bla"));
var fileCount1 = fileSystem.Directory.GetFiles(directory, "*").Length;
fileSystem.File.Delete(path);
var fileCount2 = fileSystem.Directory.GetFiles(directory, "*").Length;
Assert.AreEqual(1, fileCount1, "File should have existed");
Assert.AreEqual(0, fileCount2, "File should have been deleted");
}
示例2: MockFileStream_Dispose_ShouldNotResurrectFile
public void MockFileStream_Dispose_ShouldNotResurrectFile()
{
var fileSystem = new MockFileSystem();
var path = XFS.Path("C:\\test");
var directory = fileSystem.Path.GetDirectoryName(path);
fileSystem.AddFileWithCreate(path, new MockFileData("Bla"));
var stream = fileSystem.File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete);
var fileCount1 = fileSystem.Directory.GetFiles(directory, "*").Length;
fileSystem.File.Delete(path);
var fileCount2 = fileSystem.Directory.GetFiles(directory, "*").Length;
stream.Dispose();
var fileCount3 = fileSystem.Directory.GetFiles(directory, "*").Length;
Assert.AreEqual(1, fileCount1, "File should have existed");
Assert.AreEqual(0, fileCount2, "File should have been deleted");
Assert.AreEqual(0, fileCount3, "Disposing stream should not have resurrected the file");
}
示例3: MockFileInfo_OpenText_ShouldReturnStringContentOfFile
public void MockFileInfo_OpenText_ShouldReturnStringContentOfFile()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFileWithCreate(XFS.Path(@"c:\temp\file.txt"), new MockFileData(@"line 1\r\nline 2"));
var fileInfo = fileSystem.FileInfo.FromFileName(XFS.Path(@"c:\temp\file.txt"));
// Act
string result;
using (var streamReader = fileInfo.OpenText())
{
result = streamReader.ReadToEnd();
}
Assert.AreEqual(@"line 1\r\nline 2", result);
}
示例4: MockFileInfo_OpenRead_ShouldReturnByteContentOfFile
public void MockFileInfo_OpenRead_ShouldReturnByteContentOfFile()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFileWithCreate(XFS.Path(@"c:\temp\file.txt"), new MockFileData(new byte[] { 1, 2 }));
var fileInfo = fileSystem.FileInfo.FromFileName(XFS.Path(@"c:\temp\file.txt"));
// Act
byte[] result = new byte[2];
using (var stream = fileInfo.OpenRead())
{
stream.Read(result, 0, 2);
}
Assert.AreEqual(new byte[] { 1, 2 }, result);
}
示例5: MockFile_OpenText_ShouldRetainCreationTime
public void MockFile_OpenText_ShouldRetainCreationTime()
{
// Arrange
var fs = new MockFileSystem();
string filepath = XFS.Path(@"C:\TestData\test.txt");
var file = new MockFileData(@"I'm here");
var creationTime = new DateTime(2012, 03, 21);
file.CreationTime = creationTime;
fs.AddFileWithCreate(filepath, file);
// Act
using (var reader = fs.File.OpenText(filepath))
{
reader.ReadLine();
}
// Assert
Assert.AreEqual(creationTime, fs.FileInfo.FromFileName(filepath).CreationTime);
}
示例6: MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem
public void MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFileWithCreate(XFS.Path(@"c:\foo\bar.txt"), new MockFileData("Demo text content"));
// Act
var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo\"));
// Assert
Assert.IsTrue(result);
}