Пример #1
0
        public void FloatVariationReturnsFlagValue()
        {
            featureStore.Upsert(VersionedDataKind.Features,
                                new FeatureFlagBuilder("key").OffWithValue(new JValue(2.5f)).Build());

            Assert.Equal(2.5f, client.FloatVariation("key", user, 1.0f));
        }
Пример #2
0
        public void FloatVariationSendsEvent()
        {
            var flag = new FeatureFlagBuilder("key").OffWithValue(new JValue(2.5f)).Build();

            featureStore.Upsert(VersionedDataKind.Features, flag);

            client.FloatVariation("key", user, 1.0f);
            Assert.Equal(1, eventSink.Events.Count);
            CheckFeatureEvent(eventSink.Events[0], flag, new JValue(2.5f), new JValue(1.0f), null);
        }
Пример #3
0
        public void FloatVariationSendsEvent()
        {
            var flag = new FeatureFlagBuilder("key").Version(1).OffWithValue(LdValue.Of(2.5f)).Build();

            testData.UsePreconfiguredFlag(flag);

            client.FloatVariation("key", user, 1.0f);
            Assert.Equal(1, eventSink.Events.Count);
            CheckFeatureEvent(eventSink.Events[0], flag, LdValue.Of(2.5f), LdValue.Of(1.0f), null);
        }
        public void FloatVariationReturnsFlagValue()
        {
            testData.UsePreconfiguredFlag(new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(2.5f)).Build());

            Assert.Equal(2.5f, client.FloatVariation("key", user, 1.0f));
        }
Пример #5
0
        public T Get <T>(Enum featureFlag, IDictionary <string, object> userAttributes = null)
        {
            var value = default(T);
            var type  = typeof(T);

            _user = GetUser(userAttributes);
            var feature = featureFlag.GetFlag();

            switch (feature.Type)
            {
            case VariationType.Boolean:
                if (feature.Type != VariationType.Boolean && type == typeof(bool))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be bool");
                }

                value = (T)Convert.ChangeType(_ldClient.BoolVariation(feature.Key, _user, (bool)feature.DefaultValue), typeof(T));
                break;

            case VariationType.String:
                if (feature.Type != VariationType.String && type == typeof(string))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be string");
                }

                value = (T)Convert.ChangeType(_ldClient.StringVariation(feature.Key, _user, (string)feature.DefaultValue), typeof(T));
                break;

            case VariationType.Number:
                if (feature.Type != VariationType.Number && type == typeof(int))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be int");
                }

                value = (T)Convert.ChangeType(_ldClient.IntVariation(feature.Key, _user, (int)feature.DefaultValue), typeof(T));
                break;

            case VariationType.Float:
                if (feature.Type != VariationType.Float && type == typeof(float))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be float");
                }

                value = (T)Convert.ChangeType(_ldClient.FloatVariation(feature.Key, _user, (float)feature.DefaultValue), typeof(T));
                break;

            case VariationType.ArrayOfString:
                if (feature.Type != VariationType.ArrayOfString && type == typeof(string))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be array of string");
                }
                var commaSeperateStr = _ldClient.StringVariation(feature.Key, _user, (string)feature.DefaultValue);

                value = (T)Convert.ChangeType(commaSeperateStr.Split(new[] { ',' }, StringSplitOptions.None), typeof(T));
                break;

            case VariationType.Json:
                if (feature.Type != VariationType.Json && type == typeof(JToken))
                {
                    throw new InvalidCastException($"Feature flag is configure to be {feature.Type} except to be JToken");
                }

                value = (T)Convert.ChangeType(_ldClient.JsonVariation(feature.Key, _user, (JToken)feature.DefaultValue), typeof(T));
                break;
            }

            return(value);
        }