public void BuildRule_KindNotSet_ThrowsInvalidOperationException() { var ruleBuilder = ReferenceRule.For("ProjectA") .Referencing("ProjectB") .Because("A cool rule I made"); Assert.Throws <InvalidOperationException>(() => ruleBuilder.BuildRule()); }
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); }
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); }
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); }
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); }
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); }