public async Task ShouldRaiseErrorWhenMethodsMatchingPatternAreNotDecoratedWithAttributes() { //GIVEN const string projectName = "MyProject"; const string classInclusionPattern = "*Specification"; const string methodInclusionPattern = "Should*"; var projectAssemblyNameInclusionPattern = $"*{projectName}*"; const string matchingMethod1Name = "ShouldA"; const string matchingMethod2Name = "ShouldB"; const string className = "MySpecification"; using var context = new NScanE2EDriver(_output); context.HasProject(projectName) .With(File(Any.CSharpFileName()).Containing( Class(className).With( Method(matchingMethod1Name), Method(matchingMethod2Name)))); context.Add(RuleDemandingThat() .Project(projectAssemblyNameInclusionPattern) .HasDecoratedMethods(classInclusionPattern, methodInclusionPattern)); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain( HasAttributesOnMessage.HasMethodsNotDecoratedWithAttribute(projectAssemblyNameInclusionPattern, classInclusionPattern, methodInclusionPattern) .Error() .NonCompliantMethodFound(className, matchingMethod1Name) .NonCompliantMethodFound(className, matchingMethod2Name)); }
public async Task ShouldReportSuccessWhenThereAreNoCircularDependenciesBetweenNamespaces() { //GIVEN using var context = new NScanE2EDriver(_output); context.HasProject("MyProject") .WithRootNamespace("MyProject") .With(FileWithNamespace("lol1.cs", "MyProject")); context.Add(RuleDemandingThat().Project("*MyProject*").HasNoCircularUsings()); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain(HasNoCircularUsings("*MyProject*").Ok()); }
public async Task ShouldReportSuccessWhenAllProjectsHaveSpecifiedFramework() { //GIVEN using var context = new NScanE2EDriver(_output); context.HasProject("MyProject") .WithTargetFramework(TargetFramework.RecentDotNet); context.Add(RuleDemandingThat().Project("*MyProject*").HasTargetFramework(TargetFramework.RecentDotNet)); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain(HasFramework("*MyProject*", TargetFramework.RecentDotNet).Ok()); }
public async Task ShouldReportErrorForProjectsThatDoNotHaveSpecifiedFramework() { //GIVEN using var context = new NScanE2EDriver(_output); context.HasProject("MyProject").WithTargetFramework(TargetFramework.RecentDotNet); context.Add(RuleBuilder.RuleDemandingThat().Project("*MyProject*").HasTargetFramework("netstandard2.1")); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain( HasTargetFrameworkReportedMessage.HasFramework("*MyProject*", "netstandard2.1").Error() .ProjectHasAnotherTargetFramework("MyProject", TargetFramework.RecentDotNet)); }
public async Task ShouldReportErrorWhenACycleIsDiscovered() { //GIVEN using var context = new NScanE2EDriver(_output); context.HasProject("MyProject") .WithRootNamespace("MyProject") .With(FileWithNamespace("lol1.cs", "MyProject").Using("MyProject.Util")) .With(FileWithNamespace("lol2.cs", "MyProject.Util").Using("MyProject")); context.Add(RuleDemandingThat().Project("*MyProject*").HasNoCircularUsings()); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain(HasNoCircularUsings("*MyProject*").Error() .CycleFound("MyProject", "MyProject", "MyProject.Util", "MyProject")); }
public async Task ShouldReportFailureWhenThereAreForbiddenUsingDependenciesBetweenNamespaces() { //GIVEN using var context = new NScanE2EDriver(_output); context.HasProject("MyProject") .WithRootNamespace("MyProject") .With(FileWithNamespace("Port.cs", "MyProject.Ports").Using("MyProject.Adapters")) .With(FileWithNamespace("Adapter.cs", "MyProject.Adapters")); context.Add(RuleDemandingThat().Project("*MyProject*") .HasNoUsings(@from: "MyProject.Ports*", to: "MyProject.Adapters*")); //WHEN await context.PerformAnalysis(); //THEN context.ReportShouldContain(HasNoUsings("*MyProject*", "MyProject.Ports*", "MyProject.Adapters*").Error() .UsingsPathFound("MyProject", "MyProject.Ports", "MyProject.Adapters")); }