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


C# MockFileSystem.AddFileWithCreate方法代码示例

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


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

示例1: MockFile_Delete_ShouldDeleteFile

        public void MockFile_Delete_ShouldDeleteFile()
        {
            var fileSystem = new MockFileSystem();
            var path = XFS.Path("C:\\test");
            var directory = fileSystem.Path.GetDirectoryName(path);
            fileSystem.AddFileWithCreate(path, new MockFileData("Bla"));

            var fileCount1 = fileSystem.Directory.GetFiles(directory, "*").Length;
            fileSystem.File.Delete(path);
            var fileCount2 = fileSystem.Directory.GetFiles(directory, "*").Length;

            Assert.AreEqual(1, fileCount1, "File should have existed");
            Assert.AreEqual(0, fileCount2, "File should have been deleted");
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:14,代码来源:MockFileDeleteTests.cs

示例2: MockFileStream_Dispose_ShouldNotResurrectFile

        public void MockFileStream_Dispose_ShouldNotResurrectFile()
        {
            var fileSystem = new MockFileSystem();
            var path = XFS.Path("C:\\test");
            var directory = fileSystem.Path.GetDirectoryName(path);
            fileSystem.AddFileWithCreate(path, new MockFileData("Bla"));
            var stream = fileSystem.File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete);

            var fileCount1 = fileSystem.Directory.GetFiles(directory, "*").Length;
            fileSystem.File.Delete(path);
            var fileCount2 = fileSystem.Directory.GetFiles(directory, "*").Length;
            stream.Dispose();
            var fileCount3 = fileSystem.Directory.GetFiles(directory, "*").Length;

            Assert.AreEqual(1, fileCount1, "File should have existed");
            Assert.AreEqual(0, fileCount2, "File should have been deleted");
            Assert.AreEqual(0, fileCount3, "Disposing stream should not have resurrected the file");
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileStreamTests.cs

示例3: MockFileInfo_OpenText_ShouldReturnStringContentOfFile

        public void MockFileInfo_OpenText_ShouldReturnStringContentOfFile()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFileWithCreate(XFS.Path(@"c:\temp\file.txt"), new MockFileData(@"line 1\r\nline 2"));
            var fileInfo = fileSystem.FileInfo.FromFileName(XFS.Path(@"c:\temp\file.txt"));

            // Act
            string result;
            using (var streamReader = fileInfo.OpenText())
            {
                result = streamReader.ReadToEnd();
            }

            Assert.AreEqual(@"line 1\r\nline 2", result);
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockFileInfoTests.cs

示例4: MockFileInfo_OpenRead_ShouldReturnByteContentOfFile

        public void MockFileInfo_OpenRead_ShouldReturnByteContentOfFile()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFileWithCreate(XFS.Path(@"c:\temp\file.txt"), new MockFileData(new byte[] { 1, 2 }));
            var fileInfo = fileSystem.FileInfo.FromFileName(XFS.Path(@"c:\temp\file.txt"));

            // Act
            byte[] result = new byte[2];
            using (var stream = fileInfo.OpenRead())
            {
                stream.Read(result, 0, 2);
            }

            Assert.AreEqual(new byte[] { 1, 2 }, result);
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockFileInfoTests.cs

示例5: MockFile_OpenText_ShouldRetainCreationTime

        public void MockFile_OpenText_ShouldRetainCreationTime()
        {
            // Arrange
            var fs = new MockFileSystem();
            string filepath = XFS.Path(@"C:\TestData\test.txt");
            var file = new MockFileData(@"I'm here");
            var creationTime = new DateTime(2012, 03, 21);
            file.CreationTime = creationTime;
            fs.AddFileWithCreate(filepath, file);

            // Act
            using (var reader = fs.File.OpenText(filepath))
            {
                reader.ReadLine();
            }

            // Assert
            Assert.AreEqual(creationTime, fs.FileInfo.FromFileName(filepath).CreationTime);
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:19,代码来源:MockFileOpenTests.cs

示例6: MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem

        public void MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFileWithCreate(XFS.Path(@"c:\foo\bar.txt"), new MockFileData("Demo text content"));

            // Act
            var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo\"));

            // Assert
            Assert.IsTrue(result);
        }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:12,代码来源:MockDirectoryTests.cs


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