public override void Analyze(TestAnalysisContext context)
{
TestRuleBehaviors testRuleBehaviors = context.Policy.GetProperty(Behaviors);
// Currently, we only allow test rule behavior either be passed by context
// or injected via static data, not by both mechanisms.
(s_testRuleBehaviors == 0 || testRuleBehaviors == 0).Should().BeTrue();
if (testRuleBehaviors == TestRuleBehaviors.None)
{
testRuleBehaviors = s_testRuleBehaviors;
}
;
switch (testRuleBehaviors)
{
case TestRuleBehaviors.RaiseExceptionInvokingAnalyze:
{
throw new InvalidOperationException(nameof(TestRuleBehaviors.RaiseExceptionInvokingAnalyze));
}
case TestRuleBehaviors.RaiseTargetParseError:
{
Errors.LogTargetParseError(
context,
new Region
{
StartLine = 42,
StartColumn = 54
},
"Could not parse target.");
break;
}
case TestRuleBehaviors.LogError:
{
context.Logger.Log(this,
new Result
{
RuleId = this.Id,
Level = FailureLevel.Error,
Message = new Message {
Text = "Simple test rule message."
}
});
break;
}
default:
{
break;
}
}
string fileName = Path.GetFileName(context.TargetUri.LocalPath);
if (fileName.Contains(nameof(FailureLevel.Error)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(FailureLevel.Error, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Failed),
context.TargetUri.GetFileName()));
}
if (fileName.Contains(nameof(FailureLevel.Warning)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(FailureLevel.Warning, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Failed),
context.TargetUri.GetFileName()));
}
if (fileName.Contains(nameof(FailureLevel.Note)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(FailureLevel.Note, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Note),
context.TargetUri.GetFileName()));
}
else if (fileName.Contains(nameof(ResultKind.Pass)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(ResultKind.Pass, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Pass),
context.TargetUri.GetFileName()));
}
else if (fileName.Contains(nameof(ResultKind.Review)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(ResultKind.Review, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Review),
context.TargetUri.GetFileName()));
}
else if (fileName.Contains(nameof(ResultKind.Open)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(ResultKind.Open, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Open),
context.TargetUri.GetFileName()));
}
else if (fileName.Contains(nameof(ResultKind.Informational)))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(ResultKind.Informational, context, null,
nameof(SkimmerBaseTestResources.TEST1001_Information),
context.TargetUri.GetFileName()));
}
}