本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}
示例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"]);
}
示例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;
}