本文整理汇总了C#中MockFile.ReadAllText方法的典型用法代码示例。如果您正苦于以下问题:C# MockFile.ReadAllText方法的具体用法?C# MockFile.ReadAllText怎么用?C# MockFile.ReadAllText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFile
的用法示例。
在下文中一共展示了MockFile.ReadAllText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile
public void MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile()
{
// Arrange
string path = XFS.Path(@"c:\something\demo.txt");
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\something\"), new MockDirectoryData() }
});
var file = new MockFile(fileSystem);
// Act
file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" });
// Assert
Assert.AreEqual(
"line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine,
file.ReadAllText(path));
}
示例2: MockFile_AppendAllText_ShouldPersistNewText
public void MockFile_AppendAllText_ShouldPersistNewText()
{
// Arrange
string path = XFS.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");
// Assert
Assert.AreEqual(
"Demo text content+ some text",
file.ReadAllText(path));
}
示例3: MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding
public void MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding()
{
// Arrange
const string text = "Hello there!";
var encodedText = Encoding.BigEndianUnicode.GetBytes(text);
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\something\demo.txt", new MockFileData(encodedText) }
});
var file = new MockFile(fileSystem);
// Act
var result = file.ReadAllText(@"c:\something\demo.txt", Encoding.BigEndianUnicode);
// Assert
Assert.AreEqual(text, result);
}
示例4: MockFile_ReadAllText_ShouldReturnOriginalTextData
public void MockFile_ReadAllText_ShouldReturnOriginalTextData()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\something\demo.txt", new MockFileData("Demo text content") },
{ @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) }
});
var file = new MockFile(fileSystem);
// Act
var result = file.ReadAllText(@"c:\something\demo.txt");
// Assert
Assert.AreEqual(
"Demo text content",
result);
}