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_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);
        }
Beispiel #3
0
        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 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);
        }