コード例 #1
0
        public void NoRule_EverythingIsDisallowed_ExceptSameNamespace()
        {
            var ruleConfig = new DependencyRulesBuilder();

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("N1", "C1", "N2", "C2").Should().BeFalse();
        }
コード例 #2
0
        public void NoRule_SameNamespaceIsAlwaysAllowed()
        {
            var ruleConfig = new DependencyRulesBuilder();

            var cachingTypeDependencyValidator = CreateCachingTypeDependencyValidator(ruleConfig);

            cachingTypeDependencyValidator.IsAllowedDependency("N", "C1", "N", "C2").Should().BeTrue();
        }
コード例 #3
0
        public void DisallowRule_ButSameNamespaceShouldBeAllowed()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .AddDisallowed("a.*", "a.b.*");

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("a.b.c", "C1", "a.b.c", "C2").Should().BeTrue();
        }
コード例 #4
0
        public void DisallowRule()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .AddDisallowed("S", "T");

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("S", "C", "T", "C1").Should().BeFalse();
        }
コード例 #5
0
        public void ChildCanDependOnParentImplicitly()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .SetChildCanDependOnParentImplicitly(true);

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("N1.N2", "C", "N1", "C1").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("N1", "C", "N1.N2", "C1").Should().BeFalse();
        }
コード例 #6
0
        public void DisallowRule_IsStrongerThanChildCanDependOnParentImplicitly()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .AddDisallowed("a.*", "a.b.*")
                             .SetChildCanDependOnParentImplicitly(true);

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("a.b.c", "C1", "a.b", "C2").Should().BeFalse();
        }
コード例 #7
0
        public void AllowRule_WithAnyNamespace()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .AddAllowed("*", "*");

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("S", "C1", "T", "C2").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S1", "C1", "T", "C2").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S", "C1", "T1", "C2").Should().BeTrue();
        }
コード例 #8
0
        public void ChildCanDependOnParentImplicitly_ButDisallowWins_WithWildcard()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .SetChildCanDependOnParentImplicitly(true)
                             .AddDisallowed("N1.*", "N1");

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("N1.N2", "C", "N1", "C1").Should().BeFalse();
            dependencyValidator.IsAllowedDependency("N1", "C", "N1.N2", "C1").Should().BeFalse();
        }
コード例 #9
0
        public void ValidatingATypeDependencyTwice_FirstCacheMissThenCacheHit()
        {
            var ruleConfig = new DependencyRulesBuilder();

            var cachingTypeDependencyValidator = CreateCachingTypeDependencyValidator(ruleConfig);

            cachingTypeDependencyValidator.IsAllowedDependency("N1", "C1", "N2", "C2").Should().BeFalse();
            cachingTypeDependencyValidator.MissCount.Should().Be(1);
            cachingTypeDependencyValidator.HitCount.Should().Be(0);

            cachingTypeDependencyValidator.IsAllowedDependency("N1", "C1", "N2", "C2").Should().BeFalse();
            cachingTypeDependencyValidator.MissCount.Should().Be(1);
            cachingTypeDependencyValidator.HitCount.Should().Be(1);
        }
コード例 #10
0
        public void AllowRuleWithVisibleMembers_AffectsOnlyAllowRuleSource()
        {
            var ruleConfig = new DependencyRulesBuilder()
                             .AddAllowed("S1", "T", "C1", "C2")
                             .AddAllowed("S2", "T");

            var dependencyValidator = CreateTypeDependencyValidator(ruleConfig);

            dependencyValidator.IsAllowedDependency("S1", "C", "T", "C1").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S1", "C", "T", "C2").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S1", "C", "T", "C3").Should().BeFalse();

            dependencyValidator.IsAllowedDependency("S2", "C", "T", "C1").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S2", "C", "T", "C2").Should().BeTrue();
            dependencyValidator.IsAllowedDependency("S2", "C", "T", "C3").Should().BeTrue();
        }