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


C# MockFileSystem.AddFile方法代码示例

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


在下文中一共展示了MockFileSystem.AddFile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.AddFile(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:wafe,项目名称:System.IO.Abstractions,代码行数:14,代码来源:MockFileDeleteTests.cs

示例2: 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

示例3: 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.AddFile(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:wafe,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileStreamTests.cs

示例4: MockFileSystem_AddDirectory_ShouldThrowExceptionIfDirectoryIsReadOnly

        public void MockFileSystem_AddDirectory_ShouldThrowExceptionIfDirectoryIsReadOnly()
        {
            // Arrange
            const string baseDirectory = @"C:\Test";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(baseDirectory, new MockFileData(string.Empty));
            fileSystem.File.SetAttributes(baseDirectory, FileAttributes.ReadOnly);

            // Act
            TestDelegate act = () => fileSystem.AddDirectory(baseDirectory);

            // Assert
            Assert.Throws<UnauthorizedAccessException>(act);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:14,代码来源:MockFileSystemTests.cs

示例5: Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved

        public void Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddDirectory(@"C:\OLD_LOCATION\Data");
            fileSystem.AddFile(@"C:\old_location\Data\someFile.txt", new MockFileData("abc"));

            // Act
            fileSystem.Directory.Move(@"C:\old_location", @"C:\NewLocation\");

            // Assert
            Assert.IsTrue(fileSystem.File.Exists(@"C:\NewLocation\Data\someFile.txt"));
        }
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:13,代码来源:MockDirectoryTests.cs

示例6: MockDirectory_EnumerateDirectories_WithAllDirectories_ShouldReturnsAllMatchingSubFolders

        public void MockDirectory_EnumerateDirectories_WithAllDirectories_ShouldReturnsAllMatchingSubFolders()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\.foo\"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\foo"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\foo.foo"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\.foo\.foo"));
            fileSystem.AddFile(XFS.Path(@"C:\Folder\.foo\bar"), new MockFileData(string.Empty));

            // Act
            var actualResult = fileSystem.Directory.EnumerateDirectories(XFS.Path(@"c:\Folder\"), "*.foo", SearchOption.AllDirectories);

            // Assert
            Assert.That(actualResult, Is.EquivalentTo(new[] { XFS.Path(@"C:\Folder\.foo\"), XFS.Path(@"C:\Folder\foo.foo\"), XFS.Path(@"C:\Folder\.foo\.foo\") }));
        }
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockDirectoryTests.cs

示例7: MockDirectory_GetDirectories_WithTopDirectories_ShouldOnlyReturnTopDirectories

        public void MockDirectory_GetDirectories_WithTopDirectories_ShouldOnlyReturnTopDirectories()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\.foo\"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\foo"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\foo.foo"));
            fileSystem.AddDirectory(XFS.Path(@"C:\Folder\.foo\.foo"));
            fileSystem.AddFile(XFS.Path(@"C:\Folder\.foo\bar"), new MockFileData(string.Empty));

            // Act
            var actualResult = fileSystem.Directory.GetDirectories(XFS.Path(@"c:\Folder\"), "*.foo");

            // Assert
            Assert.That(actualResult, Is.EquivalentTo(new []{XFS.Path(@"C:\Folder\.foo\"), XFS.Path(@"C:\Folder\foo.foo\")}));
        }
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockDirectoryTests.cs

示例8: MockDirectory_Exists_ShouldReturnFalseForFiles

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

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

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

示例9: MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem

        public void MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToMockFileSystem()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(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:tathamoddie,项目名称:System.IO.Abstractions,代码行数:12,代码来源:MockDirectoryTests.cs

示例10: MockFileInfo_OpenText_ShouldReturnStringContentOfFile

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

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

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

示例11: MockFileInfo_OpenRead_ShouldReturnByteContentOfFile

        public void MockFileInfo_OpenRead_ShouldReturnByteContentOfFile()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(@"c:\temp\file.txt", new MockFileData(new byte[] { 1, 2 }));
            var fileInfo = fileSystem.FileInfo.FromFileName(@"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:KallDrexx,项目名称:System.IO.Abstractions,代码行数:16,代码来源:MockFileInfoTests.cs

示例12: 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.AddFile(filepath, file);

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

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

示例13: MockFile_WriteAllText_ShouldThrowAnUnauthorizedAccessExceptionIfTheFileIsReadOnly

        public void MockFile_WriteAllText_ShouldThrowAnUnauthorizedAccessExceptionIfTheFileIsReadOnly()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            string filePath = XFS.Path(@"c:\something\demo.txt");
            var mockFileData = new MockFileData(new byte[0]);
            mockFileData.Attributes = FileAttributes.ReadOnly;
            fileSystem.AddFile(filePath, mockFileData);

            // Act
            TestDelegate action = () => fileSystem.File.WriteAllText(filePath, null);

            // Assert
            Assert.Throws<UnauthorizedAccessException>(action);
        }
开发者ID:tathamoddie,项目名称:System.IO.Abstractions,代码行数:15,代码来源:MockFileWriteAllTextTests.cs

示例14: MockFileData_AcceptsFuncAndReturnsContents

        public void MockFileData_AcceptsFuncAndReturnsContents()
        {
            // create a file in a source file system
            var sourceFileSystem = new MockFileSystem();
            sourceFileSystem.File.WriteAllBytes(sourceFileName, fileContent);
            sourceFileSystem.File.SetAttributes(sourceFileName, attributes);
            sourceFileSystem.File.SetCreationTime(sourceFileName, dateCreated);
            sourceFileSystem.File.SetLastWriteTime(sourceFileName, dateLastWritten);
            sourceFileSystem.File.SetLastAccessTime(sourceFileName, dateLastAccessed);
            var sourceFile = sourceFileSystem.DirectoryInfo.FromDirectoryName(Path.GetDirectoryName(sourceFileName)).GetFiles().Single();

            // create a new destination file system and copy the source file there
            var dfs = new MockFileSystem();
            dfs.AddFile(destinationFileName, new MockFileData(sourceFileSystem, sourceFile));
            destinationFileInfo = dfs.DirectoryInfo.FromDirectoryName(Path.GetDirectoryName(destinationFileName)).GetFiles().Single();
            destinationFileSystem = dfs;
        }
开发者ID:danbystrom,项目名称:System.IO.Abstractions,代码行数:17,代码来源:MockFileDataLazyLoadContentTests.cs


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