本文整理汇总了C#中MockFileSystem.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.FileExists方法的具体用法?C# MockFileSystem.FileExists怎么用?C# MockFileSystem.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFileSystem
的用法示例。
在下文中一共展示了MockFileSystem.FileExists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mockfile_Create_ShouldCreateNewStream
public void Mockfile_Create_ShouldCreateNewStream()
{
string fullPath = XFS.Path(@"c:\something\demo.txt");
var fileSystem = new MockFileSystem();
var sut = new MockFile(fileSystem);
Assert.That(fileSystem.FileExists(fullPath), Is.False);
sut.Create(fullPath).Close();
Assert.That(fileSystem.FileExists(fullPath), Is.True);
}
示例2: MockFile_Move_ShouldMoveFileWithinMemoryFileSystem
public void MockFile_Move_ShouldMoveFileWithinMemoryFileSystem()
{
string sourceFilePath = XFS.Path(@"c:\something\demo.txt");
string sourceFileContent = "this is some content";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{sourceFilePath, new MockFileData(sourceFileContent)},
{XFS.Path(@"c:\somethingelse\dummy.txt"), new MockFileData(new byte[] {0})}
});
string destFilePath = XFS.Path(@"c:\somethingelse\demo1.txt");
fileSystem.File.Move(sourceFilePath, destFilePath);
Assert.That(fileSystem.FileExists(destFilePath), Is.True);
Assert.That(fileSystem.GetFile(destFilePath).TextContents, Is.EqualTo(sourceFileContent));
Assert.That(fileSystem.FileExists(sourceFilePath), Is.False);
}
示例3: MockDirectory_CreateDirectory_ShouldCreatePlaceholderFileInMemoryFileSystem
public void MockDirectory_CreateDirectory_ShouldCreatePlaceholderFileInMemoryFileSystem()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\foo.txt", new MockFileData("Demo text content") }
});
// Act
fileSystem.Directory.CreateDirectory(@"c:\bar");
// Assert
Assert.IsTrue(fileSystem.FileExists(@"c:\bar\__PLACEHOLDER__.dir"));
}
示例4: MockDirectory_CreateDirectory_ShouldCreateFolderInMemoryFileSystem
public void MockDirectory_CreateDirectory_ShouldCreateFolderInMemoryFileSystem()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\foo.txt"), new MockFileData("Demo text content") }
});
// Act
fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\bar"));
// Assert
Assert.IsTrue(fileSystem.FileExists(XFS.Path(@"c:\bar\")));
Assert.IsTrue(fileSystem.AllDirectories.Any(d => d == XFS.Path(@"c:\bar\")));
}
示例5: MockFile_Delete_ShouldRemoveFileFromFileSystem
public void MockFile_Delete_ShouldRemoveFileFromFileSystem()
{
const string fullPath = @"c:\something\demo.txt";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ fullPath, new MockFileData("Demo text content") }
});
var file = new MockFile(fileSystem);
file.Delete(fullPath);
Assert.That(fileSystem.FileExists(fullPath), Is.False);
}
示例6: MockFile_OpenWrite_ShouldOverwriteExistingFiles
public void MockFile_OpenWrite_ShouldOverwriteExistingFiles()
{
const string filePath = @"c:\something\demo.txt";
const string startFileContent = "this is some content";
const string endFileContent = "this is some other content";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{filePath, new MockFileData(startFileContent)}
});
var bytes = new UTF8Encoding(true).GetBytes(endFileContent);
var stream = fileSystem.File.OpenWrite(filePath);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
Assert.That(fileSystem.FileExists(filePath), Is.True);
Assert.That(fileSystem.GetFile(filePath).TextContents, Is.EqualTo(endFileContent));
}
示例7: MockFile_OpenWrite_ShouldCreateNewFiles
public void MockFile_OpenWrite_ShouldCreateNewFiles() {
const string filePath = @"c:\something\demo.txt";
const string fileContent = "this is some content";
var fileSystem = new MockFileSystem();
var bytes = new UTF8Encoding(true).GetBytes(fileContent);
var stream = fileSystem.File.OpenWrite(filePath);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
Assert.That(fileSystem.FileExists(filePath), Is.True);
Assert.That(fileSystem.GetFile(filePath).TextContents, Is.EqualTo(fileContent));
}
示例8: MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile
public void MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile()
{
string filepath = XFS.Path(@"c:\something\doesnt\exist.txt");
var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());
var stream = filesystem.File.AppendText(filepath);
stream.Write("New too!");
stream.Flush();
stream.Close();
var file = filesystem.GetFile(filepath);
Assert.That(file.TextContents, Is.EqualTo("New too!"));
Assert.That(filesystem.FileExists(filepath));
}
示例9: GetTempFileName_Called_CreatesEmptyFileInTempDirectory
public void GetTempFileName_Called_CreatesEmptyFileInTempDirectory()
{
//Arrange
var fileSystem = new MockFileSystem();
var mockPath = new MockPath(fileSystem);
//Creating directory explicitly because in normal system Tempory path always exist.
fileSystem.Directory.CreateDirectory(mockPath.GetTempPath());
//Act
var result = mockPath.GetTempFileName();
Assert.True(fileSystem.FileExists(result));
Assert.AreEqual(0, fileSystem.FileInfo.FromFileName(result).Length);
}
示例10: Mockfile_Create_ShouldCreateNewStream
public void Mockfile_Create_ShouldCreateNewStream()
{
const string fullPath = @"c:\something\demo.txt";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
var sut = new MockFile(fileSystem);
Assert.That(fileSystem.FileExists(fullPath), Is.False);
sut.Create(fullPath).Close();
Assert.That(fileSystem.FileExists(fullPath), Is.True);
}
示例11: GetTempFileName_Called_CreatesEmptyFileInTempDirectory
public void GetTempFileName_Called_CreatesEmptyFileInTempDirectory()
{
//Arrange
var fileSystem = new MockFileSystem();
var mockPath = new MockPath(fileSystem);
//Act
var result = mockPath.GetTempFileName();
Assert.True(fileSystem.FileExists(result));
Assert.AreEqual(0, fileSystem.FileInfo.FromFileName(result).Length);
}