示例#1
0
 public static void Setup(TestContext context)
 {
     _architecture         = new ArchLoader().LoadAssemblies(typeof(RuleEvaluationTests).Assembly).Build();
     _trueRule             = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
     _falseRule            = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
     _expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
 }
示例#2
0
        public IEnumerable <EvaluationResult> Evaluate(Architecture architecture)
        {
            var evalResults = _frozenRule.Evaluate(architecture).ToList();
            var evalResultsIgnoringFrozen  = new List <EvaluationResult>();
            var identifiersOfFailedResults = evalResults.Where(result => !result.Passed)
                                             .Select(result => result.EvaluatedObjectIdentifier);

            if (!_violationStore.RuleAlreadyFrozen(_frozenRule))
            {
                _violationStore.StoreCurrentViolations(_frozenRule, identifiersOfFailedResults);
                evalResultsIgnoringFrozen.AddRange(evalResults.Select(MarkAsPassed));
            }
            else
            {
                var frozenViolations          = _violationStore.GetFrozenViolations(_frozenRule).ToList();
                var stillUnresolvedViolations = new List <StringIdentifier>();
                foreach (var evalResult in evalResults)
                {
                    if (frozenViolations.Contains(evalResult.EvaluatedObjectIdentifier,
                                                  new StringIdentifierComparer()) && !evalResult.Passed)
                    {
                        evalResultsIgnoringFrozen.Add(MarkAsPassed(evalResult));
                        stillUnresolvedViolations.Add(evalResult.EvaluatedObjectIdentifier);
                    }
                    else
                    {
                        evalResultsIgnoringFrozen.Add(evalResult);
                    }
                }

                _violationStore.StoreCurrentViolations(_frozenRule, stillUnresolvedViolations);
            }

            return(evalResultsIgnoringFrozen);
        }
示例#3
0
 /// <summary>
 ///     Verifies that the architecture meets the criteria of the archrule.
 /// </summary>
 /// <param name="architecture">The architecture to be tested</param>
 /// <param name="archRule">The rule to test the architecture with</param>
 public static void FulfilsRule(Architecture architecture, IArchRule archRule)
 {
     if (!archRule.HasNoViolations(architecture))
     {
         Assert.Fail(archRule.Evaluate(architecture).ToErrorMessage());
     }
 }
示例#4
0
 public void CreateErrorMessageTest()
 {
     Assert.Equal(ExpectedTrueArchRuleErrorMessage, TrueArchRule1.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(ExpectedTrueArchRuleErrorMessage, TrueArchRule2.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule1ErrorMessage, WrongArchRule1.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule2ErrorMessage, WrongArchRule2.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule3ErrorMessage, WrongArchRule3.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule4ErrorMessage, WrongArchRule4.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule5ErrorMessage, WrongArchRule5.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule6ErrorMessage, WrongArchRule6.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule7ErrorMessage, WrongArchRule7.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule8ErrorMessage, WrongArchRule8.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule1AndWrongArchRule3ErrorMessage,
                  WrongArchRule1AndWrongArchRule3.Evaluate(Architecture).ToErrorMessage());
     Assert.Equal(_expectedWrongArchRule4AndWrongArchRule8ErrorMessage,
                  WrongArchRule4AndWrongArchRule8.Evaluate(Architecture).ToErrorMessage());
 }
示例#5
0
 public IEnumerable <EvaluationResult> EvaluateRule(IArchRule archRule)
 {
     return(archRule.Evaluate(this));
 }
示例#6
0
 /// <summary>
 ///     Creates a new instance of the <see href="FailedArchRuleException" /> class.
 /// </summary>
 /// <param name="architecture">The architecture which was tested</param>
 /// <param name="archRule">The archrule that failed</param>
 public FailedArchRuleException(Architecture architecture, IArchRule archRule)
     : this(archRule.Evaluate(architecture))
 {
 }