public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem() { // Arrange MockFileData fileData = new MockFileData("Demo text content"); MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); MockFileInfo fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); // Act using (StreamWriter file = fileInfo.AppendText()) { file.WriteLine("This should be at the end"); } string newcontents; using (StreamReader newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } // Assert Assert.Equal("Demo text contentThis should be at the end\r\n", newcontents); }
public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem() { var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); var bytesToAdd = new byte[] { 65, 66, 67, 68, 69 }; using (var file = fileInfo.OpenWrite()) { file.Write(bytesToAdd, 0, bytesToAdd.Length); } string newcontents; using (var newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } Assert.AreEqual("ABCDEtext content", newcontents); }
public void MockFileInfo_Decrypt_ShouldReturnCorrectContentsFileInMemoryFileSystem() { // Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); fileInfo.Encrypt(); // Act fileInfo.Decrypt(); string newcontents; using (var newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } // Assert Assert.AreEqual("Demo text content", newcontents); }
public void OpenText_MockFileDataopulated_ReturnsData() { //Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"z:\a.txt", fileData } }); var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt"); //Act var reader = fileInfo.OpenText(); var result = reader.ReadToEnd(); //Assert Assert.AreEqual("Demo text content", result); }
public void MockFileInfo_AppendText_ShouldCreateFileIfMissing() { var fileSystem = new MockFileSystem(); var targetFile = XFS.Path(@"c:\a.txt"); var fileInfo = new MockFileInfo(fileSystem, targetFile); using (var file = fileInfo.AppendText()) file.WriteLine("This should be the contents"); string newcontents; using (var newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } Assert.That(fileSystem.File.Exists(targetFile), Is.True); Assert.AreEqual($"This should be the contents{Environment.NewLine}", newcontents); }
public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem() { var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); using (var file = fileInfo.AppendText()) file.WriteLine("This should be at the end"); string newcontents; using (var newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } Assert.AreEqual($"Demo text contentThis should be at the end{Environment.NewLine}", newcontents); }
public void CreateText_DataSentIn_ShouldWriteToFile() { //Arrange var fileData = new MockFileData(""); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"z:\a.txt", fileData } }); var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt"); //Act var writer = fileInfo.CreateText(); writer.WriteLine("test"); writer.Close(); var reader = fileInfo.OpenText(); var result = reader.ReadToEnd(); //Assert Assert.AreEqual("test", result); }
public void MockFileInfo_Encrypt_ShouldReturnXorOfFileInMemoryFileSystem() { // Arrange MockFileData fileData = new MockFileData("Demo text content"); MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); MockFileInfo fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); // Act fileInfo.Encrypt(); string newcontents; using (StreamReader newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } // Assert Assert.NotEqual("Demo text content", newcontents); }
public void OpenText_MockFileDataopulated_ReturnsData() { //Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { @"z:\a.txt", fileData } }); var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt"); //Act var reader = fileInfo.OpenText(); var result = reader.ReadToEnd(); //Assert Assert.AreEqual("Demo text content", result); }
public void CreateText_DataSentIn_ShouldWriteToFile() { //Arrange var fileData = new MockFileData(""); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { @"z:\a.txt", fileData } }); var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt"); //Act var writer = fileInfo.CreateText(); writer.WriteLine("test"); writer.Close(); var reader = fileInfo.OpenText(); var result = reader.ReadToEnd(); //Assert Assert.AreEqual("test",result); }
public void MockFileInfo_Decrypt_ShouldReturnCorrectContentsFileInMemoryFileSystem() { // Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); fileInfo.Encrypt(); // Act fileInfo.Decrypt(); string newcontents; using (var newfile = fileInfo.OpenText()) { newcontents = newfile.ReadToEnd(); } // Assert Assert.AreEqual("Demo text content", newcontents); }
public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem() { // Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); var bytesToAdd = new byte[] {65, 66, 67, 68, 69}; // Act using (var file = fileInfo.OpenWrite()) file.Write(bytesToAdd, 0, bytesToAdd.Length); string newcontents; using (var newfile = fileInfo.OpenText()) newcontents = newfile.ReadToEnd(); // Assert Assert.AreEqual("ABCDEtext content", newcontents); }
public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem() { // Arrange var fileData = new MockFileData("Demo text content"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\a.txt"), fileData } }); var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt")); // Act using (var file = fileInfo.AppendText()) file.WriteLine("This should be at the end"); string newcontents; using (var newfile = fileInfo.OpenText()) newcontents = newfile.ReadToEnd(); // Assert Assert.AreEqual("Demo text contentThis should be at the end\r\n", newcontents); }