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


C# TestingHelpers.MockFileSystem类代码示例

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


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

示例1: CopyFiles_Copies_files_to_destinationFolder

        public void CopyFiles_Copies_files_to_destinationFolder()
        {
            // Arrange
            var filesSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {@"c:\Temp\Folder\1.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\2.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\SubFolder\3.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\SubFolder\4.txt", new MockFileData(string.Empty)},

                {@"d:\Destination\", new MockDirectoryData()},
            });

            var fileSystemHelper = new FileSystemHelper(filesSystem);

            // Act
            var filesToCopy = fileSystemHelper.GetFiles(@"c:\Temp\", "*.*");
            fileSystemHelper.CopyFiles(filesToCopy, @"D:\Destination\", force: false);

            // Assert
            filesSystem.AllFiles.Contains(new List<string>
            {
                @"d:\Destination\Folder\1.txt",
                @"d:\Destination\Folder\2.txt",
                @"d:\Destination\Folder\SubFolder\3.txt",
                @"d:\Destination\Folder\SubFolder\4.txt",
            }, StringComparer.InvariantCultureIgnoreCase);
        }
开发者ID:sietsevdschoot,项目名称:FolderDiff,代码行数:28,代码来源:FileSystemHelperTests.cs

示例2: CopyFiles_if_force_is_true_and_destinationPath_does_not_exist_creates_destinationFolder

        public void CopyFiles_if_force_is_true_and_destinationPath_does_not_exist_creates_destinationFolder()
        {
            // Arrange
            var filesSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {@"c:\Temp\Folder\1.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\2.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\SubFolder\3.txt", new MockFileData(string.Empty)},
                {@"c:\Temp\Folder\SubFolder\4.txt", new MockFileData(string.Empty)},
            });

            var fileSystemHelper = new FileSystemHelper(filesSystem);

            // Act
            var filesToCopy = fileSystemHelper.GetFiles(@"c:\Temp\", "*.*");
            fileSystemHelper.CopyFiles(filesToCopy, @"C:\Destination\Documents\", force: true);

            // Assert
            filesSystem.AllFiles.Contains(new List<string>
            {
                @"c:\Destination\Documents\Folder\1.txt",
                @"c:\Destination\Documents\Folder\2.txt",
                @"c:\Destination\Documents\Folder\SubFolder\3.txt",
                @"c:\Destination\Documents\Folder\SubFolder\4.txt",
            }, StringComparer.InvariantCultureIgnoreCase);
        }
开发者ID:sietsevdschoot,项目名称:FolderDiff,代码行数:26,代码来源:FileSystemHelperTests.cs

示例3: Should_Compile_Less_To_Css_To_Output_Path

        public void Should_Compile_Less_To_Css_To_Output_Path()
        {
            var lessContent = @"@brand_color: #4D926F;

                                    #header {
                                        color: @brand_color;
                                    }

                                    h2 {
                                        color: @brand_color;
                                    }";

            var lessOutput = @"#header{color:#4d926f}h2{color:#4d926f}";

            var filepath = @"c:\css\style.less";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { filepath, new MockFileData(lessContent) }
            });

            var files = new List<FileInfo>() { new FileInfo(filepath) };

            var factory = new TestContainerFactory();
            var engine = factory.GetEngine(fileSystem, @"c:\css");

            var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine);
            minifier.Minify();

            var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8);

            Assert.Equal(lessOutput, minifiedFile);
        }
开发者ID:sunilrav,项目名称:pretzel,代码行数:32,代码来源:CssMinificationTests.cs

示例4: Should_Combine_Files_To_Output_Path

        public void Should_Combine_Files_To_Output_Path()
        {
            var filepath1 = @"c:\css\style.css";
            var filepath2 = @"c:\css\style2.css";

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { filepath1, new MockFileData("a { color: Red; }") },
                { filepath2, new MockFileData("a { color: Blue; }") }
            });

            var files = new List<FileInfo> { new FileInfo(filepath1), new FileInfo(filepath2) };

            var factory = new TestContainerFactory();
            var engine = factory.GetEngine(fileSystem, @"c:\css");

            var minifier = new CssMinifier(fileSystem, files, _outputPath, () => engine);
            minifier.Minify();

            var expectedOutput = @"a{color:Red}a{color:Blue}";

            var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8);

            Assert.Equal(expectedOutput, minifiedFile);
        }
开发者ID:sunilrav,项目名称:pretzel,代码行数:25,代码来源:CssMinificationTests.cs

示例5: SetUp

        public void SetUp()
        {
            var stream_website = Assembly.GetExecutingAssembly().GetManifestResourceStream("Bankleitzahlen.Bundesbank.Tests.Resources.bankleitzahlen_download.html");
            var stream_änderungsdatei = Assembly.GetExecutingAssembly().GetManifestResourceStream("Bankleitzahlen.Bundesbank.Tests.Resources.blz_2015_09_07_txt.txt");

            var webclientMock = new Mock<IWebClient>();
            webclientMock.Setup(client => client.OpenReadTaskAsync(It.Is<Uri>(uri => uri == BankleitzahlenänderungsdateiService.BankleitzahlenänderungsdateiUri))).ReturnsAsync(stream_website);
            webclientMock.Setup(client => client.OpenReadTaskAsync(It.Is<Uri>(uri => uri == new Uri("https://foo.bla/blz_2015_09_07_txt.txt")))).ReturnsAsync(stream_änderungsdatei);

            var webclientFactoryMock = new Mock<IWebClientFactory>();
            webclientFactoryMock.Setup(factory => factory.CreateWebClient()).Returns(webclientMock.Object);

            var fileSystemMock = new MockFileSystem(new Dictionary<string, MockFileData>
                {
                    { @"c:\data\Bundesbankänderungsdateien\blz_2015_09_07_txt.txt", new MockFileData(
@"100305001Bankhaus Löbbecke                                         10117Berlin                             Bankhaus Löbbecke Berlin   26225LOEBDEBBXXX09043961U000000000
100306001North Channel Bank                                        55118Mainz a Rhein                      North Channel Bank Mainz   26205GENODEF1OGK88000532U000000000
100307001Eurocity Bank                                             60311Frankfurt am Main                  Eurocity Bank              26535DLGHDEB1XXX16044339U000000000", Encoding.GetEncoding(1252)) }
                });

            //_service = new BankleitzahlenänderungsdateiService(fileSystemMock);
            _service = new BankleitzahlenänderungsdateiService();
            _service.WebClientFactory = webclientFactoryMock.Object;
            _service.FileSystem = fileSystemMock;
        }
开发者ID:chkpnt,项目名称:Bankleitzahlen-Tool,代码行数:25,代码来源:BankleitzahlenänderungsdateiServiceTests.cs

示例6: ExtractSnippet

        public void ExtractSnippet()
        {
            // Declare content
            const string content =
            @"Some
            Content
            Here";
            // Mock file system
            IFileSystem fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { "Content.txt", new MockFileData(content) }
            });

            // Run the extraction
            DefaultSnippetExtractor extractor = new DefaultSnippetExtractor();
            FileInfoBase fileInfoBase = fileSystem.FileInfo.FromFileName("Content.txt");
            Extension.Model.PlainTextSnippet snippet = extractor.Extract(fileInfoBase, null) as Extension.Model.PlainTextSnippet;

            // Load the expected file content
            MemoryStream memoryStream = new MemoryStream();
            using (var fileReader = new StreamReader(fileInfoBase.OpenRead()))
            using (var fileWriter = new StreamWriter(memoryStream))
            {
                fileWriter.Write(fileReader.ReadToEnd());
            }

            // Assert
            Assert.AreEqual(content, snippet.Text);
        }
开发者ID:defrancea,项目名称:Projbook,代码行数:29,代码来源:DefaultSnippetExtractorTests.cs

示例7: Should_Compile_Single_Less_File

        public void Should_Compile_Single_Less_File()
        {
            var lessContent = @"@brand_color: #4D926F;

                                    #header {
                                        color: @brand_color;
                                    }
 
                                    h2 {
                                        color: @brand_color;
                                    }";

            var lessOutput = @"#header{color:#4d926f}h2{color:#4d926f}";

            var filepath = @"c:\css\style.less";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { HtmlFilePath, new MockFileData(PageContent)},
                { filepath, new MockFileData(lessContent) }
            });

            var minifier = new LessTransform(fileSystem);
            var context = new SiteContext { SourceFolder = @"C:\", OutputFolder = @"C:\_site" };
            context.Pages.Add(new NonProcessedPage { OutputFile = HtmlFilePath, Content = PageContent });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath, Content = lessContent, Filepath = filepath });
            minifier.Transform(context);

            var minifiedFile = fileSystem.File.ReadAllText(@"c:\css\style.css", Encoding.UTF8);
            Assert.Equal(lessOutput, minifiedFile);
        }
开发者ID:impressive-mark,项目名称:pretzel,代码行数:30,代码来源:LessTransformTests.cs

示例8: It_should_store_result_after_http_lookup

 public void It_should_store_result_after_http_lookup()
 {
     IFileSystem mockFileSystem = new MockFileSystem();
     ratingService.GetRatingWithCache("tt0061811", new MockHttpService(OmdbapiResult), mockFileSystem);
     string expectedPath = Path.Combine(Raticon.Constants.CommonApplicationDataPath, "Cache", "tt0061811.json");
     Assert.IsTrue(mockFileSystem.File.Exists(expectedPath));
 }
开发者ID:Jamedjo,项目名称:Raticon,代码行数:7,代码来源:RatingServiceTest.cs

示例9: NoDeliveriesFound_DoesntRequireHost

        public async Task NoDeliveriesFound_DoesntRequireHost()
        {
            var provider = Substitute.For<ISqlSyntaxProvider>();
            provider.DoesTableExist(Arg.Any<Database>(), Arg.Any<string>()).Returns(true);

            SqlSyntaxContext.SqlSyntaxProvider = provider;

            var settings = Substitute.For<IChauffeurSettings>();
            string s;
            settings.TryGetChauffeurDirectory(out s).Returns(x =>
            {
                x[0] = @"c:\foo";
                return true;
            });

            var conn = Substitute.For<IDbConnection>();
            var db = new Database(conn);

            var writer = new MockTextWriter();

            var fs = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                {@"c:\foo\bar.txt", new MockFileData("This is not a deliverable")}
            });

            var deliverable = new DeliveryDeliverable(null, writer, db, settings, fs, null);

            await deliverable.Run(null, null);

            Assert.That(writer.Messages.Count(), Is.EqualTo(1));
        }
开发者ID:Jaxwood,项目名称:Chauffeur,代码行数:31,代码来源:DeliveryDeliverableTests.cs

示例10: Should_Combine_Files_To_Output_Path

        public void Should_Combine_Files_To_Output_Path()
        {
            var filepath1 = @"c:\css\script1.js";
            var script1 = @"function test() { alert('hello'); }";

            var filepath2 = @"c:\css\script2.css";
            var script2 = @"document.write('<h1>This is a heading</h1>');
document.write('<p>This is a paragraph.</p>');
document.write('<p>This is another paragraph.</p>');";

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { filepath1, new MockFileData(script1) },
                { filepath2, new MockFileData(script2) }
            });

            var files = new List<FileInfo> { new FileInfo(filepath1), new FileInfo(filepath2) };

            var minifier = new JsMinifier(fileSystem, files, _outputPath);
            minifier.Minify();

            var expectedOutput = "function test(){alert(\"hello\")}document.write(\"<h1>This is a heading<\\/h1>\");document.write(\"<p>This is a paragraph.<\\/p>\");document.write(\"<p>This is another paragraph.<\\/p>\")";

            var minifiedFile = fileSystem.File.ReadAllText(_outputPath, Encoding.UTF8);

            Assert.Equal(expectedOutput, minifiedFile);
        }
开发者ID:impressive-mark,项目名称:pretzel,代码行数:27,代码来源:JsMinificationTests.cs

示例11: InstallWithPowershellFile

        public void InstallWithPowershellFile()
        {
            RetrieveFileDataForTestStep testFileLocation = index => @"c:\a\b";
            UploadReportFilesForTestStep uploader = (index, upload) => { };

            var fileSystem = new MockFileSystem(
                new Dictionary<string, MockFileData>
                    {
                        { @"c:\a\b\c.ps1", new MockFileData("Out-Host -InputObject 'hello word'") }
                    });

            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var installer = new ScriptExecuteTestStepProcessor(
               testFileLocation,
               uploader,
               diagnostics,
               fileSystem,
               sectionBuilder.Object);

            var data = new ScriptExecuteTestStep
            {
                pk_TestStepId = 1,
                Order = 2,
                ScriptLanguage = ScriptLanguage.Powershell,
            };

            var result = installer.Process(data, new List<InputParameter>());
            Assert.AreEqual(TestExecutionState.Passed, result);
        }
开发者ID:pvandervelde,项目名称:Sherlock,代码行数:30,代码来源:ScriptExecuteTestStepProcessorTest.cs

示例12: ParsePropertiesFile_RealFile_Parsed

        public void ParsePropertiesFile_RealFile_Parsed()
        {
            var resource = new EmbeddedResourceReader().GetResource("PropertiesFile.txt");

            // Arrange
            var mockFileSystem = new MockFileSystem();
            var propertiesFile = @"C:\BuildAgent\temp\buildTmp\teamcity.build322130465402584030.properties";
            mockFileSystem.AddFile(propertiesFile, resource);

            var propertiesFileParser = new PropertiesFileParser(mockFileSystem);

            // Act
            var dictionary = propertiesFileParser.ParsePropertiesFile(propertiesFile);

            // Assert
            dictionary["agent.home.dir"].Should().Be(@"C:\BuildAgent");
            dictionary["agent.name"].Should().Be(@"BUILDS8");
            dictionary["agent.ownPort"].Should().Be(@"9090");
            dictionary["agent.work.dir"].Should().Be(@"C:\BuildAgent\work");
            dictionary["build.number"].Should().Be(@"4");
            dictionary["FxCopRoot"].Should()
                .Be(@"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop");
            dictionary["teamcity.agent.dotnet.agent_url"].Should().Be(@"http://localhost:9090/RPC2");
            dictionary["teamcity.auth.userId"].Should().Be(@"TeamCityBuildId=781682");
        }
开发者ID:QualiSystems,项目名称:FluentTc,代码行数:25,代码来源:PropertiesFileParserTests.cs

示例13: ReadAllPaths_WhenSomeAreEmpty_ReturnsOnlyNonEmptyPaths

        public void ReadAllPaths_WhenSomeAreEmpty_ReturnsOnlyNonEmptyPaths()
        {
            // Arrange
            string[] sourceFolderPaths = {
                @"C:\Users\Kevin\Documents\Cloud Backup Test",
                @" ",
                @"  ",
                @"C:\Users\Kevin\Documents\LINQPad Queries"
            };

            string contents =
                sourceFolderPaths[0] + Environment.NewLine +
                sourceFolderPaths[1] + Environment.NewLine +
                sourceFolderPaths[2] + Environment.NewLine +
                sourceFolderPaths[3];

            string[] expected = {
                @"C:\Users\Kevin\Documents\Cloud Backup Test",
                @"C:\Users\Kevin\Documents\LINQPad Queries"
            };

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { SourceFolderPathsFilePath, new MockFileData(contents) },
            });

            // Act
            var actor =
                ActorOfAsTestActorRef<CloudBackupActor>(Props.Create(() => new CloudBackupActor(SourceFolderPathsFilePath, fileSystem)))
                .UnderlyingActor;

            // Assert
            CollectionAssert.AreEqual(expected, actual: actor.SourceFolderPaths);
        }
开发者ID:kevinmcfarlane,项目名称:CloudBackupActors,代码行数:34,代码来源:SourceFolderTests.cs

示例14: Posts_Are_Imported

        public void Posts_Are_Imported()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { ImportFile, new MockFileData(ImportContent) }
            });

            var wordpressImporter = new WordpressImportSql(fileSystem, BaseSite, ImportFile);
            wordpressImporter.Import();

            Assert.True(fileSystem.File.Exists(BaseSite + "_posts\\2010-09-28-about.md"));
            Assert.True(fileSystem.File.Exists(BaseSite + "_posts\\2010-12-07-recyclez-votre-vieux-pc-avec-jolicloud-1-1.md"));
            Assert.True(fileSystem.AllPaths.Count() == 3);
            var postContentAbout = fileSystem.File.ReadAllText(BaseSite + "_posts\\2010-09-28-about.md");
            var headerAbout = postContentAbout.YamlHeader();

            Assert.Equal("About", headerAbout["title"].ToString());

            var postContentJolicloud = fileSystem.File.ReadAllText(BaseSite + "_posts\\2010-12-07-recyclez-votre-vieux-pc-avec-jolicloud-1-1.md");
            var headerJolicloud = postContentJolicloud.YamlHeader();

            Assert.Equal("Recyclez votre vieux PC avec Jolicloud 1.1", headerJolicloud["title"].ToString());
            Assert.NotNull(headerJolicloud["tags"]);
            Assert.NotNull(headerJolicloud["categories"]);
        }
开发者ID:MichaelPereira,项目名称:pretzel,代码行数:25,代码来源:WordpressSqlImportTests.cs

示例15: Initialize

        public static void Initialize(TestContext c)
        {
            var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
                                                        {
                                                            {
                                                                SourcePath1,
                                                                new MockFileData(string.Empty)
                                                                    {
                                                                        LastAccessTime =
                                                                            DateTime.Now
                                                                    }
                                                            },
                                                            {
                                                                SourcePath2,
                                                                new MockFileData(string.Empty)
                                                                    {
                                                                        LastAccessTime =
                                                                            DateTime.Now
                                                                                    .AddHours(1)
                                                                    }
                                                            },
                                                        });

            AssemblyFinderHelper.FileSystem = mockFileSystem;
        }
开发者ID:EdsonF,项目名称:LINQBridgeVs,代码行数:25,代码来源:AssemblyFinderHelperTests.cs


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