public void ClauseWithUnknownOperatorDoesNotMatch()
        {
            var clause = new ClauseBuilder().Attribute("name").Op("invalidOp").Values(LdValue.Of("Bob")).Build();
            var f      = new FeatureFlagBuilder("key").BooleanWithClauses(clause).Build();
            var user   = User.Builder("key").Name("Bob").Build();

            Assert.Equal(LdValue.Of(false), BasicEvaluator.Evaluate(f, user, EventFactory.Default).Result.Value);
        }
        public void ClauseReturnsFalseForMissingAttribute()
        {
            var clause = new ClauseBuilder().Attribute("legs").Op("in").Values(LdValue.Of(4)).Build();
            var f      = new FeatureFlagBuilder("key").BooleanWithClauses(clause).Build();
            var user   = User.Builder("key").Name("bob").Build();

            Assert.Equal(LdValue.Of(false), BasicEvaluator.Evaluate(f, user, EventFactory.Default).Result.Value);
        }
        public void ClauseCanMatchCustomAttribute()
        {
            var clause = new ClauseBuilder().Attribute("legs").Op("in").Values(LdValue.Of(4)).Build();
            var f      = new FeatureFlagBuilder("key").BooleanWithClauses(clause).Build();
            var user   = User.Builder("key").Custom("legs", 4).Build();

            Assert.Equal(LdValue.Of(true), BasicEvaluator.Evaluate(f, user, EventFactory.Default).Result.Value);
        }
Ejemplo n.º 4
0
        private static bool ApplyOperator(Operator op, LdValue userValue, LdValue clauseValue)
        {
            // Calling ApplyOperator directly wouldn't work in these tests, because we rely on
            // preprocessing that happens in the Clause constructor.
            var clause = new ClauseBuilder().Attribute("anyAttr").Op(op).Values(clauseValue).Build();

            return(Evaluator.ClauseMatchAny(clause, userValue));
        }
        public void ClauseCanBeNegated()
        {
            var clause = new ClauseBuilder().Attribute("name").Op("in").Values(LdValue.Of("Bob"))
                         .Negate(true).Build();
            var f    = new FeatureFlagBuilder("key").BooleanWithClauses(clause).Build();
            var user = User.Builder("key").Name("Bob").Build();

            Assert.Equal(LdValue.Of(false), BasicEvaluator.Evaluate(f, user, EventFactory.Default).Result.Value);
        }
        public void MatchingRuleWithZeroRollout()
        {
            var clause = new ClauseBuilder().Attribute("email").Op("in").Values(LdValue.Of("*****@*****.**")).Build();
            var rule   = new SegmentRule(new List <Clause> {
                clause
            }, 0, null);
            var s = new SegmentBuilder("test").Version(1).Rules(rule).Build();
            var u = User.Builder("foo").Email("*****@*****.**").Build();

            Assert.False(SegmentMatchesUser(s, u));
        }
        public void NonMatchingRuleWithMultipleClauses()
        {
            var clause1 = new ClauseBuilder().Attribute("email").Op("in").Values(LdValue.Of("*****@*****.**")).Build();
            var clause2 = new ClauseBuilder().Attribute("name").Op("in").Values(LdValue.Of("bill")).Build();
            var rule    = new SegmentRule(new List <Clause> {
                clause1, clause2
            }, null, null);
            var s = new SegmentBuilder("test").Version(1).Rules(rule).Build();
            var u = User.Builder("foo").Email("*****@*****.**").Name("bob").Build();

            Assert.False(SegmentMatchesUser(s, u));
        }
        public void RuleWithNoVariationOrRolloutReturnsMalformedFlagError()
        {
            var user   = User.WithKey("userkey");
            var clause = ClauseBuilder.ShouldMatchUser(user);
            var rule   = new RuleBuilder().Id("ruleid").Clauses(clause).Build();
            var f      = FeatureFlagWithRules(rule);

            var result = BasicEvaluator.Evaluate(f, user, EventFactory.Default);

            var expected = new EvaluationDetail <LdValue>(LdValue.Null, null,
                                                          EvaluationReason.ErrorReason(EvaluationErrorKind.MalformedFlag));

            Assert.Equal(expected, result.Result);
            Assert.Equal(0, result.PrerequisiteEvents.Count);
        }
Ejemplo n.º 9
0
 internal FeatureFlagBuilder BooleanMatchingSegment(string segmentKey)
 {
     return(BooleanWithClauses(ClauseBuilder.ShouldMatchSegment(segmentKey)));
 }