Esempio n. 1
0
        public void CheckIfItsValid_ArchitecturalRule_Error_NullReference()
        {
            ArchitecturalRule rule = null;

            var result = Record.Exception(() =>
            {
                rule.CheckIfItsValid();
            });

            Assert.Null(result);
        }
        public static IEnumerable <ArchitecturalViolationOccurrence> GetViolatingOccurrences(
            ArchitecturalRule rule,
            IDictionary <string, IEnumerable <string> > layersNamespaces,
            IEnumerable <Structure> structures)
        {
            if (rule == null)
            {
                return(Enumerable.Empty <ArchitecturalViolationOccurrence>());
            }

            rule.CheckIfItsValid();

            var originNamespaces = layersNamespaces[rule.OriginLayer];
            var targetNamespaces = layersNamespaces[rule.TargetLayer];

            var originStructures = structures
                                   .Where(s => originNamespaces.Any(n => n.Equals(s.Namespace)));

            if (rule.RuleOperator == RuleOperator.NeedToRelate)
            {
                return(GetNeedToRelateViolatingOccurrences(
                           targetNamespaces, originStructures, rule.RelationTypes));
            }
            else if (rule.RuleOperator == RuleOperator.CanNotRelate)
            {
                return(GetCanNotRelateViolatingOccurrences(
                           targetNamespaces, originStructures, rule.RelationTypes));
            }
            else
            {
                var anotherStructures = structures
                                        .Where(s => !originNamespaces.Any(n => n.Equals(s.Namespace)));

                if (rule.RuleOperator == RuleOperator.OnlyNeedToRelate)
                {
                    return(GetOnlyNeedToRelateViolatingOccurrences(
                               targetNamespaces, originStructures,
                               anotherStructures, rule.RelationTypes));
                }
                else if (rule.RuleOperator == RuleOperator.OnlyCanRelate)
                {
                    return(GetOnlyCanRelateViolatingOccurrences(
                               targetNamespaces, anotherStructures, rule.RelationTypes));
                }
            }

            return(Enumerable.Empty <ArchitecturalViolationOccurrence>());
        }
Esempio n. 3
0
        public void CheckIfItsValid_ArchitecturalRule_Success()
        {
            var rule = new ArchitecturalRule()
            {
                OriginLayer  = "Origin",
                TargetLayer  = "Target",
                RuleOperator = RuleOperator.OnlyNeedToRelate
            };

            var result = Record.Exception(() =>
            {
                rule.CheckIfItsValid();
            });

            Assert.Null(result);
        }