private static IEnumerable <EvaluationResult> EvaluateNotDependOnEachOther(IEnumerable <Slice> slices,
                                                                                   ICanBeEvaluated archRule,
                                                                                   Architecture architecture)
        {
            var slicesList = slices.ToList();

            foreach (var slice in slicesList)
            {
                var sliceDependencies = FindDependencies(slice, slicesList).Except(new[] { slice }).ToList();
                var passed            = !sliceDependencies.Any();
                var description       = slice.Description + " does not depend on another slice.";
                if (!passed)
                {
                    description = slice.Description + " does depend on other slices:";
                    foreach (var sliceDependency in sliceDependencies)
                    {
                        var depsToSlice = slice.Dependencies.Where(dependency =>
                                                                   sliceDependency.Types.Contains(dependency.Target))
                                          .Distinct(new TypeDependencyComparer()).ToList();
                        description += "\n" + slice.Description + " -> " + sliceDependency.Description;
                        description  = depsToSlice.Aggregate(description,
                                                             (current, dependency) =>
                                                             current + ("\n\t" + dependency.Origin + " -> " + dependency.Target));
                    }

                    description += "\n";
                }

                yield return(new EvaluationResult(slice, passed, description, archRule, architecture));
            }
        }
 public CombinedArchRuleCreator(ICanBeEvaluated oldRule, LogicalConjunction logicalConjunction,
                                BasicObjectProvider <TRuleType> basicObjectProvider)
 {
     _oldRule                = oldRule;
     _logicalConjunction     = logicalConjunction;
     _currentArchRuleCreator = new ArchRuleCreator <TRuleType>(basicObjectProvider);
 }
 public CombinedArchRule(ICanBeEvaluated firstRule, LogicalConjunction logicalConjunction,
                         ICanBeEvaluated secondRule)
 {
     _firstRule          = firstRule;
     _secondRule         = secondRule;
     _logicalConjunction = logicalConjunction;
 }
 public EvaluationResult([CanBeNull] ICanBeAnalyzed obj, bool passed, string description,
                         ICanBeEvaluated archRule, Architecture architecture)
 {
     EvaluatedObject = obj;
     Passed          = passed;
     Description     = description;
     ArchRule        = archRule;
     Architecture    = architecture;
 }
 public EvaluationResult(object obj, StringIdentifier evaluatedObjectIdentifier, bool passed, string description,
                         ICanBeEvaluated archRule, Architecture architecture)
 {
     EvaluatedObject           = obj;
     EvaluatedObjectIdentifier = evaluatedObjectIdentifier;
     Passed       = passed;
     Description  = description;
     ArchRule     = archRule;
     Architecture = architecture;
 }
Exemple #6
0
        private static IEnumerable <EvaluationResult> EvaluateBeFreeOfCycles(IEnumerable <Slice> slices,
                                                                             ICanBeEvaluated archRule,
                                                                             Architecture architecture)
        {
            var slicesList = slices.ToList();

            var cycles = slicesList.DetectCycles(slc => FindDependencies(slc, slicesList))
                         .Where(dependencyCycle => dependencyCycle.IsCyclic).ToList();

            if (cycles.Any())
            {
                foreach (var cycle in cycles)
                {
                    var description = "Cycle found:";
                    foreach (var slice in cycle.Contents)
                    {
                        var dependencies = slice.Dependencies.ToList();
                        foreach (var otherSlice in cycle.Contents.Except(new[] { slice }))
                        {
                            var depsToSlice = dependencies.Where(dependency =>
                                                                 otherSlice.Types.Contains(dependency.Target))
                                              .Distinct(new TypeDependencyComparer()).ToList();
                            if (depsToSlice.Any())
                            {
                                description += "\n" + slice.Description + " -> " + otherSlice.Description;
                                description  = depsToSlice.Aggregate(description,
                                                                     (current, dependency) =>
                                                                     current + ("\n\t" + dependency.Origin + " -> " + dependency.Target));
                            }
                        }
                    }

                    description += "\n";
                    var cycleIdentifier = new EnumerableIdentifier(cycle.Contents.Select(slice => slice.Identifier));
                    yield return(new EvaluationResult(cycle, cycleIdentifier, false, description, archRule,
                                                      architecture));
                }
            }
            else
            {
                var slicesIdentifier = new EnumerableIdentifier(slicesList.Select(slice => slice.Identifier));
                yield return(new EvaluationResult(slicesList, slicesIdentifier, true, "All Slices are free of cycles.",
                                                  archRule,
                                                  architecture));
            }
        }
        private static EvaluationResult CreateEvaluationResult(
            IEnumerable <ConditionElementResult> conditionElementResults,
            Architecture architecture, ICanBeEvaluated archRuleCreator)
        {
            var conditionElementResultsList = conditionElementResults.ToList();
            var analyzedObject = conditionElementResultsList.First().ConditionResult.AnalyzedObject;
            var passRule       = conditionElementResultsList.Aggregate(true,
                                                                       (currentResult, conditionElementResult) =>
                                                                       conditionElementResult.LogicalConjunction.Evaluate(currentResult,
                                                                                                                          conditionElementResult.ConditionResult.Pass));
            var description = analyzedObject.FullName;

            if (passRule)
            {
                description += " passed";
            }
            else
            {
                var first = true;
                var failDescriptionCache =
                    new List <string>(); //Prevent failDescriptions like "... failed because ... is public and is public"
                foreach (var conditionResult in conditionElementResultsList.Select(result => result.ConditionResult)
                         .Where(condResult =>
                                !condResult.Pass && !failDescriptionCache.Contains(condResult.FailDescription)))
                {
                    if (!first)
                    {
                        description += " and";
                    }

                    description += " " + conditionResult.FailDescription;
                    failDescriptionCache.Add(conditionResult.FailDescription);
                    first = false;
                }
            }

            var identifier = new StringIdentifier(analyzedObject.FullName);

            return(new EvaluationResult(analyzedObject, identifier, passRule, description, archRuleCreator,
                                        architecture));
        }
Exemple #8
0
 public CombinedArchRuleDefinition(ICanBeEvaluated oldRule, LogicalConjunction logicalConjunction)
 {
     _oldRule            = oldRule;
     _logicalConjunction = logicalConjunction;
 }
Exemple #9
0
        public IEnumerable <EvaluationResult> EvaluateConditions(IEnumerable <T> filteredObjects,
                                                                 Architecture architecture, ICanBeEvaluated archRuleCreator)
        {
            var filteredObjectsList = filteredObjects.ToList();

            if (filteredObjectsList.IsNullOrEmpty())
            {
                yield return(new EvaluationResult(null, CheckEmpty(), "There are no objects matching the criteria",
                                                  archRuleCreator, architecture));

                yield break;
            }

            var conditionResults = _conditionElements.Select(conditionElement =>
                                                             conditionElement.Check(filteredObjectsList, architecture).ToList()).ToList();

            for (var i = 0; i < filteredObjectsList.Count; i++)
            {
                var index = i;
                yield return(CreateEvaluationResult(conditionResults.Select(results => results[index]), architecture,
                                                    archRuleCreator));
            }
        }
        public IEnumerable <EvaluationResult> EvaluateConditions(IEnumerable <T> filteredObjects,
                                                                 Architecture architecture, ICanBeEvaluated archRuleCreator)
        {
            var filteredObjectsList = filteredObjects.ToList();

            if (filteredObjectsList.IsNullOrEmpty())
            {
                yield return(new EvaluationResult(null, new StringIdentifier(""), CheckEmpty(),
                                                  "There are no objects matching the criteria", archRuleCreator, architecture));

                yield break;
            }

            var conditionResults = _conditionElements.Select(conditionElement =>
                                                             conditionElement.Check(filteredObjectsList, architecture).ToList()).ToList();

            foreach (var t in filteredObjectsList)
            {
                yield return(CreateEvaluationResult(
                                 conditionResults.Select(results => results.Find(x => x.ConditionResult.AnalyzedObject.Equals(t))),
                                 architecture, archRuleCreator));
            }
        }