示例#1
0
        public void BuildRule_KindNotSet_ThrowsInvalidOperationException()
        {
            var ruleBuilder = ReferenceRule.For("ProjectA")
                              .Referencing("ProjectB")
                              .Because("A cool rule I made");

            Assert.Throws <InvalidOperationException>(() => ruleBuilder.BuildRule());
        }
示例#2
0
        public void BuildRule_KindSpecifiedUsingIsExplicitlyForbidden_ReturnsRuleWithCorrectKind()
        {
            var ruleBuilder = ReferenceRule.For("ProjectA")
                              .Referencing("ProjectB", version: "12.0.0", withPrivateAssetsAll: true)
                              .IsExplicitlyForbidden()
                              .Because("A cool rule I made");

            var rule = ruleBuilder.BuildRule();

            Assert.Equal(RuleKind.ExplicitlyForbidden, rule.Kind);
        }
示例#3
0
        private static bool DoesVersionRuleMatch(Reference reference,
                                                 ReferenceRule rule)
        {
            // if the value is not set, it is neutral -> true
            if (rule.Version == null)
            {
                return(true);
            }

            return(rule.Version == reference.VersionOrNull);
        }
示例#4
0
        private static bool DoesPrivateAssetsRuleMatch(Reference reference,
                                                       ReferenceRule rule)
        {
            // if the value is not set, it is neutral -> true
            if (!rule.IsPrivateAssetsAllSet.HasValue)
            {
                return(true);
            }

            return(rule.IsPrivateAssetsAllSet.Value == reference.IsPrivateAssetsAllSet);
        }
示例#5
0
        public void BuildRule_PrivateAssetsAndVersionNotSpecified_ReturnsRuleWithThoseAsNull()
        {
            var ruleBuilder = ReferenceRule.For("ProjectA")
                              .Referencing("ProjectB")
                              .IsForbidden()
                              .Because("A cool rule I made");

            var rule = ruleBuilder.BuildRule();

            Assert.Null(rule.IsPrivateAssetsAllSet);
            Assert.Null(rule.Version);
        }
示例#6
0
        public void BuildRule_AllFieldsSpecified_ReturnsCorrectRule()
        {
            var ruleBuilder = ReferenceRule.For("ProjectA")
                              .Referencing("ProjectB", version: "12.0.0", withPrivateAssetsAll: true)
                              .IsForbidden()
                              .Because("A cool rule I made");

            var rule = ruleBuilder.BuildRule();

            Assert.Equal("ProjectA", rule.PatternFrom);
            Assert.Equal("ProjectB", rule.PatternTo);
            Assert.Equal("A cool rule I made", rule.Description);
            Assert.Equal(RuleKind.Forbidden, rule.Kind);
            Assert.Equal(true, rule.IsPrivateAssetsAllSet);
            Assert.Equal("12.0.0", rule.Version);
        }