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


C# MockFile类代码示例

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


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

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

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

示例3: Mockfile_Create_ThrowsWhenPathIsReadOnly

 public void Mockfile_Create_ThrowsWhenPathIsReadOnly()
 {
     string path = XFS.Path(@"c:\something\read-only.txt");
     var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Content") } });
     var mockFile = new MockFile(fileSystem);
     
     mockFile.SetAttributes(path, FileAttributes.ReadOnly);
  
     var exception =  Assert.Throws<UnauthorizedAccessException>(() => mockFile.Create(path).Close());
     Assert.That(exception.Message, Is.EqualTo(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path)));
 }
开发者ID:BrianLanghoor,项目名称:System.IO.Abstractions,代码行数:11,代码来源:MockFileCreateTests.cs

示例4: Mockfile_Create_ShouldCreateNewStream

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

            var sut = new MockFile(fileSystem);

            Assert.That(fileSystem.FileExists(fullPath), Is.False);

            sut.Create(fullPath).Close();

            Assert.That(fileSystem.FileExists(fullPath), Is.True);
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:13,代码来源:MockFileCreateTests.cs

示例5: Initialize

        public void Initialize()
        {
            this.mockFileSystem = new Mock<IFileSystem>();
            this.mockSettingsService = new Mock<ISettingsService>();
            this.mockFile = new MockFile();
            this.mockFileInfoFactory = new Mock<IFileInfoFactory>();
            this.mockFileInfo = new MockFileInfo();

            this.mockFileSystem.SetupGet(x => x.File).Returns(this.mockFile);
            this.mockFileSystem.SetupGet(x => x.FileInfo).Returns(this.mockFileInfoFactory.Object);
            this.mockFileInfoFactory.Setup(x => x.FromFileName(It.IsAny<string>())).Returns(this.mockFileInfo);

            this.service = new CodeConfigService();
        }
开发者ID:asudbury,项目名称:NinjaCoderForMvvmCross,代码行数:14,代码来源:TestCodeConfigService.cs

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

示例7: MockFile_Exists_ShouldReturnTrueForPathVaryingByCase

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

            var file = new MockFile(fileSystem);

            // Act
            var result = file.Exists(XFS.Path(@"c:\SomeThing\Other.gif"));

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

示例8: MockFile_Exists_ShouldReturnFalseForEntirelyDifferentPath

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

            var file = new MockFile(fileSystem);

            // Act
            var result = file.Exists(XFS.Path(@"c:\SomeThing\DoesNotExist.gif"));

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

示例9: MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile

        public void MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile()
        {
            // Arrange
            string path = XFS.Path(@"c:\something\demo.txt");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\something\"), new MockDirectoryData() }
            });
            var file = new MockFile(fileSystem);

            // Act
            file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" });

            // Assert
            Assert.AreEqual(
                "line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine,
                file.ReadAllText(path));
        }
开发者ID:wafe,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileAppendAllLinesTests.cs

示例10: MockFile_GetSetCreationTime_ShouldPersist

        public void MockFile_GetSetCreationTime_ShouldPersist()
        {
            // 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
            var creationTime = new DateTime(2010, 6, 4, 13, 26, 42);
            file.SetCreationTime(path, creationTime);
            var result = file.GetCreationTime(path);

            // Assert
            Assert.AreEqual(creationTime, result);
        }
开发者ID:rockarts,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileTests.cs

示例11: MockFile_SetCreationTime_ShouldAffectCreationTimeUtc

        public void MockFile_SetCreationTime_ShouldAffectCreationTimeUtc()
        {
            // 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
            var creationTime = new DateTime(2010, 6, 4, 13, 26, 42);
            file.SetCreationTime(path, creationTime);
            var result = file.GetCreationTimeUtc(path);

            // Assert
            Assert.AreEqual(creationTime.ToUniversalTime(), result);
        }
开发者ID:ericnewton76,项目名称:System.IO.Abstractions,代码行数:18,代码来源:MockFileTests.cs

示例12: MockFile_ReadLines_ShouldReturnOriginalTextData

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

            var file = new MockFile(fileSystem);

            // Act
            var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt"));

            // Assert
            CollectionAssert.AreEqual(
                new[] { "Demo", "text", "content", "value" },
                result);
        }
开发者ID:johncmckim,项目名称:System.IO.Abstractions,代码行数:19,代码来源:MockFileReadLinesTests.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_AppendAllText_ShouldPersistNewText

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

示例15: MockFile_ReadLines_ShouldReturnOriginalDataWithCustomEncoding

        public void MockFile_ReadLines_ShouldReturnOriginalDataWithCustomEncoding()
        {
            // Arrange
            string text = "Hello\r\nthere\rBob\nBob!";
            var encodedText = Encoding.BigEndianUnicode.GetBytes(text);
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\something\demo.txt"), new MockFileData(encodedText) }
            });

            var file = new MockFile(fileSystem);

            // Act
            var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode);

            // Assert
            CollectionAssert.AreEqual(
                new [] { "Hello", "there", "Bob", "Bob!" },
                result);
        }
开发者ID:johncmckim,项目名称:System.IO.Abstractions,代码行数:20,代码来源:MockFileReadLinesTests.cs


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