Esempio n. 1
0
        public void BasicBooleanStrategy()
        {
            // given: we have a basic boolean feature
            var feature = new FeatureState();

            feature.Key     = "bool1";
            feature.Value   = true;
            feature.Version = 1;
            feature.Type    = FeatureValueType.BOOLEAN;
            var strategy = new RolloutStrategy("id", "name");

            strategy.Value = false;
            var ruleset = new RolloutStrategyAttribute();

            ruleset.Conditional = RolloutStrategyAttributeConditional.EQUALS;
            ruleset.Type        = RolloutStrategyFieldType.STRING;
            ruleset.FieldName   = GetEnumMemberValue(StrategyAttributeWellKnownNames.Country);
            ruleset.Values      = new List <object> {
                GetEnumMemberValue(StrategyAttributeCountryName.Turkey)
            };

            strategy.Attributes = new List <RolloutStrategyAttribute> {
                ruleset
            };
            feature.Strategies = new List <RolloutStrategy> {
                strategy
            };

            repo.Notify(new List <FeatureState> {
                feature
            });

            var matchCC   = new TestClientContext().Country(StrategyAttributeCountryName.Turkey);
            var unmatchCC = new TestClientContext().Country(StrategyAttributeCountryName.Newzealand);

            Assert.AreEqual(false, repo.GetFeature("bool1").WithContext(matchCC).BooleanValue);
            Assert.AreEqual(true, repo.GetFeature("bool1").WithContext(unmatchCC).BooleanValue);
            Assert.AreEqual(true, repo.GetFeature("bool1").BooleanValue);
        }
Esempio n. 2
0
        private void StringTypeComparison(FeatureValueType ft)
        {
            // given: we have a basic string feature with two custom strategies based on age and platform
            var feature = new FeatureState();

            feature.Key     = "s1";
            feature.Value   = "feature";
            feature.Version = 1;
            feature.Type    = ft;
            var notMobileStrategy = new RolloutStrategy("id", "not-mobile");

            notMobileStrategy.Value = "not-mobile";
            var ruleset1 = new RolloutStrategyAttribute();

            ruleset1.Conditional = RolloutStrategyAttributeConditional.EXCLUDES;
            ruleset1.Type        = RolloutStrategyFieldType.STRING;
            ruleset1.FieldName   = GetEnumMemberValue(StrategyAttributeWellKnownNames.Platform);
            ruleset1.Values      = new List <object> {
                GetEnumMemberValue(StrategyAttributePlatformName.Android), GetEnumMemberValue(StrategyAttributePlatformName.Ios)
            };

            notMobileStrategy.Attributes = new List <RolloutStrategyAttribute> {
                ruleset1
            };

            var over20Strategy = new RolloutStrategy("id", "older-than-twenty");

            over20Strategy.Value = "older-than-twenty";
            var ruleset2 = new RolloutStrategyAttribute();

            ruleset2.Conditional = RolloutStrategyAttributeConditional.GREATEREQUALS;
            ruleset2.Type        = RolloutStrategyFieldType.NUMBER;
            ruleset2.FieldName   = "age";
            ruleset2.Values      = new List <object> {
                20
            };
            over20Strategy.Attributes = new List <RolloutStrategyAttribute> {
                ruleset2
            };

            feature.Strategies = new List <RolloutStrategy> {
                notMobileStrategy, over20Strategy
            };

            // when: setup repo
            repo.Notify(new List <FeatureState> {
                feature
            });

            var ccAge27Ios     = new TestClientContext().Platform(StrategyAttributePlatformName.Ios).Attr("age", "27");
            var ccAge18Android = new TestClientContext().Platform(StrategyAttributePlatformName.Android).Attr("age", "18");
            var ccAge43MacOS   = new TestClientContext().Platform(StrategyAttributePlatformName.Macos).Attr("age", "43");
            var ccAge18MacOS   = new TestClientContext().Platform(StrategyAttributePlatformName.Macos).Attr("age", "18");
            var ccEmpty        = new TestClientContext();

            switch (ft)
            {
            case FeatureValueType.STRING:
                // then
                Assert.AreEqual("feature", repo.GetFeature("s1").StringValue);
                Assert.AreEqual("feature", repo.GetFeature("s1").WithContext(ccEmpty).StringValue);
                Assert.AreEqual("feature", repo.GetFeature("s1").WithContext(ccAge18Android).StringValue);
                Assert.AreEqual("not-mobile", repo.GetFeature("s1").WithContext(ccAge18MacOS).StringValue);
                Assert.AreEqual("older-than-twenty", repo.GetFeature("s1").WithContext(ccAge27Ios).StringValue);
                Assert.AreEqual("not-mobile", repo.GetFeature("s1").WithContext(ccAge43MacOS).StringValue);
                break;

            case FeatureValueType.JSON:
                Assert.AreEqual("feature", repo.GetFeature("s1").JsonValue);
                Assert.AreEqual("feature", repo.GetFeature("s1").WithContext(ccEmpty).JsonValue);
                Assert.AreEqual("feature", repo.GetFeature("s1").WithContext(ccAge18Android).JsonValue);
                Assert.AreEqual("not-mobile", repo.GetFeature("s1").WithContext(ccAge18MacOS).JsonValue);
                Assert.AreEqual("older-than-twenty", repo.GetFeature("s1").WithContext(ccAge27Ios).JsonValue);
                Assert.AreEqual("not-mobile", repo.GetFeature("s1").WithContext(ccAge43MacOS).JsonValue);
                break;
            }
        }