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


C# MockFileSystem类代码示例

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


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

示例1: Directories_On_Different_FileSystems_Are_Not_Equal

 public void Directories_On_Different_FileSystems_Are_Not_Equal()
 {
     var dirA = FileSystem.DirectoryDescribing(@"c:\path\to");
     var dirB = new MockFileSystem().DirectoryDescribing(@"c:\path\to");
     AssertEqualityNotEquals(dirA, dirB);
     AssertOperatorNotEquals(dirA, dirB);
 }
开发者ID:toroso,项目名称:fs4net,代码行数:7,代码来源:RootedDirectoryEqualityFixture.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: MockFileInfo_Length_ShouldThrowFileNotFoundExcpetionIfFileDoesNotExistInMemoryFileSystem

        public void MockFileInfo_Length_ShouldThrowFileNotFoundExcpetionIfFileDoesNotExistInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData(fileContent) },
                { @"c:\a\b\c.txt", new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\foo.txt");

            try
            {
                // Act
                fileInfo.Length.ToString();

                // Assert
                Assert.Fail("Expected exception was not thrown");
            }
            catch (FileNotFoundException ex)
            {
                // Assert
                Assert.AreEqual(@"c:\foo.txt", ex.FileName);
            }
        }
开发者ID:jchannon,项目名称:System.IO.Abstractions,代码行数:25,代码来源:MockFileInfoTests.cs

示例4: MockFileSystem

        public void MockDirectory_GetFiles_ShouldReturnFilesDirectlyBelowPathWhenPatternIsWildcardAndSearchOptionIsTopDirectoryOnly()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData("Demo text content") },
                { @"c:\b.txt", new MockFileData("Demo text content") },
                { @"c:\c.txt", new MockFileData("Demo text content") },
                { @"c:\a\a.txt", new MockFileData("Demo text content") },
                { @"c:\a\b.txt", new MockFileData("Demo text content") },
                { @"c:\a\c.txt", new MockFileData("Demo text content") },
                { @"c:\a\a\a.txt", new MockFileData("Demo text content") },
                { @"c:\a\a\b.txt", new MockFileData("Demo text content") },
                { @"c:\a\a\c.txt", new MockFileData("Demo text content") },
            });

            // Act
            var result = fileSystem.Directory.GetFiles(@"c:\a", "*", SearchOption.TopDirectoryOnly);

            // Assert
            CollectionAssert.AreEqual
            (
                new[]
                {
                    @"c:\a\a.txt",
                    @"c:\a\b.txt",
                    @"c:\a\c.txt"
                },
                result
            );
        }
开发者ID:TomGillen,项目名称:System.IO.Abstractions,代码行数:31,代码来源:MockDirectoryTests.cs

示例5: Files_On_Different_FileSystems_Are_Not_Equal

 public void Files_On_Different_FileSystems_Are_Not_Equal()
 {
     var fileA = FileSystem.FileDescribing(@"c:\path\to\file.txt");
     var fileB = new MockFileSystem().FileDescribing(@"c:\path\to\file.txt");
     AssertEqualityNotEquals(fileA, fileB);
     AssertOperatorNotEquals(fileA, fileB);
 }
开发者ID:toroso,项目名称:fs4net,代码行数:7,代码来源:RootedFileEqualityFixture.cs

示例6: MyTestInitialize

 public void MyTestInitialize()
 {
     _fileSystem = new MockFileSystem();
     var mockExifReader = new MockExifReader(_fileSystem);
     _directoryFactory = new PictureDirectoryFactory(_fileSystem, mockExifReader);
     _fileHandlerFactory = new FileHandlerFactory(_fileSystem);
 }
开发者ID:JMnITup,项目名称:PictureHandler,代码行数:7,代码来源:FileHandlerUploaderTests.cs

示例7: MockFile_Open_ThrowsOnTruncateWithMissingFile

        public void MockFile_Open_ThrowsOnTruncateWithMissingFile()
        {
            string filepath = XFS.Path(@"c:\something\doesnt\exist.txt");
            var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());

            Assert.Throws<FileNotFoundException>(() => filesystem.File.Open(filepath, FileMode.Truncate));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:7,代码来源:MockFileOpenTests.cs

示例8: MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding

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

示例9: MockFile_Move_ShouldThrowArgumentNullExceptionWhenSourceIsNull_ParamName

        public void MockFile_Move_ShouldThrowArgumentNullExceptionWhenSourceIsNull_ParamName() {
            string destFilePath = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();

            var exception = Assert.Throws<ArgumentNullException>(() => fileSystem.File.Move(null, destFilePath));

            Assert.That(exception.ParamName, Is.EqualTo("sourceFileName"));
        }
开发者ID:ericnewton76,项目名称:System.IO.Abstractions,代码行数:8,代码来源:MockFileMoveTests.cs

示例10: MockFile_Copy_ShouldThrowArgumentNullExceptionWhenSourceIsNull_Message

        public void MockFile_Copy_ShouldThrowArgumentNullExceptionWhenSourceIsNull_Message()
        {
            string destFilePath = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem();

            var exception = Assert.Throws<ArgumentNullException>(() => fileSystem.File.Copy(null, destFilePath));

            Assert.That(exception.Message, Is.StringStarting("File name cannot be null."));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:9,代码来源:MockFileCopyTests.cs

示例11: MockFile_Open_ThrowsOnCreateNewWithExistingFile

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

            Assert.Throws<IOException>(() => filesystem.File.Open(filepath, FileMode.CreateNew));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:10,代码来源:MockFileOpenTests.cs

示例12: CreateNewDirectoryWithRenameAttemptsDateTest

 public void CreateNewDirectoryWithRenameAttemptsDateTest()
 {
     MockFileSystem mockFileSystem = new MockFileSystem();
     FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
     Assert.AreEqual(1, mockFileSystem.DirectoryCount);
     Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012"));
     FileCreator.CreateNewDirectoryWithRenameAttempts("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012", mockFileSystem, 10);
     Assert.AreEqual(2, mockFileSystem.DirectoryCount);
     Assert.IsTrue(mockFileSystem.DirectoryExists("D:\\tmp\\ayt-export\\iPhone Text History Backup - 03-03-2012 (2)"));
 }
开发者ID:jzajac2,项目名称:AllYourTexts,代码行数:10,代码来源:FileCreatorTest.cs

示例13: MockFile_WriteAllText_ShouldThrowAnArgumentExceptionIfThePathIsEmpty

        public void MockFile_WriteAllText_ShouldThrowAnArgumentExceptionIfThePathIsEmpty()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            // Act
            TestDelegate action = () => fileSystem.File.WriteAllText(string.Empty, "hello world");

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

示例14: MockFile_Open_CreatesNewFileFileOnCreateNew

        public void MockFile_Open_CreatesNewFileFileOnCreateNew()
        {
            string filepath = XFS.Path(@"c:\something\doesnt\exist.txt");
            var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>());

            var stream = filesystem.File.Open(filepath, FileMode.CreateNew);

            Assert.That(filesystem.File.Exists(filepath), Is.True);
            Assert.That(stream.Position, Is.EqualTo(0));
            Assert.That(stream.Length, Is.EqualTo(0));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:11,代码来源:MockFileOpenTests.cs

示例15: MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath

        public void MockDriveInfo_Constructor_ShouldThrowExceptionIfUncPath(string driveName)
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            // Act
            TestDelegate action = () => new MockDriveInfo(fileSystem, XFS.Path(driveName));

            // Assert
            Assert.Throws<ArgumentException>(action);
        }
开发者ID:johncmckim,项目名称:System.IO.Abstractions,代码行数:11,代码来源:MockDriveInfoTests.cs


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