Exemplo n.º 1
0
        public void ShouldReportErrorWhenMultipleProjectsHaveFilesInWrongNamespaces()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("MyProject1")
            .WithRootNamespace("MyProject1")
            .With(FileWithNamespace("lol1.cs", "WrongNamespace"))
            .With(FileWithNamespace("lol2.cs", "WrongNamespace"))
            .With(FileWithNamespace("lol3.cs", "MyProject1"));
            context.HasProject("MyProject2")
            .WithRootNamespace("MyProject2")
            .With(FileWithNamespace("lol1.cs", "WrongNamespace"))
            .With(FileWithNamespace("lol2.cs", "WrongNamespace"))
            .With(FileWithNamespace("lol3.cs", "MyProject2"));
            context.Add(RuleDemandingThat().Project("*MyProject*").HasCorrectNamespaces());

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(
                HasCorrectNamespacesMessage.HasCorrectNamespaces("*MyProject*").Error()
                .ExpectedNamespace("MyProject1", "MyProject1")
                .ButFoundIncorrectNamespaceFor("lol1.cs", "WrongNamespace")
                .ExpectedNamespace("MyProject1", "MyProject1")
                .ButFoundIncorrectNamespaceFor("lol2.cs", "WrongNamespace")
                .ExpectedNamespace("MyProject2", "MyProject2")
                .ButFoundIncorrectNamespaceFor("lol1.cs", "WrongNamespace")
                .ExpectedNamespace("MyProject2", "MyProject2")
                .ButFoundIncorrectNamespaceFor("lol2.cs", "WrongNamespace"));
            context.ReportShouldNotContainText("lol3");
        }
Exemplo n.º 2
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 ShouldNotReportErrorForProjectsThatDoNotMatchTheNamePattern()
            {
                //GIVEN
                const string projectAssemblyNameThatDoesNotMatchRuleFilter = "Trolololo";
                var          context = new NScanDriver();

                context
                .HasProject(projectAssemblyNameThatDoesNotMatchRuleFilter)
                .WithTargetFramework(TargetFramework.Default);
                context.Add(RuleDemandingThat().Project("*MyProject*").HasTargetFramework("netstandard2.1"));

                //WHEN
                context.PerformAnalysis();

                //THEN
                context.ReportShouldNotContainText(projectAssemblyNameThatDoesNotMatchRuleFilter);
            }
Exemplo n.º 4
0
        ShouldReportErrorWhenMultipleNestedFilesOfSingleProjectAreInWrongNamespaceEvenThoughSomeAreInTheRightOne()
        {
            //GIVEN
            var context = new NScanDriver();

            context.HasProject("MyProject")
            .WithRootNamespace("MyProject")
            .With(FileWithNamespace($"Domain{Path.DirectorySeparatorChar}lol4.cs", "MyProject.Domain"))
            .With(FileWithNamespace($"Domain{Path.DirectorySeparatorChar}lol5.cs", "MyProject"));
            context.Add(RuleDemandingThat().Project("*MyProject*").HasCorrectNamespaces());

            //WHEN
            context.PerformAnalysis();

            //THEN
            context.ReportShouldContain(HasCorrectNamespacesMessage
                                        .HasCorrectNamespaces("*MyProject*").Error()
                                        .ExpectedNamespace("MyProject", "MyProject")
                                        .ButFoundIncorrectNamespaceFor($"Domain{Path.DirectorySeparatorChar}lol5.cs", "MyProject"));
            context.ReportShouldNotContainText("lol4");
        }