public void ShouldReportErrorWhenFileDeclaresNoNamespaces() { //GIVEN var ruleViolationFactory = Substitute.For <IProjectScopedRuleViolationFactory>(); var parentProjectAssemblyName = Any.String(); var parentProjectRootNamespace = Any.String(); var pathRelativeToProjectRoot = Any.Instance <RelativeFilePath>(); var fileBuilder = new SourceCodeFileBuilder { RuleViolationFactory = ruleViolationFactory, DeclaredNamespaces = new List <string>(), ParentProjectAssemblyName = parentProjectAssemblyName, ParentProjectRootNamespace = parentProjectRootNamespace, PathRelativeToProjectRoot = pathRelativeToProjectRoot }; var file = fileBuilder.Build(); var report = Substitute.For <IAnalysisReportInProgress>(); var description = Any.Instance <RuleDescription>(); var violation = Any.Instance <RuleViolation>(); ruleViolationFactory.ProjectScopedRuleViolation(description, parentProjectAssemblyName + " has root namespace " + parentProjectRootNamespace + " but the file " + pathRelativeToProjectRoot + " has no namespace declared").Returns(violation); //WHEN file.CheckNamespacesCorrectness(report, description); //THEN XReceived.Only(() => report.Add(violation)); }
public void ShouldReportIncorrectNamespaceWhenIsInRootFolderAndItsOnlyNamespaceDoesNotMatchRootNamespace() { //GIVEN var ruleViolationFactory = Substitute.For <IProjectScopedRuleViolationFactory>(); var parentProjectAssemblyName = Any.String(); var parentProjectRootNamespace = Any.String(); var pathRelativeToProjectRoot = Any.Instance <RelativeFilePath>(); var fileBuilder = new SourceCodeFileBuilder { RuleViolationFactory = ruleViolationFactory, ParentProjectAssemblyName = parentProjectAssemblyName, PathRelativeToProjectRoot = pathRelativeToProjectRoot, ParentProjectRootNamespace = parentProjectRootNamespace, DeclaredNamespaces = Any.OtherThan(parentProjectRootNamespace).AsList() }; var file = fileBuilder.Build(); var report = Substitute.For <IAnalysisReportInProgress>(); var description = Any.Instance <RuleDescription>(); var violation = Any.Instance <RuleViolation>(); ruleViolationFactory.ProjectScopedRuleViolation(description, parentProjectAssemblyName + " has root namespace " + parentProjectRootNamespace + " but the file " + pathRelativeToProjectRoot + " has incorrect namespace " + fileBuilder.DeclaredNamespaces.Single()).Returns(violation); //WHEN file.CheckNamespacesCorrectness(report, description); //THEN XReceived.Only(() => report.Add(violation)); }