当前位置: 首页>>代码示例>>C#>>正文


C# MockFileSystem.GetFile方法代码示例

本文整理汇总了C#中MockFileSystem.GetFile方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.GetFile方法的具体用法?C# MockFileSystem.GetFile怎么用?C# MockFileSystem.GetFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MockFileSystem的用法示例。


在下文中一共展示了MockFileSystem.GetFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MockFileSystem_AddFile_ShouldRepaceExistingFile

        public void MockFileSystem_AddFile_ShouldRepaceExistingFile()
        {
            const string path = @"c:\some\file.txt";
            const string existingContent = "Existing content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { path, new MockFileData(existingContent) }
            });
            Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(existingContent));

            const string newContent = "New content";
            fileSystem.AddFile(path, new MockFileData(newContent));

            Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(newContent));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileSystemTests.cs

示例2: Mockfile_Create_OverwritesExistingFile

        public void Mockfile_Create_OverwritesExistingFile()
        {
            string path = XFS.Path(@"c:\some\file.txt");
            var fileSystem = new MockFileSystem();

            var mockFile = new MockFile(fileSystem);

            fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(path));

            // Create a file
            using (var stream = mockFile.Create(path))
            {
                var contents = new UTF8Encoding(false).GetBytes("Test 1");
                stream.Write(contents, 0, contents.Length);
            }

            // Create new file that should overwrite existing file
            var expectedContents = new UTF8Encoding(false).GetBytes("Test 2");
            using (var stream = mockFile.Create(path))
            {
                stream.Write(expectedContents, 0, expectedContents.Length);
            }

            var actualContents = fileSystem.GetFile(path).Contents;

            Assert.That(actualContents, Is.EqualTo(expectedContents));
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:27,代码来源:MockFileCreateTests.cs

示例3: MockFileStream_Flush_WritesByteToFile

        public void MockFileStream_Flush_WritesByteToFile()
        {
            // Arrange
            var filepath = XFS.Path(@"c:\something\foo.txt");
            var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());
            var cut = new MockFileStream(filesystem, filepath);

            // Act
            cut.WriteByte(255);
            cut.Flush();

            // Assert
            CollectionAssert.AreEqual(new byte[]{255}, filesystem.GetFile(filepath).Contents);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:14,代码来源:MockFileStreamTests.cs

示例4: MockFile_Copy_ShouldCreateFileAtNewDestination

        public void MockFile_Copy_ShouldCreateFileAtNewDestination()
        {
            string sourceFileName = XFS.Path(@"c:\source\demo.txt");
            var sourceContents = new MockFileData("Source content");
            string destFileName = XFS.Path(@"c:\source\demo_copy.txt");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {sourceFileName, sourceContents}
            });

            fileSystem.File.Copy(sourceFileName, destFileName, false);

            var copyResult = fileSystem.GetFile(destFileName);
            Assert.AreEqual(copyResult.Contents, sourceContents.Contents);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileCopyTests.cs

示例5: MockFile_WriteAllBytes_ShouldWriteDataToMemoryFileSystem

        public void MockFile_WriteAllBytes_ShouldWriteDataToMemoryFileSystem()
        {
            // Arrange
            string path = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();
            var fileContent = new byte[] { 1, 2, 3, 4 };

            // Act
            fileSystem.File.WriteAllBytes(path, fileContent);

            // Assert
            Assert.AreEqual(
                fileContent,
                fileSystem.GetFile(path).Contents);
        }
开发者ID:johncmckim,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileWriteAllBytesTests.cs

示例6: MockFile_WriteAllText_ShouldOverriteAnExistingFile

        public void MockFile_WriteAllText_ShouldOverriteAnExistingFile()
        {
            // http://msdn.microsoft.com/en-us/library/ms143375.aspx

            // Arrange
            string path = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();

            // Act
            fileSystem.File.WriteAllText(path, "foo");
            fileSystem.File.WriteAllText(path, "bar");

            // Assert
            Assert.AreEqual("bar", fileSystem.GetFile(path).TextContents);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileWriteAllTextTests.cs

示例7: MockFile_WriteAllText_ShouldWriteTextFileToMemoryFileSystem

        public void MockFile_WriteAllText_ShouldWriteTextFileToMemoryFileSystem()
        {
            // Arrange
            string path = XFS.Path(@"c:\something\demo.txt");
            string fileContent = "Hello there!";
            var fileSystem = new MockFileSystem();

            // Act
            fileSystem.File.WriteAllText(path, fileContent);

            // Assert
            Assert.AreEqual(
                fileContent,
                fileSystem.GetFile(path).TextContents);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileWriteAllTextTests.cs

示例8: MockFileSystem_GetFile_ShouldReturnNullWhenFileIsNotRegistered

        public void MockFileSystem_GetFile_ShouldReturnNullWhenFileIsNotRegistered()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\something\demo.txt", new MockFileData("Demo\r\ntext\ncontent\rvalue") },
                { @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) }
            });

            // Act
            var result = fileSystem.GetFile(@"c:\something\else.txt");

            // Assert
            Assert.IsNull(result);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileSystemTests.cs

示例9: MockFile_Copy_ShouldOverwriteFileWhenOverwriteFlagIsTrue

        public void MockFile_Copy_ShouldOverwriteFileWhenOverwriteFlagIsTrue()
        {
            string sourceFileName = XFS.Path(@"c:\source\demo.txt");
            var sourceContents = new MockFileData("Source content");
            string destFileName = XFS.Path(@"c:\destination\demo.txt");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {sourceFileName, sourceContents},
                {destFileName, new MockFileData("Destination content")}
            });

            fileSystem.File.Copy(sourceFileName, destFileName, true);

            var copyResult = fileSystem.GetFile(destFileName);
            Assert.AreEqual(copyResult.Contents, sourceContents.Contents);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockFileCopyTests.cs

示例10: MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructorWhenPathsDifferByCase

        public void MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructorWhenPathsDifferByCase()
        {
            // Arrange
            var file1 = new MockFileData("Demo\r\ntext\ncontent\rvalue");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\something\demo.txt", file1 },
                { @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) }
            });

            // Act
            var result = fileSystem.GetFile(@"c:\SomeThing\DEMO.txt");

            // Assert
            Assert.AreEqual(file1, result);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockFileSystemTests.cs

示例11: Mockfile_Create_CanWriteToNewStream

        public void Mockfile_Create_CanWriteToNewStream()
        {
            string fullPath = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();
            var data = new UTF8Encoding(false).GetBytes("Test string");

            var sut = new MockFile(fileSystem);
            using (var stream = sut.Create(fullPath))
            {
                stream.Write(data, 0, data.Length);
            }

            var mockFileData = fileSystem.GetFile(fullPath);
            var fileData = mockFileData.Contents;

            Assert.That(fileData, Is.EqualTo(data));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:17,代码来源:MockFileCreateTests.cs

示例12: MockFile_Move_ShouldMoveFileWithinMemoryFileSystem

        public void MockFile_Move_ShouldMoveFileWithinMemoryFileSystem()
        {
            string sourceFilePath = XFS.Path(@"c:\something\demo.txt");
            string sourceFileContent = "this is some content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {sourceFilePath, new MockFileData(sourceFileContent)},
                {XFS.Path(@"c:\somethingelse\dummy.txt"), new MockFileData(new byte[] {0})}
            });

            string destFilePath = XFS.Path(@"c:\somethingelse\demo1.txt");

            fileSystem.File.Move(sourceFilePath, destFilePath);

            Assert.That(fileSystem.FileExists(destFilePath), Is.True);
            Assert.That(fileSystem.GetFile(destFilePath).TextContents, Is.EqualTo(sourceFileContent));
            Assert.That(fileSystem.FileExists(sourceFilePath), Is.False);
        }
开发者ID:ericnewton76,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileMoveTests.cs

示例13: MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding

        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);
        }
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:19,代码来源:MockFileAppendAllTextTests.cs

示例14: MockFile_Open_OpensExistingFileOnAppend

        public void MockFile_Open_OpensExistingFileOnAppend()
        {
            string filepath = XFS.Path(@"c:\something\does\exist.txt");
            var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { filepath, new MockFileData("I'm here") }
            });

            var stream = filesystem.File.Open(filepath, FileMode.Append);
            var file = filesystem.GetFile(filepath);
            
            Assert.That(stream.Position, Is.EqualTo(file.Contents.Length));
            Assert.That(stream.Length, Is.EqualTo(file.Contents.Length));

            stream.Seek(0, SeekOrigin.Begin);

            byte[] data;
            using (var br = new BinaryReader(stream))
                data = br.ReadBytes((int)stream.Length);

            CollectionAssert.AreEqual(file.Contents, data);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:22,代码来源:MockFileOpenTests.cs

示例15: MockFile_WriteAllText_Encoding_ShouldWriteTextFileToMemoryFileSystem

        public void MockFile_WriteAllText_Encoding_ShouldWriteTextFileToMemoryFileSystem(Encoding encoding)
        {
            // Arrange
            const string path = @"c:\something\demo.txt";
            const string fileContent = "Hello there! Dzięki.";
            var fileSystem = new MockFileSystem();

            // Act
            fileSystem.File.WriteAllText(path, fileContent, encoding);

            // Assert
            Assert.AreEqual(
                encoding.GetString(encoding.GetBytes(fileContent)),
                fileSystem.GetFile(path).TextContents);
        }
开发者ID:KallDrexx,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileTests.cs


注:本文中的MockFileSystem.GetFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。