Beispiel #1
0
        public void ShouldReportErrorWhenThereIsADependency()
        {
            //GIVEN
            var dto = Any.Instance <NoUsingsRuleComplementDto>();
            var ruleViolationFactory = Substitute.For <INamespaceBasedRuleViolationFactory>();
            var assemblyName         = Any.Instance <AssemblyName>();
            var namespacesCache      = Substitute.For <INamespacesDependenciesCache>();
            var report     = Substitute.For <IAnalysisReportInProgress>();
            var violation  = Any.Instance <RuleViolation>();
            var pathsFound = new List <NamespaceDependencyPath>
            {
                Any.Instance <NamespaceDependencyPath>(),
                Any.Instance <NamespaceDependencyPath>(),
                Any.Instance <NamespaceDependencyPath>(),
            };
            var rule = new NoUsingsRule(dto, ruleViolationFactory);

            ruleViolationFactory.NoUsingsRuleViolation(rule.Description(), assemblyName, pathsFound)
            .Returns(violation);
            namespacesCache.RetrievePathsBetween(dto.FromPattern, dto.ToPattern).Returns(pathsFound);

            //WHEN
            rule.Evaluate(assemblyName, namespacesCache, report);

            //THEN
            report.Received(1).Add(violation);
        }
Beispiel #2
0
        public void ShouldNotReportAnythingWhenThereIsNoDependency()
        {
            //GIVEN
            var dto             = Any.Instance <NoUsingsRuleComplementDto>();
            var rule            = new NoUsingsRule(dto, Any.Instance <INamespaceBasedRuleViolationFactory>());
            var namespacesCache = Substitute.For <INamespacesDependenciesCache>();
            var report          = Substitute.For <IAnalysisReportInProgress>();

            namespacesCache.RetrievePathsBetween(dto.FromPattern, dto.ToPattern)
            .Returns(NoPaths());

            //WHEN
            rule.Evaluate(Any.Instance <AssemblyName>(), namespacesCache, report);

            //THEN
            report.ReceivedNothing();
        }