Пример #1
0
        public void ShouldReportFailureWhenPatternExclusionDoesNotRuleOutDependingThatMatchAlone()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("CompositionRoot");
            context.HasProject("CompositionRootSpecification").WithReferences("CompositionRoot");
            context.HasProject("CompositionRootTests").WithReferences("CompositionRoot");

            context.Add(RuleBuilder.RuleDemandingThat()
                        .Project("*")
                        .Except("*Tests*")
                        .IndependentOfProject("*CompositionRoot*"));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject(
                    "* except *Tests*", "*CompositionRoot*").Error()
                .ViolationPath("CompositionRootSpecification", "CompositionRoot"));
            context.ReportShouldNotContainText("CompositionRootTests");
            context.ShouldIndicateFailure();
        }
        public void ShouldDetectMultipleIndirectRuleBreaksWithMultipleViolationPaths()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("A").WithReferences("B", "C");
            context.HasProject("B").WithReferences("D");
            context.HasProject("C").WithReferences("D");
            context.HasProject("D");

            context.Add(RuleDemandingThat().Project("A").IndependentOfProject("D"));
            context.Add(RuleDemandingThat().Project("A").IndependentOfProject("B"));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject("A", "D").Error()
                .ViolationPath("A", "B", "D")
                .ViolationPath("A", "C", "D"));
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject("A", "B").Error()
                .ViolationPath("A", "B"));
            context.ShouldIndicateFailure();
        }
        public void ShouldReportSuccessWhenNoProjectHasSpecifiedPackageReference()
        {
            //GIVEN
            var projectName = Any.String();
            var packageName = Any.String();
            var context     = new NScanDriver();

            context.HasProject(projectName);

            context.Add(RuleDemandingThat().Project(projectName).IndependentOfPackage(packageName));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfPackage(projectName, packageName).Ok());
            context.ShouldIndicateSuccess();
        }
        public void ShouldReportAllSatisfiedRules()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("A");
            context.HasProject("B");

            context.Add(RuleDemandingThat().Project("A")
                        .IndependentOfProject("B"));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject("A", "B").Ok());
            context.ShouldIndicateSuccess();
        }
        public void ShouldDetectRuleBreakWithGlobExpression()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("Posts.Domain").WithReferences("Posts.Ports");
            context.HasProject("Posts.Ports");

            context.Add(RuleDemandingThat().Project("*.Domain").IndependentOfProject("*.Ports"));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject("*.Domain", "*.Ports").Error()
                .ViolationPath("Posts.Domain", "Posts.Ports"));
            context.ShouldIndicateFailure();
        }
        public void ShouldReportFailureWhenProjectsHasSpecifiedPackageReferenceDirectly()
        {
            //GIVEN
            var projectName = Any.String();
            var packageName = Any.String();
            var context     = new NScanDriver();

            context.HasProject(projectName).WithPackages(packageName);

            context.Add(RuleDemandingThat().Project(projectName).IndependentOfPackage(packageName));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfPackage(projectName, packageName).Error()
                .ViolationPath(projectName));
            context.ShouldIndicateFailure();
        }
Пример #7
0
        public void ShouldReportSuccessWhenPatternExclusionRulesOutDependingThatWouldOtherwiseMatch()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("CompositionRoot");
            context.HasProject("CompositionRootSpecification").WithReferences("CompositionRoot");

            context.Add(RuleBuilder.RuleDemandingThat()
                        .Project("*")
                        .Except("*Specification*")
                        .IndependentOfProject("*CompositionRoot*"));

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                ProjectIndependentOfMessage.ProjectIndependentOfProject(
                    "* except *Specification*", "*CompositionRoot*"
                    ).Ok());
            context.ShouldIndicateSuccess();
        }