public void ShouldAddRuleToRuleSet()
        {
            //GIVEN
            var ruleSet     = Substitute.For <INamespacesBasedRuleSet>();
            var ruleFactory = Substitute.For <INamespaceBasedRuleFactory>();
            var analysis    = new ProjectNamespacesAnalysis(Any.Instance <ISolutionForNamespaceBasedRules>(), ruleSet, ruleFactory);
            var dto1        = Any.Instance <NoUsingsRuleComplementDto>();
            var dto2        = Any.Instance <NoCircularUsingsRuleComplementDto>();
            var dto3        = Any.Instance <NoUsingsRuleComplementDto>();
            var projectScopedRuleUnionDtos = new List <NamespaceBasedRuleUnionDto>
            {
                NamespaceBasedRuleUnionDto.With(dto1),
                NamespaceBasedRuleUnionDto.With(dto2),
                NamespaceBasedRuleUnionDto.With(dto3)
            };
            var rule1 = Any.Instance <INamespacesBasedRule>();
            var rule2 = Any.Instance <INamespacesBasedRule>();
            var rule3 = Any.Instance <INamespacesBasedRule>();

            ruleFactory.CreateNamespacesBasedRuleFrom(dto1).Returns(rule1);
            ruleFactory.CreateNamespacesBasedRuleFrom(dto2).Returns(rule2);
            ruleFactory.CreateNamespacesBasedRuleFrom(dto3).Returns(rule3);

            //WHEN
            analysis.Add(projectScopedRuleUnionDtos);

            //THEN
            Received.InOrder(() =>
            {
                ruleSet.Add(rule1);
                ruleSet.Add(rule2);
                ruleSet.Add(rule3);
            });
        }
        public void ShouldAddAllNamespaceBasedRulesFromDtosToRuleSet()
        {
            //GIVEN
            var ruleDto1           = Any.Instance <NoCircularUsingsRuleComplementDto>();
            var ruleDto2           = Any.Instance <NoUsingsRuleComplementDto>();
            var ruleDto3           = Any.Instance <NoCircularUsingsRuleComplementDto>();
            var namespacesAnalysis = Substitute.For <IProjectNamespacesAnalysis>();
            var analysis           = new AnalysisBuilder
            {
                NamespacesAnalysis = namespacesAnalysis,
            }.Build();

            var ruleDtos = new[]
            {
                NamespaceBasedRuleUnionDto.With(ruleDto1),
                NamespaceBasedRuleUnionDto.With(ruleDto2),
                NamespaceBasedRuleUnionDto.With(ruleDto3)
            };

            //WHEN
            analysis.AddNamespaceBasedRules(ruleDtos);

            //THEN
            namespacesAnalysis.Received(1).Add(ruleDtos);
        }
Esempio n. 3
0
        public IFullNamespaceBasedRuleConstructed HasNoUsings(string @from, string to)
        {
            var complementDto = NoUsingsComplement(from, to);

            _namespaceBasedRuleDto = NamespaceBasedRuleUnionDto.With(complementDto);
            _testedRuleDefinition  = TestedRuleDefinition.From(complementDto);
            return(this);
        }
Esempio n. 4
0
        public IFullNamespaceBasedRuleConstructed HasNoCircularUsings()
        {
            var complementDto = NoCircularUsingsRuleComplement();

            _namespaceBasedRuleDto = NamespaceBasedRuleUnionDto.With(complementDto);
            _testedRuleDefinition  = TestedRuleDefinition.From(complementDto);
            return(this);
        }
 private static Parser <NamespaceBasedRuleUnionDto> HasNoUsingsRuleComplement(Pattern dependingPattern)
 {
     return(Parse.String(HasNoUsingsRuleMetadata.HasNoUsings)
            .Then(_ => Spaces)
            .Then(_ =>
                  from fromKeyWord in Parse.String("from").Then(_ => Spaces)
                  from fromPattern in TextUntilWhitespace
                  from toKeyWord in Parse.String("to").Then(_ => Spaces)
                  from toPattern in TextUntilEol
                  select NamespaceBasedRuleUnionDto.With(
                      new NoUsingsRuleComplementDto(
                          dependingPattern,
                          Pattern.WithoutExclusion(fromPattern),
                          Pattern.WithoutExclusion(toPattern)))));
 }
 private static Parser <NamespaceBasedRuleUnionDto> HasNoCircularUsingsRuleComplement(Pattern dependingPattern)
 {
     return(Parse.String(HasNoCircularUsingsRuleMetadata.HasNoCircularUsings).Then(_ => OptionalSpacesUntilEol).Return(
                NamespaceBasedRuleUnionDto.With(new NoCircularUsingsRuleComplementDto(dependingPattern))));
 }