本文整理汇总了C#中MockFile.AppendAllText方法的典型用法代码示例。如果您正苦于以下问题:C# MockFile.AppendAllText方法的具体用法?C# MockFile.AppendAllText怎么用?C# MockFile.AppendAllText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFile
的用法示例。
在下文中一共展示了MockFile.AppendAllText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding
public void MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding()
{
// Arrange
const string Path = @"c:\something\demo.txt";
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{Path, new MockFileData("AA", Encoding.UTF32)}
});
var file = new MockFile(fileSystem);
// Act
file.AppendAllText(Path, "BB", Encoding.UTF8);
// Assert
CollectionAssert.AreEqual(
new byte[] {255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66},
fileSystem.GetFile(Path).Contents);
}
示例3: 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));
}