public void WriteUTF32BEFileTest() { // Arrange. var fileName = "UTF32BE" + _fileName; var expectedResult = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse nisl."; if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } // Act. using (var immediateBuffer = new ImmediateBuffer(new File(fileName))) { immediateBuffer.FileInstance.SetInputEncoding(EncodingType.UTF32BE); immediateBuffer.FileInstance.SetOutputEncoding(EncodingType.UTF32BE); immediateBuffer.InsertAtCursor(expectedResult); immediateBuffer.DumpBufferToCurrentFile(); Assert.AreEqual(new UTF32Encoding(true, true).ToString(), immediateBuffer.FileInstance.InputEncoding.ToString()); Assert.AreEqual(new UTF32Encoding(true, true).ToString(), immediateBuffer.FileInstance.OutputEncoding.ToString()); } string actualResult; using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite)) { using var sw = new StreamReader(fs, new UTF32Encoding(true, true)); actualResult = sw.ReadToEnd(); } // Assert. Assert.IsTrue(string.Equals(expectedResult, actualResult, StringComparison.InvariantCulture), "The text returned by the buffer differs."); }
public void ReadUTF7FileTest() { // Arrange. var fileName = "UTF7" + _fileName; var expectedResult = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse nisl."; using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite)) { using var sw = new StreamWriter(fs, Encoding.UTF7); fs.Write(new byte[] { 0x2b, 0x2f, 0x76, 0x38 }); sw.Write(expectedResult); sw.Flush(); } // Act. using var immediateBuffer = new ImmediateBuffer(new File(fileName)); immediateBuffer.FillBufferFromFile(); var actualResult = immediateBuffer.GetBufferContent(); // Assert. Assert.AreEqual(Encoding.UTF7.ToString(), immediateBuffer.FileInstance.InputEncoding.ToString()); Assert.AreEqual(Encoding.UTF7.ToString(), immediateBuffer.FileInstance.OutputEncoding.ToString()); Assert.IsTrue(string.Equals(expectedResult, actualResult, StringComparison.InvariantCulture), "The text returned by the buffer differs."); }