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));
        }
        public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding()
        {
            // 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", Encoding.BigEndianUnicode);

            // Assert
            var expected = new byte[]
            {
                68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116,
                101, 110, 116, 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));
        }
Example #3
0
        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
            fileSystem.GetFile(Path)
            .Contents.ShouldBeEquivalentTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 }, options => options.WithStrictOrdering());
        }
        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));
        }
        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);
        }
        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));
        }
        public void MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding()
        {
            // Arrange
            const string   PATH       = @"c:\something\demo.txt";
            MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { PATH, new MockFileData("AA", Encoding.UTF32) }
            });

            MockFile file = new MockFile(fileSystem);

            // Act
            file.AppendAllText(PATH, "BB", Encoding.UTF8);

            // Assert
            Assert.Equal(
                new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 },
                fileSystem.GetFile(PATH).Contents);
        }
Example #8
0
        public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding()
        {
            // 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", Encoding.BigEndianUnicode);

            // Assert
            var expected = new byte[]
            {
                68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116,
                101, 110, 116, 0, 43, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101,
                0, 32, 0, 116, 0, 101, 0, 120, 0, 116
            };

            if (XFS.IsUnixPlatform())
            {
                // Remove EOF on mono
                expected = new byte[]
                {
                    68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116,
                    101, 110, 0, 43, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101,
                    0, 32, 0, 116, 0, 101, 0, 120, 0, 116
                };
            }


            file.ReadAllBytes(path).ShouldBeEquivalentTo(expected, options => options.WithStrictOrdering());
        }