コード例 #1
0
 public void CanGetValuesAsList()
 {
     Assert.Equal(new bool[] { true, false }, LdValue.Convert.Bool.ArrayFrom(new bool[] { true, false }).AsList(LdValue.Convert.Bool));
     Assert.Equal(new bool[] { true, false }, LdValue.Convert.Bool.ArrayOf(true, false).AsList(LdValue.Convert.Bool));
     Assert.Equal(new bool[] { true, false }, LdValue.BuildArray().Add(true).Add(false).Build().AsList(LdValue.Convert.Bool));
     Assert.Equal(new int[] { 1, 2 }, LdValue.Convert.Int.ArrayFrom(new int[] { 1, 2 }).AsList(LdValue.Convert.Int));
     Assert.Equal(new int[] { 1, 2 }, LdValue.Convert.Int.ArrayOf(1, 2).AsList(LdValue.Convert.Int));
     Assert.Equal(new int[] { 1, 2 }, LdValue.BuildArray().Add(1).Add(2).Build().AsList(LdValue.Convert.Int));
     Assert.Equal(new long[] { 1, 2 }, LdValue.Convert.Long.ArrayFrom(new long[] { 1, 2 }).AsList(LdValue.Convert.Long));
     Assert.Equal(new long[] { 1, 2 }, LdValue.Convert.Long.ArrayOf(1, 2).AsList(LdValue.Convert.Long));
     Assert.Equal(new long[] { 1, 2 }, LdValue.BuildArray().Add(1).Add(2).Build().AsList(LdValue.Convert.Long));
     Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.Convert.Float.ArrayFrom(new float[] { 1.0f, 2.0f }).AsList(LdValue.Convert.Float));
     Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.Convert.Float.ArrayOf(1.0f, 2.0f).AsList(LdValue.Convert.Float));
     Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.BuildArray().Add(1.0f).Add(2.0f).Build().AsList(LdValue.Convert.Float));
     Assert.Equal(new double[] { 1.0d, 2.0d }, LdValue.Convert.Double.ArrayFrom(new double[] { 1.0d, 2.0d }).AsList(LdValue.Convert.Double));
     Assert.Equal(new double[] { 1.0d, 2.0d }, LdValue.Convert.Double.ArrayOf(1.0d, 2.0d).AsList(LdValue.Convert.Double));
     Assert.Equal(new double[] { 1.0f, 2.0f }, LdValue.BuildArray().Add(1.0d).Add(2.0d).Build().AsList(LdValue.Convert.Double));
     Assert.Equal(new string[] { "a", "b" }, LdValue.Convert.String.ArrayFrom(new string[] { "a", "b" }).AsList(LdValue.Convert.String));
     Assert.Equal(new string[] { "a", "b" }, LdValue.Convert.String.ArrayOf("a", "b").AsList(LdValue.Convert.String));
     Assert.Equal(new string[] { "a", "b" }, LdValue.BuildArray().Add("a").Add("b").Build().AsList(LdValue.Convert.String));
     Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                  LdValue.ArrayFrom(new LdValue[] { anIntValue, aStringValue }).AsList(LdValue.Convert.Json));
     Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                  LdValue.ArrayOf(anIntValue, aStringValue).AsList(LdValue.Convert.Json));
     Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                  LdValue.BuildArray().Add(anIntValue).Add(aStringValue).Build().AsList(LdValue.Convert.Json));
     Assert.Equal(LdValue.Null, LdValue.Convert.Int.ArrayFrom((IEnumerable <int>)null));
 }
コード例 #2
0
        public void CanGetValuesAsList()
        {
            Assert.Equal(new bool[] { true, false }, LdValue.Convert.Bool.ArrayFrom(new bool[] { true, false }).AsList(LdValue.Convert.Bool));
            Assert.Equal(new bool[] { true, false }, LdValue.Convert.Bool.ArrayOf(true, false).AsList(LdValue.Convert.Bool));
            Assert.Equal(new bool[] { true, false }, LdValue.BuildArray().Add(true).Add(false).Build().AsList(LdValue.Convert.Bool));
            Assert.Equal(new int[] { 1, 2 }, LdValue.Convert.Int.ArrayFrom(new int[] { 1, 2 }).AsList(LdValue.Convert.Int));
            Assert.Equal(new int[] { 1, 2 }, LdValue.Convert.Int.ArrayOf(1, 2).AsList(LdValue.Convert.Int));
            Assert.Equal(new int[] { 1, 2 }, LdValue.BuildArray().Add(1).Add(2).Build().AsList(LdValue.Convert.Int));
            Assert.Equal(new long[] { 1, 2 }, LdValue.Convert.Long.ArrayFrom(new long[] { 1, 2 }).AsList(LdValue.Convert.Long));
            Assert.Equal(new long[] { 1, 2 }, LdValue.Convert.Long.ArrayOf(1, 2).AsList(LdValue.Convert.Long));
            Assert.Equal(new long[] { 1, 2 }, LdValue.BuildArray().Add(1).Add(2).Build().AsList(LdValue.Convert.Long));
            Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.Convert.Float.ArrayFrom(new float[] { 1.0f, 2.0f }).AsList(LdValue.Convert.Float));
            Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.Convert.Float.ArrayOf(1.0f, 2.0f).AsList(LdValue.Convert.Float));
            Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.BuildArray().Add(1.0f).Add(2.0f).Build().AsList(LdValue.Convert.Float));
            Assert.Equal(new double[] { 1.0d, 2.0d }, LdValue.Convert.Double.ArrayFrom(new double[] { 1.0d, 2.0d }).AsList(LdValue.Convert.Double));
            Assert.Equal(new double[] { 1.0d, 2.0d }, LdValue.Convert.Double.ArrayOf(1.0d, 2.0d).AsList(LdValue.Convert.Double));
            Assert.Equal(new double[] { 1.0f, 2.0f }, LdValue.BuildArray().Add(1.0d).Add(2.0d).Build().AsList(LdValue.Convert.Double));
            Assert.Equal(new string[] { "a", "b" }, LdValue.Convert.String.ArrayFrom(new string[] { "a", "b" }).AsList(LdValue.Convert.String));
            Assert.Equal(new string[] { "a", "b" }, LdValue.Convert.String.ArrayOf("a", "b").AsList(LdValue.Convert.String));
            Assert.Equal(new string[] { "a", "b" }, LdValue.BuildArray().Add("a").Add("b").Build().AsList(LdValue.Convert.String));
            Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                         LdValue.ArrayFrom(new LdValue[] { anIntValue, aStringValue }).AsList(LdValue.Convert.Json));
            Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                         LdValue.ArrayOf(anIntValue, aStringValue).AsList(LdValue.Convert.Json));
            Assert.Equal(new LdValue[] { anIntValue, aStringValue },
                         LdValue.BuildArray().Add(anIntValue).Add(aStringValue).Build().AsList(LdValue.Convert.Json));

#pragma warning disable 0618
            Assert.Equal(new bool[] { true, false }, LdValue.FromJToken(new JArray {
                new JValue(true), new JValue(false)
            }).AsList(LdValue.Convert.Bool));
            Assert.Equal(new int[] { 1, 2 }, LdValue.FromJToken(new JArray {
                new JValue(1), new JValue(2)
            }).AsList(LdValue.Convert.Int));
            Assert.Equal(new long[] { 1, 2 }, LdValue.FromJToken(new JArray {
                new JValue(1L), new JValue(2L)
            }).AsList(LdValue.Convert.Long));
            Assert.Equal(new float[] { 1.0f, 2.0f }, LdValue.FromJToken(new JArray {
                new JValue(1.0f), new JValue(2.0f)
            }).AsList(LdValue.Convert.Float));
            Assert.Equal(new double[] { 1.0d, 2.0d }, LdValue.FromJToken(new JArray {
                new JValue(1.0d), new JValue(2.0d)
            }).AsList(LdValue.Convert.Double));
            Assert.Equal(new string[] { "a", "b" }, LdValue.FromJToken(new JArray {
                new JValue("a"), new JValue("b")
            }).AsList(LdValue.Convert.String));
            Assert.Equal(new LdValue[] { anIntValue, aStringValue }, LdValue.FromJToken(new JArray {
                new JValue(someInt), new JValue(someString)
            }).AsList(LdValue.Convert.Json));
#pragma warning restore 0618

            Assert.Equal(LdValue.Null, LdValue.Convert.Int.ArrayFrom((IEnumerable <int>)null));
        }
コード例 #3
0
            internal ItemDescriptor CreateFlag(int version)
            {
                var builder = LdValue.BuildObject()
                              .Add("key", _key)
                              .Add("version", version)
                              .Add("on", _on)
                              .Add("offVariation", _offVariation)
                              .Add("fallthrough", LdValue.BuildObject().Add("variation", _fallthroughVariation).Build())
                              .Add("salt", "")
                              .Add("variations", LdValue.ArrayFrom(_variations));

                if (_targets != null)
                {
                    builder.Add("targets", LdValue.ArrayFrom(
                                    _targets.Select(kv =>
                                                    LdValue.BuildObject()
                                                    .Add("variation", kv.Key)
                                                    .Add("values", LdValue.Convert.String.ArrayFrom(kv.Value))
                                                    .Build())
                                    ));
                }
                if (_rules != null)
                {
                    builder.Add("rules", LdValue.ArrayFrom(
                                    _rules.Select((r, index) =>
                                                  LdValue.BuildObject()
                                                  .Add("id", "rule" + index)
                                                  .Add("variation", r._variation)
                                                  .Add("clauses", LdValue.ArrayFrom(
                                                           r._clauses.Select(c =>
                                                                             LdValue.BuildObject()
                                                                             .Add("attribute", c._attribute.AttributeName)
                                                                             .Add("op", c._operator)
                                                                             .Add("values", LdValue.ArrayFrom(c._values))
                                                                             .Add("negate", c._negate)
                                                                             .Build())
                                                           ))
                                                  .Build())
                                    ));
                }

                var json = builder.Build().ToJsonString();

                return(DataModel.Features.Deserialize(json));
            }