Exemplo n.º 1
0
 public override void Initialize(TestAnalysisContext context)
 {
     if (s_testRuleBehaviors == TestRuleBehaviors.RaiseExceptionInvokingInitialize)
     {
         throw new InvalidOperationException(nameof(TestRuleBehaviors.RaiseExceptionInvokingInitialize));
     }
 }
Exemplo n.º 2
0
        public override AnalysisApplicability CanAnalyze(TestAnalysisContext context, out string reasonIfNotApplicable)
        {
            AnalysisApplicability applicability = AnalysisApplicability.ApplicableToSpecifiedTarget;

            reasonIfNotApplicable = null;

            if (s_testRuleBehaviors == TestRuleBehaviors.RaiseExceptionInvokingCanAnalyze)
            {
                throw new InvalidOperationException(nameof(TestRuleBehaviors.RaiseExceptionInvokingCanAnalyze));
            }

            if (context.Options.RegardAnalysisTargetAsNotApplicable)
            {
                reasonIfNotApplicable = "testing NotApplicableToSpecifiedTarget";
                return(AnalysisApplicability.NotApplicableToSpecifiedTarget);
            }

            string fileName = Path.GetFileName(context.TargetUri.LocalPath);

            if (fileName.Contains("NotApplicable"))
            {
                reasonIfNotApplicable = "test was configured to find target not applicable.";
                applicability         = AnalysisApplicability.NotApplicableToSpecifiedTarget;
            }

            return(applicability);
        }
Exemplo n.º 3
0
 public override void Initialize(TestAnalysisContext context)
 {
     if (context.Policy.GetProperty(Behaviors).HasFlag(TestRuleBehaviors.RaiseExceptionInvokingInitialize))
     {
         throw new InvalidOperationException(nameof(TestRuleBehaviors.RaiseExceptionInvokingInitialize));
     }
 }
Exemplo n.º 4
0
 public override void Analyze(TestAnalysisContext context)
 {
     if (context.Policy.GetProperty(Behaviors) == TestRuleBehaviors.LogError)
     {
         context.Logger.Log(this,
                            new Result()
         {
             RuleId  = this.Id,
             Level   = ResultLevel.Error,
             Message = "Simple test rule message."
         });
     }
 }
        public override AnalysisApplicability CanAnalyze(TestAnalysisContext context, out string reasonIfNotApplicable)
        {
            AnalysisApplicability applicability = AnalysisApplicability.ApplicableToSpecifiedTarget;

            reasonIfNotApplicable = null;

            string fileName = Path.GetFileName(context.TargetUri.LocalPath);

            if (fileName.Contains("NotApplicable"))
            {
                reasonIfNotApplicable = "test was configured to find target not applicable.";
                applicability         = AnalysisApplicability.NotApplicableToSpecifiedTarget;
            }

            return(applicability);
        }
Exemplo n.º 6
0
        public void Warnings_LogRuleWasExplicitlyDisabled()
        {
            var testLogger            = new TestMessageLogger();
            var binaryAnalysisContext = new TestAnalysisContext();

            binaryAnalysisContext.Logger = testLogger;

            string ruleId = nameof(ruleId);

            Warnings.LogRuleExplicitlyDisabled(binaryAnalysisContext, ruleId);

            testLogger.Messages.Should().BeNull();
            testLogger.ToolNotifications.Should().BeNull();
            testLogger.ConfigurationNotifications.Count.Should().Equals(1);
            testLogger.ConfigurationNotifications[0].Descriptor.Id.Should().Equals(ruleId);
        }
 public override void Analyze(TestAnalysisContext context)
 {
 }
Exemplo n.º 8
0
        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()));
            }
        }
        public override void Analyze(TestAnalysisContext context)
        {
            if (context.Policy.GetProperty(Behaviors) == TestRuleBehaviors.LogError)
            {
                context.Logger.Log(this,
                                   new Result()
                {
                    RuleId  = this.Id,
                    Level   = FailureLevel.Error,
                    Message = new Message {
                        Text = "Simple test rule message."
                    }
                });
            }

            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()));
            }
        }
Exemplo n.º 10
0
        public override void Analyze(TestAnalysisContext context)
        {
            // We do not access the static test rule behaviors here. We also want to
            // ensure this data is only set with flags (if any) that are legal for
            // this property.
            (s_testRuleBehaviors & s_testRuleBehaviors.AccessibleOutsideOfContextOnly())
            .Should().Be(s_testRuleBehaviors);

            // Now we'll make sure the context test rule behaviors are restricted
            // to settings that are legal to pass in a context object.
            TestRuleBehaviors testRuleBehaviors = context.Policy.GetProperty(Behaviors);

            (testRuleBehaviors & testRuleBehaviors.AccessibleWithinContextOnly())
            .Should().Be(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()));
            }
        }