本文整理汇总了C#中Chutzpah.Models.ChutzpahTestSettingsFile类的典型用法代码示例。如果您正苦于以下问题:C# ChutzpahTestSettingsFile类的具体用法?C# ChutzpahTestSettingsFile怎么用?C# ChutzpahTestSettingsFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChutzpahTestSettingsFile类属于Chutzpah.Models命名空间,在下文中一共展示了ChutzpahTestSettingsFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public void Process(IFrameworkDefinition frameworkDefinition, ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings)
{
if (!referencedFile.IsFileUnderTest)
{
return;
}
var regExp = settings.TestPatternRegex ?? GetTestPattern(referencedFile,testFileText, settings);
var lines = fileSystem.GetLines(referencedFile.Path);
int lineNum = 1;
foreach (var line in lines)
{
var match = regExp.Match(line);
while (match.Success)
{
var testNameGroup = match.Groups["TestName"];
var testName = testNameGroup.Value;
if (!string.IsNullOrWhiteSpace(testName))
{
referencedFile.FilePositions.Add(lineNum, testNameGroup.Index + 1, testName);
}
match = match.NextMatch();
}
lineNum++;
}
}
示例2: GetTestPattern
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings)
{
var mochaFrameworkDefinition = MochaDefinition.GetInterfaceType(settings, referencedFile.Path, testFileText);
var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase);
switch (mochaFrameworkDefinition)
{
case Constants.MochaQunitInterface:
return isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript;
case Constants.MochaBddInterface:
return isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript;
case Constants.MochaTddInterface:
return isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript;
case Constants.MochaExportsInterface:
return isCoffeeFile ? RegexPatterns.MochaExportsTestRegexCoffeeScript : RegexPatterns.MochaExportsTestRegexJavaScript;
default:
return isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript;
}
}
示例3: GetTestHarnessTemplatePath
private string GetTestHarnessTemplatePath(IFrameworkDefinition definition, ChutzpahTestSettingsFile chutzpahTestSettings)
{
string templatePath = null;
if (!string.IsNullOrEmpty(chutzpahTestSettings.CustomTestHarnessPath))
{
// If CustomTestHarnessPath is absolute path then Path.Combine just returns it
var harnessPath = Path.Combine(chutzpahTestSettings.SettingsFileDirectory, chutzpahTestSettings.CustomTestHarnessPath);
var fullPath = fileProbe.FindFilePath(harnessPath);
if (fullPath != null)
{
ChutzpahTracer.TraceInformation("Using Custom Test Harness from {0}", fullPath);
templatePath = fullPath;
}
else
{
ChutzpahTracer.TraceError("Cannot find Custom Test Harness at {0}", chutzpahTestSettings.CustomTestHarnessPath);
}
}
if (templatePath == null)
{
templatePath = fileProbe.GetPathInfo(Path.Combine(Constants.TestFileFolder, definition.GetTestHarness(chutzpahTestSettings))).FullPath;
ChutzpahTracer.TraceInformation("Using builtin Test Harness from {0}", templatePath);
}
return templatePath;
}
示例4: GetInterfaceType
public static string GetInterfaceType(ChutzpahTestSettingsFile chutzpahTestSettings, string testFilePath, string testFileText)
{
if(!string.IsNullOrEmpty(chutzpahTestSettings.MochaInterface)
&& knownInterfaces.Contains(chutzpahTestSettings.MochaInterface,StringComparer.OrdinalIgnoreCase))
{
return chutzpahTestSettings.MochaInterface.ToLowerInvariant();
}
var isCoffeeFile = testFilePath.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase);
if (isCoffeeFile)
{
if (RegexPatterns.MochaBddTestRegexCoffeeScript.IsMatch(testFileText)) return Constants.MochaBddInterface;
if (RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript.IsMatch(testFileText))
{
return RegexPatterns.MochaTddSuiteRegexCoffeeScript.IsMatch(testFileText) ? Constants.MochaTddInterface : Constants.MochaQunitInterface;
}
if (RegexPatterns.MochaExportsTestRegexCoffeeScript.IsMatch(testFileText)) return Constants.MochaExportsInterface;
}
else
{
if (RegexPatterns.MochaBddTestRegexJavaScript.IsMatch(testFileText)) return Constants.MochaBddInterface;
if (RegexPatterns.MochaTddOrQunitTestRegexJavaScript.IsMatch(testFileText))
{
return RegexPatterns.MochaTddSuiteRegexJavaScript.IsMatch(testFileText) ? Constants.MochaTddInterface : Constants.MochaQunitInterface;
}
if (RegexPatterns.MochaExportsTestRegexJavaScript.IsMatch(testFileText)) return Constants.MochaExportsInterface;
}
return Constants.MochaBddInterface;
}
示例5: SetupAmdPathsIfNeeded
private void SetupAmdPathsIfNeeded(ChutzpahTestSettingsFile chutzpahTestSettings, List<ReferencedFile> referencedFiles, string testHarnessDirectory)
{
if (chutzpahTestSettings.TestHarnessReferenceMode == TestHarnessReferenceMode.AMD)
{
referenceProcessor.SetupAmdFilePaths(referencedFiles, testHarnessDirectory, chutzpahTestSettings);
}
}
示例6: ProcessTransforms
private void ProcessTransforms(ChutzpahTestSettingsFile settings, TestCaseSummary overallSummary, TransformResult results)
{
// Do this here per settings file in case an individual transformer has any associated state
// - we want them fresh
var knownTransforms =
transformerProvider
.GetTransformers(fileSystem)
.ToDictionary(x => x.Name, x => x, StringComparer.InvariantCultureIgnoreCase);
foreach (var transformConfig in settings.Transforms)
{
SummaryTransformer transform = null;
if (knownTransforms.TryGetValue(transformConfig.Name, out transform))
{
var outputPath = transformConfig.Path;
if (!fileSystem.IsPathRooted(outputPath) && !string.IsNullOrWhiteSpace(transformConfig.SettingsFileDirectory))
{
outputPath = fileSystem.GetFullPath(Path.Combine(transformConfig.SettingsFileDirectory, outputPath));
}
// TODO: In future, this would ideally split out the summary to just those parts
// relevant to the files associated with the settings file being handled
transform.Transform(overallSummary, outputPath);
results.AddResult(transform.Name, outputPath);
}
}
}
示例7: GetTestPattern
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings)
{
var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase);
var regExp = isCoffeeFile
? RegexPatterns.QUnitTestRegexCoffeeScript
: RegexPatterns.QUnitTestRegexJavaScript;
return regExp;
}
示例8: GenerateCompiledSources
public override IDictionary<string, string> GenerateCompiledSources(IEnumerable<ReferencedFile> referencedFiles, ChutzpahTestSettingsFile chutzpahTestSettings)
{
var compiledMap = (from referencedFile in referencedFiles
let content = fileSystem.GetText(referencedFile.Path)
let jsText = GetOrAddCompiledToCache(content, referencedFile.Path)
select new { FileName = referencedFile.Path, Content = jsText })
.ToDictionary(x => x.FileName, x => x.Content);
return compiledMap;
}
示例9: TestHarness
public TestHarness(ChutzpahTestSettingsFile chutzpahTestSettings, TestOptions testOptions, IEnumerable<ReferencedFile> referencedFiles, IFileSystemWrapper fileSystem)
{
this.chutzpahTestSettings = chutzpahTestSettings;
this.testOptions = testOptions;
this.referencedFiles = referencedFiles;
this.fileSystem = fileSystem;
BuildTags(referencedFiles);
CleanupTestHarness();
}
示例10: Will_set_settings_file_directory
public void Will_set_settings_file_directory()
{
var mockFileProbe = new Mock<IFileProbe>();
var mockSerializer = new Mock<IJsonSerializer>();
var settings = new ChutzpahTestSettingsFile();
mockFileProbe.Setup(x => x.FindTestSettingsFile(It.IsAny<string>())).Returns(@"C:\settingsDir\settingsFile.json");
mockSerializer.Setup(x => x.DeserializeFromFile<ChutzpahTestSettingsFile>(It.IsAny<string>())).Returns(settings);
ChutzpahTestSettingsFile.Read("dir", mockFileProbe.Object, mockSerializer.Object);
Assert.Equal(@"C:\settingsDir", settings.SettingsFileDirectory);
}
示例11: Will_set_custom_harness_directory_based_relative_to_settings_file_directory
public void Will_set_custom_harness_directory_based_relative_to_settings_file_directory()
{
var mockFileProbe = new Mock<IFileProbe>();
var mockSerializer = new Mock<IJsonSerializer>();
var settings = new ChutzpahTestSettingsFile { TestHarnessLocationMode = TestHarnessLocationMode.Custom, TestHarnessDirectory = "custom" };
mockFileProbe.Setup(x => x.FindTestSettingsFile(It.IsAny<string>())).Returns(@"C:\settingsDir2\settingsFile.json");
mockFileProbe.Setup(x => x.FindFolderPath(@"C:\settingsDir2\custom")).Returns(@"customPath");
mockSerializer.Setup(x => x.DeserializeFromFile<ChutzpahTestSettingsFile>(It.IsAny<string>())).Returns(settings);
ChutzpahTestSettingsFile.Read("dir2", mockFileProbe.Object, mockSerializer.Object);
Assert.Equal(@"customPath", settings.TestHarnessDirectory);
}
示例12: Will_get_cached_settings_given_same_starting_directory
public void Will_get_cached_settings_given_same_starting_directory()
{
var mockFileProbe = new Mock<IFileProbe>();
var mockSerializer = new Mock<IJsonSerializer>();
var settings = new ChutzpahTestSettingsFile();
mockFileProbe.Setup(x => x.FindTestSettingsFile("dir3")).Returns(@"C:\settingsDir3\settingsFile.json");
mockSerializer.Setup(x => x.DeserializeFromFile<ChutzpahTestSettingsFile>(It.IsAny<string>())).Returns(settings);
ChutzpahTestSettingsFile.Read("dir3", mockFileProbe.Object, mockSerializer.Object);
var cached = ChutzpahTestSettingsFile.Read("dir3", mockFileProbe.Object, mockSerializer.Object);
Assert.Equal(@"C:\settingsDir3", cached.SettingsFileDirectory);
}
示例13: GetReferencedFiles
/// <summary>
/// Scans the test file extracting all referenced files from it.
/// </summary>
/// <param name="referencedFiles">The list of referenced files</param>
/// <param name="definition">Test framework defintition</param>
/// <param name="textToParse">The content of the file to parse and extract from</param>
/// <param name="currentFilePath">Path to the file under test</param>
/// <param name="chutzpahTestSettings"></param>
/// <returns></returns>
public void GetReferencedFiles(List<ReferencedFile> referencedFiles, IFrameworkDefinition definition, ChutzpahTestSettingsFile chutzpahTestSettings)
{
var filesUnderTests = referencedFiles.Where(x => x.IsFileUnderTest).ToList();
var referencePathSet = new HashSet<string>(referencedFiles.Select(x => x.Path), StringComparer.OrdinalIgnoreCase);
// Process the references that the user specifies in the chutzpah settings file
foreach (var reference in chutzpahTestSettings.References.Where(reference => reference != null))
{
// The path we assume default to the chuzpah.json directory if the Path property is not set
var referencePath = string.IsNullOrEmpty(reference.Path) ? reference.SettingsFileDirectory : reference.Path;
ProcessFilePathAsReference(
referencePathSet,
definition,
reference.SettingsFileDirectory,
chutzpahTestSettings,
referencePath,
referencedFiles,
new ReferencePathSettings(reference));
}
// Process the references defined using /// <reference comments in test file contents
foreach (var fileUnderTest in filesUnderTests)
{
var testFileText = fileSystem.GetText(fileUnderTest.Path);
definition.Process(fileUnderTest, testFileText, chutzpahTestSettings);
if (fileUnderTest.ExpandReferenceComments)
{
var result = GetReferencedFiles(
referencePathSet,
definition,
testFileText,
fileUnderTest.Path,
chutzpahTestSettings);
var flattenedReferenceTree = from root in result
from flattened in FlattenReferenceGraph(root)
select flattened;
referencedFiles.AddRange(flattenedReferenceTree);
}
}
}
示例14: Generate
/// <summary>
/// This will get called for the test file and all referenced files.
/// If the referenced file can be handled it generate a .js file and sets to the reference files generatedfilepath and adds the new file path to the temporary file collection
/// If it can't handle the file it does nothing
/// </summary>
public virtual void Generate(IEnumerable<ReferencedFile> referencedFiles, IList<string> temporaryFiles, ChutzpahTestSettingsFile chutzpahTestSettings)
{
// Filter down to just the referenced files this generator supports
referencedFiles = referencedFiles.Where(CanHandleFile).ToList();
if (referencedFiles.Any())
{
var compiledMap = GenerateCompiledSources(referencedFiles, chutzpahTestSettings);
foreach (var referencedFile in referencedFiles)
{
if (!compiledMap.ContainsKey(referencedFile.Path)) continue;
var jsText = compiledMap[referencedFile.Path];
WriteGeneratedReferencedFile(referencedFile, jsText, temporaryFiles);
}
}
}
示例15: GenerateCompiledSources
public override IDictionary<string, string> GenerateCompiledSources(IEnumerable<ReferencedFile> referencedFiles, ChutzpahTestSettingsFile chutzpahTestSettings)
{
var referenceList = (from referencedFile in referencedFiles
let content = fileSystem.GetText(referencedFile.Path)
select new TypeScriptFile { FileName = referencedFile.Path, Content = content }).ToList();
InsertLibDeclarationFile(referenceList);
var compiledMap = new Dictionary<string, string>();
var needsCompileMap = referenceList.ToDictionary(x => x.FileName, x => x.Content);
if (needsCompileMap.Count > 0)
{
var needsCompileMapJson = jsonSerializer.Serialize(needsCompileMap);
var resultJson = typeScriptEngine.Compile(needsCompileMapJson, chutzpahTestSettings.TypeScriptCodeGenTarget.ToString(), chutzpahTestSettings.TypeScriptModuleKind.ToString());
compiledMap = jsonSerializer.Deserialize<Dictionary<string, string>>(resultJson);
}
return compiledMap.ToDictionary(x => ToFilePath(x.Key), x => x.Value);
}