Beispiel #1
0
        public void CanGetFlagValue()
        {
            var state = FeatureFlagsState.Builder().AddFlag("key",
                                                            new EvaluationDetail <LdValue>(LdValue.Of("value"), 1, EvaluationReason.OffReason)).Build();

            Assert.Equal(LdValue.Of("value"), state.GetFlagValueJson("key"));
        }
Beispiel #2
0
        public void ReasonIsNullIfReasonsWereNotRecorded()
        {
            var reason = EvaluationReason.FallthroughReason;
            var state  = FeatureFlagsState.Builder().AddFlag("key",
                                                             new EvaluationDetail <LdValue>(LdValue.Of("value"), 1, reason)).Build();

            Assert.Null(state.GetFlagReason("key"));
        }
Beispiel #3
0
        public void CanGetFlagReason()
        {
            var reason = EvaluationReason.FallthroughReason;
            var state  = FeatureFlagsState.Builder(FlagsStateOption.WithReasons).AddFlag("key",
                                                                                         new EvaluationDetail <LdValue>(LdValue.Of("value"), 1, reason)).Build();

            Assert.Equal(EvaluationReason.FallthroughReason, state.GetFlagReason("key"));
        }
Beispiel #4
0
        public void CanDeserializeFromJson()
        {
            var state = FeatureFlagsState.Builder(FlagsStateOption.WithReasons)
                        .AddFlag("key1", LdValue.Of("value1"), 0, EvaluationReason.OffReason, 100, false, null)
                        .AddFlag("key2", LdValue.Of("value2"), 1, EvaluationReason.FallthroughReason, 200, true, UnixMillisecondTime.OfMillis(1000))
                        .Build();

            var jsonString = LdJsonSerialization.SerializeObject(state);
            var state1     = LdJsonSerialization.DeserializeObject <FeatureFlagsState>(jsonString);

            Assert.Equal(state, state1);
        }
Beispiel #5
0
        public void CanConvertToValuesMap()
        {
            var state = FeatureFlagsState.Builder()
                        .AddFlag("key1", new EvaluationDetail <LdValue>(LdValue.Of("value1"), 1, EvaluationReason.OffReason))
                        .AddFlag("key2", new EvaluationDetail <LdValue>(LdValue.Of("value2"), 1, EvaluationReason.OffReason))
                        .Build();

            var expected = new Dictionary <string, LdValue>
            {
                { "key1", LdValue.Of("value1") },
                { "key2", LdValue.Of("value2") }
            };

            Assert.Equal(expected, state.ToValuesJsonMap());
        }
Beispiel #6
0
        public void CanSerializeToJson()
        {
            var state = FeatureFlagsState.Builder(FlagsStateOption.WithReasons)
                        .AddFlag("key1", LdValue.Of("value1"), 0, EvaluationReason.OffReason, 100, false, null)
                        .AddFlag("key2", LdValue.Of("value2"), 1, EvaluationReason.FallthroughReason, 200, true, UnixMillisecondTime.OfMillis(1000))
                        .Build();

            var expectedString = @"{""key1"":""value1"",""key2"":""value2"",
                ""$flagsState"":{
                  ""key1"":{
                    ""variation"":0,""version"":100,""reason"":{""kind"":""OFF""}
                  },""key2"":{
                    ""variation"":1,""version"":200,""reason"":{""kind"":""FALLTHROUGH""},""trackEvents"":true,""debugEventsUntilDate"":1000
                  }
                },
                ""$valid"":true
            }";
            var actualString   = LdJsonSerialization.SerializeObject(state);

            AssertHelpers.JsonEqual(expectedString, actualString);
        }
Beispiel #7
0
        public void UnknownFlagReturnsNullReason()
        {
            var state = FeatureFlagsState.Builder().Build();

            Assert.Null(state.GetFlagReason("key"));
        }
Beispiel #8
0
        public void UnknownFlagReturnsNullValue()
        {
            var state = FeatureFlagsState.Builder().Build();

            Assert.Equal(LdValue.Null, state.GetFlagValueJson("key"));
        }