예제 #1
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));
        }
예제 #2
0
        public void CombinedArchRuleAndTest()
        {
            var thisClassExistsAndThisClassExists1 =
                ThisClassExists.And().Classes().That().Are(ThisClass).Should().Exist();
            var thisClassExistsAndThisClassDoesNotExist1 =
                ThisClassExists.And().Classes().That().Are(ThisClass).Should().NotExist();
            var thisClassDoesNotExistAndThisClassExists1 =
                ThisClassDoesNotExist.And().Classes().That().Are(ThisClass).Should().Exist();
            var thisClassDoesNotExistAndThisClassDoesNotExist1 =
                ThisClassDoesNotExist.And().Classes().That().Are(ThisClass).Should().NotExist();


            var thisClassExistsAndThisClassExists2             = ThisClassExists.And(ThisClassExists);
            var thisClassExistsAndThisClassDoesNotExist2       = ThisClassExists.And(ThisClassDoesNotExist);
            var thisClassDoesNotExistAndThisClassExists2       = ThisClassDoesNotExist.And(ThisClassExists);
            var thisClassDoesNotExistAndThisClassDoesNotExist2 = ThisClassDoesNotExist.And(ThisClassDoesNotExist);

            var thisClassExistsAndThisClassExistsAndThisClassExists =
                ThisClassExists.And(thisClassExistsAndThisClassExists2);
            var thisClassExistsAndThisClassExistsAndThisClassExistsAndThisClassExists =
                thisClassExistsAndThisClassExists2.And(thisClassExistsAndThisClassExists2);
            var thisClassExistsAndThisClassExistsAndThisClassDoesNotExist =
                ThisClassExists.And(thisClassExistsAndThisClassDoesNotExist2);
            var thisClassExistsAndThisClassDoesNotExistAndThisClassExists =
                thisClassExistsAndThisClassDoesNotExist2.And(ThisClassExists);
            var thisClassDoesNotExistAndThisClassExistsAndThisClassDoesNotExist =
                ThisClassDoesNotExist.And(thisClassExistsAndThisClassDoesNotExist2);

            Assert.True(thisClassExistsAndThisClassExists1.HasNoViolations(Architecture));
            Assert.False(thisClassExistsAndThisClassDoesNotExist1.HasNoViolations(Architecture));
            Assert.False(thisClassDoesNotExistAndThisClassExists1.HasNoViolations(Architecture));
            Assert.False(thisClassDoesNotExistAndThisClassDoesNotExist1.HasNoViolations(Architecture));

            Assert.True(thisClassExistsAndThisClassExists2.HasNoViolations(Architecture));
            Assert.False(thisClassExistsAndThisClassDoesNotExist2.HasNoViolations(Architecture));
            Assert.False(thisClassDoesNotExistAndThisClassExists2.HasNoViolations(Architecture));
            Assert.False(thisClassDoesNotExistAndThisClassDoesNotExist2.HasNoViolations(Architecture));

            Assert.True(thisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations(Architecture));
            Assert.True(
                thisClassExistsAndThisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations(Architecture));
            Assert.False(thisClassExistsAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations(Architecture));
            Assert.False(thisClassExistsAndThisClassDoesNotExistAndThisClassExists.HasNoViolations(Architecture));
            Assert.False(thisClassDoesNotExistAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations(Architecture));
        }
        public void TypesShouldBeInCorrectLayer()
        {
            //you can use the fluent API to write your own rules
            IArchRule exampleClassesShouldBeInExampleLayer =
                Classes().That().Are(ExampleClasses).Should().Be(ExampleLayer);
            IArchRule forbiddenInterfacesShouldBeInForbiddenLayer =
                Interfaces().That().Are(ForbiddenInterfaces).Should().Be(ForbiddenLayer);

            //check if your architecture fulfils your rules
            exampleClassesShouldBeInExampleLayer.Check(Architecture);
            forbiddenInterfacesShouldBeInForbiddenLayer.Check(Architecture);

            //you can also combine your rules
            IArchRule combinedArchRule =
                exampleClassesShouldBeInExampleLayer.And(forbiddenInterfacesShouldBeInForbiddenLayer);

            combinedArchRule.Check(Architecture);
        }
예제 #4
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));
        }