Exemple #1
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>
 /// <exception cref="FailedArchRuleException">Thrown if the rule is violated</exception>
 public static void CheckRule(Architecture architecture, IArchRule archRule)
 {
     if (!archRule.HasNoViolations(architecture))
     {
         throw new FailedArchRuleException(architecture, archRule);
     }
 }
 /// <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());
     }
 }
Exemple #3
0
        public void Cycles()
        {
            IArchRule rule = Slices().Matching("Module.(*)").Should().BeFreeOfCycles();

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
        public void All_Interfaces_Are_In_Contracts_Namespace()
        {
            IArchRule interfacesShouldBeInContractsLayer =
                ArchRuleDefinition.Interfaces().That().Are(Interfaces).Should().Be(InterfaceLayer);

            Assert.IsTrue(interfacesShouldBeInContractsLayer.HasNoViolations(Architecture));
        }
Exemple #5
0
        public void AttributeAccess()
        {
            IArchRule rule = Classes().That().DoNotHaveAnyAttributes(typeof(Display)).Should()
                             .NotDependOnAny(Classes().That().AreAssignableTo(typeof(ICanvas)));

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
Exemple #6
0
        public void ClassNamespaceContainment()
        {
            IArchRule rule = Classes().That().HaveNameContaining("Canvas").Should()
                             .ResideInNamespace(typeof(ICanvas).Namespace);

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
Exemple #7
0
        public void InheritanceNaming()
        {
            IArchRule rule = Classes().That().AreAssignableTo(typeof(ICar)).Should()
                             .HaveNameContaining("Car");

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
Exemple #8
0
        public void ClassDependency()
        {
            IArchRule rule = Classes().That().AreAssignableTo(typeof(ICar)).Should()
                             .NotDependOnAny(Classes().That().AreAssignableTo(typeof(ICanvas)));

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
Exemple #9
0
        public void NamespaceDependency()
        {
            IArchRule rule = Types().That().ResideInNamespace("Model").Should()
                             .NotDependOnAny(Types().That().ResideInNamespace("Controller"));

            Assert.False(rule.HasNoViolations(Architecture));
            //rule.Check(Architecture);
        }
Exemple #10
0
        public void All_Classes_Have_Correct_Namespace()
        {
            IArchRule classesHaveCorrectNamespace =
                ArchRuleDefinition.Classes().That().Are(Classes).Should().Be(Layer);
            IArchRule interfacesHaveCorrectNamespace =
                ArchRuleDefinition.Interfaces().That().Are(Interfaces).Should().Be(Layer);

            IArchRule combinedArchRule =
                classesHaveCorrectNamespace.And(interfacesHaveCorrectNamespace);

            Assert.IsTrue(combinedArchRule.HasNoViolations(Architecture));
        }
Exemple #11
0
        public void BasicRulesBehaveAsExpected()
        {
            Assert.True(ThisClassExists.HasNoViolations(Architecture));
            Assert.False(ThisClassDoesNotExist.HasNoViolations(Architecture));
            Assert.True(ThisCondition1.HasNoViolations(Architecture));
            Assert.True(ThisCondition2.HasNoViolations(Architecture));
            Assert.True(OtherCondition1.HasNoViolations(Architecture));
            Assert.True(OtherCondition2.HasNoViolations(Architecture));
            Assert.False(FalseThisCondition1.HasNoViolations(Architecture));
            Assert.False(FalseThisCondition2.HasNoViolations(Architecture));

            Assert.True(ThisShouldCondition1.HasNoViolations(Architecture));
            Assert.True(ThisShouldCondition2.HasNoViolations(Architecture));
            Assert.True(OtherShouldCondition1.HasNoViolations(Architecture));
            Assert.True(OtherShouldCondition2.HasNoViolations(Architecture));
            Assert.False(FalseThisShouldCondition1.HasNoViolations(Architecture));
            Assert.False(FalseThisShouldCondition2.HasNoViolations(Architecture));
        }
Exemple #12
0
        public void Check_Infrastructure_Dependencies()
        {
            IArchRule infrastructureLayerShouldNotAccessControllerLayer =
                ArchRuleDefinition.Types().That().Are(InfrastructureLayer).Should().NotDependOnAny(ControllerLayer);

            IArchRule infrastructureLayerShouldAccessDomainLayer =
                ArchRuleDefinition.Types().That().Are(InfrastructureLayer).Should().DependOnAny(DomainLayer);

            IArchRule infrastructureLayerShouldNotAccessApplicationLayer =
                ArchRuleDefinition.Types().That().Are(InfrastructureLayer).Should().NotDependOnAny(ApplicationLayer);

            IArchRule combinedArchRule =
                infrastructureLayerShouldNotAccessControllerLayer
                .And(infrastructureLayerShouldAccessDomainLayer)
                .And(infrastructureLayerShouldNotAccessApplicationLayer);

            Assert.IsTrue(combinedArchRule.HasNoViolations(Architecture));
        }
Exemple #13
0
 public bool FulfilsRule(IArchRule archRule)
 {
     return(archRule.HasNoViolations(this));
 }