public void TestAppendText() { _gridFS.Delete(Query.Null); Assert.IsFalse(_gridFS.Exists("HelloWorld.txt")); using (var writer = _gridFS.AppendText("HelloWorld.txt")) { Assert.IsFalse(writer.BaseStream.CanRead); Assert.IsTrue(writer.BaseStream.CanSeek); Assert.IsTrue(writer.BaseStream.CanWrite); writer.Write("Hello"); } Assert.IsTrue(_gridFS.Exists("HelloWorld.txt")); using (var writer = _gridFS.AppendText("HelloWorld.txt")) { writer.Write(" World"); } var memoryStream = new MemoryStream(); _gridFS.Download(memoryStream, "HelloWorld.txt"); var bytes = memoryStream.ToArray(); Assert.AreEqual(0xEF, bytes[0]); // the BOM Assert.AreEqual(0xBB, bytes[1]); Assert.AreEqual(0xBF, bytes[2]); var text = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3); Assert.AreEqual("Hello World", text); }
public void AppendTextTest() { Assert.IsFalse(gridFS.Exists("HelloWorld.txt")); using (var writer = gridFS.AppendText("HelloWorld.txt")) { Assert.IsFalse(writer.BaseStream.CanRead); Assert.IsTrue(writer.BaseStream.CanSeek); Assert.IsTrue(writer.BaseStream.CanWrite); writer.Write("동해물과"); } Assert.IsTrue(gridFS.Exists("HelloWorld.txt")); using (var writer = gridFS.AppendText("HelloWorld.txt")) { writer.Write(" 백두산이"); } var memoryStream = new MemoryStream(); gridFS.Download(memoryStream, "HelloWorld.txt"); var bytes = memoryStream.ToArray(); // 2-byte 문자열임을 나타내는 헤더값 StringTool.IsMultiByteString(bytes).Should().Be.True(); //Assert.AreEqual(0xEF, bytes[0]); // the BOM //Assert.AreEqual(0xBB, bytes[1]); //Assert.AreEqual(0xBF, bytes[2]); // Header 값을 빼고, 한다. // var text = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3); var text = memoryStream.ToText(Encoding.UTF8); Assert.AreEqual("동해물과 백두산이", text); }