本文整理汇总了C#中MockFile.Create方法的典型用法代码示例。如果您正苦于以下问题:C# MockFile.Create方法的具体用法?C# MockFile.Create怎么用?C# MockFile.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFile
的用法示例。
在下文中一共展示了MockFile.Create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: Mockfile_Create_ThrowsWhenPathIsReadOnly
public void Mockfile_Create_ThrowsWhenPathIsReadOnly()
{
string path = XFS.Path(@"c:\something\read-only.txt");
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Content") } });
var mockFile = new MockFile(fileSystem);
mockFile.SetAttributes(path, FileAttributes.ReadOnly);
var exception = Assert.Throws<UnauthorizedAccessException>(() => mockFile.Create(path).Close());
Assert.That(exception.Message, Is.EqualTo(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path)));
}
示例3: 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);
}
示例4: Mockfile_Create_CanWriteToNewStream
public void Mockfile_Create_CanWriteToNewStream()
{
string fullPath = XFS.Path(@"c:\something\demo.txt");
var fileSystem = new MockFileSystem();
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));
}
示例5: 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);
}