• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MockFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MockFile_AppendAllText_ShouldFailIfNotExistButDirectoryAlsoNotExist

        public void MockFile_AppendAllText_ShouldFailIfNotExistButDirectoryAlsoNotExist()
        {
            // Arrange
            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
            path = @"c:\something2\demo.txt";

            // Assert
            Exception ex;
            ex = Assert.Throws<DirectoryNotFoundException>(() => fileSystem.File.AppendAllText(path, "some text"));
            Assert.That(ex.Message, Is.EqualTo(String.Format("Could not find a part of the path '{0}'.", path)));

            ex = Assert.Throws<DirectoryNotFoundException>(() => fileSystem.File.AppendAllText(path, "some text", Encoding.Unicode));
            Assert.That(ex.Message, Is.EqualTo(String.Format("Could not find a part of the path '{0}'.", path)));
        }
开发者ID:KallDrexx,项目名称:System.IO.Abstractions,代码行数:23,代码来源:MockFileTests.cs


示例17: AddFile

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the given filename to the collection of files that should be considered to
		/// exist and set its contents so it can be read.
		/// </summary>
		/// <param name="filename">The filename (may or may not include path).</param>
		/// <param name="contents">The contents of the file</param>
		/// <param name="encoding">File encoding</param>
		/// ------------------------------------------------------------------------------------
		public void AddFile(string filename, string contents, Encoding encoding)
		{
			FileUtils.AssertValidFilePath(filename);
			string dir = Path.GetDirectoryName(filename);
			if (!string.IsNullOrEmpty(dir) && !((IFileOS)this).DirectoryExists(dir))
				ExistingDirectories.Add(dir); // Theoretically, this should add containing folders recursively.
			m_existingFiles[filename] = new MockFile(contents, encoding);
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:17,代码来源:MockFileOs.cs


示例18: Initialize

        public void Initialize()
        {
            this.mockPluginService = new Mock<IPluginService>();
            this.mockVisualStudioService = new Mock<IVisualStudioService>();
            this.mockFileSystem = new Mock<IFileSystem>();
            this.mockSettingsService = new Mock<ISettingsService>();
            this.mockNugetService = new Mock<INugetService>();

            this.mockFile = new MockFile();
            this.mockFileInfoFactory = new Mock<IFileInfoFactory>();
            this.mockFileInfo = new MockFileInfo();

            this.mockTestingServiceFactory = new Mock<ITestingServiceFactory>();
            this.mockCodeSnippetFactory = new Mock<ICodeSnippetFactory>();

            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 PluginsService(
                this.mockPluginService.Object,
                this.mockSettingsService.Object,
                this.mockNugetService.Object,
                this.mockCodeSnippetFactory.Object,
                this.mockTestingServiceFactory.Object);*/
        }
开发者ID:RobGibbens,项目名称:NinjaCoderForMvvmCross,代码行数:26,代码来源:TestPluginsService.cs


示例19: MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding

        public void MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding()
        {
            // Arrange
            const string text = "Hello there!";
            var encodedText = Encoding.BigEndianUnicode.GetBytes(text);
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\something\demo.txt", new MockFileData(encodedText) }
            });

            var file = new MockFile(fileSystem);

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

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


示例20: MockFile_ReadAllText_ShouldReturnOriginalTextData

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

            var file = new MockFile(fileSystem);

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

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MockFileSystem类代码示例发布时间:2022-05-24
下一篇:
C# MockFactory类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap