本文整理汇总了C#中FileSystem.GetFilesByExtension方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystem.GetFilesByExtension方法的具体用法?C# FileSystem.GetFilesByExtension怎么用?C# FileSystem.GetFilesByExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem.GetFilesByExtension方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchTest
public async Task BatchTest()
{
FileSystem fs = new FileSystem();
string path = @"C:\PathToSpecs"; //path to specs
Assert.True(fs.DirectoryExists(path), $"{path} does not exist");
// get all of the json and yaml files from filesystem
string[] files = fs.GetFilesByExtension(path, SearchOption.AllDirectories, "json", "yaml");
Assert.True(files.Count() > 0, $"{path} does not contain any json or yaml files");
foreach (string file in files)
{
// Comment this block out if not needed
if (!fs.ReadFileAsText(file).Contains(@"""swagger"": ""2.0"""))
{
//skip files that are not swagger files.
continue;
}
using (var memoryFileSystem = GenerateCodeForTestFromSpec(file))
{
// Expected Files
Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);
Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\Models\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);
var result = await Compile(memoryFileSystem);
// filter the warnings
var warnings = result.Messages.Where(
each => each.Severity == DiagnosticSeverity.Warning
&& !SuppressWarnings.Contains(each.Id)).ToArray();
// use this to dump the files to disk for examination
// memoryFileSystem.SaveFilesToTemp(file.Name);
// filter the errors
var errors = result.Messages.Where(each => each.Severity == DiagnosticSeverity.Error).ToArray();
Write(warnings, memoryFileSystem);
Write(errors, memoryFileSystem);
// use this to write out all the messages, even hidden ones.
// Write(result.Messages, memoryFileSystem);
// Don't proceed unless we have zero Warnings.
Assert.Empty(warnings);
// Don't proceed unless we have zero Errors.
Assert.Empty(errors);
// Should also succeed.
Assert.True(result.Succeeded);
}
}
}