Example #1
0
        private void TestTypeConversion <T, U>(T fromValue, U toValue, Func <T, LdValue> constructor,
                                               LdValue.Converter <U> converter, Func <LdValue, U> getter)
        {
            var value = constructor(fromValue);

            Assert.Equal(toValue, getter(value));
            Assert.Equal(toValue, converter.ToType(value));
        }
Example #2
0
        private void TestConvertIntegerToNumericType <T>(LdValue.Converter <T> converter, Func <LdValue, T> getter)
        {
            var t_2 = (T)Convert.ChangeType(2, typeof(T));

            TestTypeConversion((int)2, t_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((long)2, t_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((float)2, t_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((double)2, t_2, n => LdValue.Of(n), converter, getter);
        }
Example #3
0
        private void TestConvertNonIntegerToIntegerType <T>(LdValue.Converter <T> converter, Func <LdValue, T> getter)
        {
            var t_2       = (T)Convert.ChangeType(2, typeof(T));
            var t_3       = (T)Convert.ChangeType(3, typeof(T));
            var t_minus_2 = (T)Convert.ChangeType(-2, typeof(T));
            var t_minus_3 = (T)Convert.ChangeType(-3, typeof(T));

            TestTypeConversion((float)2.25, t_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((double)2.25, t_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((float)2.75, t_3, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((double)2.75, t_3, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((float)-2.25, t_minus_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((double)-2.25, t_minus_2, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((float)-2.75, t_minus_3, n => LdValue.Of(n), converter, getter);
            TestTypeConversion((double)-2.75, t_minus_3, n => LdValue.Of(n), converter, getter);
        }
Example #4
0
        private void TestNonNumericValueAsNumericTypeIsZero <T>(LdValue.Converter <T> converter,
                                                                Func <LdValue, T> getter, T zero)
        {
            var values = new LdValue[]
            {
                LdValue.Null,
                aTrueBoolValue,
                aStringValue,
                aNumericLookingStringValue,
                anArrayValue,
                anObjectValue
            };

            foreach (var value in values)
            {
                Assert.Equal(zero, getter(value));
                Assert.Equal(zero, converter.ToType(value));
            }
        }
Example #5
0
        private void TestCustomAttribute <T>(T value,
                                             Func <IUserBuilder, string, T, IUserBuilderCanMakeAttributePrivate> setter, LdValue.Converter <T> converter)
        {
            var user0 = setter(User.Builder(key), "foo", value).Build();

            Assert.Equal(value, converter.ToType(user0.Custom["foo"]));
            Assert.Empty(user0.PrivateAttributeNames);

            var user1 = setter(User.Builder(key), "bar", value).AsPrivateAttribute().Build();

            Assert.Equal(value, converter.ToType(user1.Custom["bar"]));
            Assert.Equal(new HashSet <string> {
                "bar"
            }, user1.PrivateAttributeNames);
        }