Esempio n. 1
0
        public void TryGetKind(object value, ValueKind expectedKind)
        {
            // arrange
            // act
            bool isScalar = Scalars.TryGetKind(value, out ValueKind kind);

            // assert
            Assert.True(isScalar);
            Assert.Equal(expectedKind, kind);
        }
Esempio n. 2
0
        public void Object_Is_Not_A_Serialized_Scalar()
        {
            // arrange
            object o = new object();

            // act
            bool isScalar = Scalars.TryGetKind(o, out _);

            // assert
            Assert.False(isScalar);
        }
Esempio n. 3
0
        public void NullableDecimal_Is_Float()
        {
            // arrange
            decimal?d = 123.123M;

            // act
            bool isScalar = Scalars.TryGetKind(d, out ValueKind kind);

            // assert
            Assert.True(isScalar);
            Assert.Equal(ValueKind.Float, kind);
        }
Esempio n. 4
0
        public void Object_From_Dictionary()
        {
            // arrange
            var list = new Dictionary <string, object>();

            // act
            bool success = Scalars.TryGetKind(list, out ValueKind kind);

            // assert
            Assert.True(success);
            Assert.Equal(ValueKind.Object, kind);
        }
Esempio n. 5
0
        public void List_From_ArrayOfObject()
        {
            // arrange
            var list = new object[0];

            // act
            bool success = Scalars.TryGetKind(list, out ValueKind kind);

            // assert
            Assert.True(success);
            Assert.Equal(ValueKind.List, kind);
        }
Esempio n. 6
0
        public void Decimal_Is_Float()
        {
            // arrange
            var d = 123.123M;

            // act
            var isScalar = Scalars.TryGetKind(d, out ValueKind kind);

            // assert
            Assert.True(isScalar);
            Assert.Equal(ValueKind.Float, kind);
        }
Esempio n. 7
0
        public void List_From_ListOfObject()
        {
            // arrange
            var list = new List <object>();

            // act
            var success = Scalars.TryGetKind(list, out ValueKind kind);

            // assert
            Assert.True(success);
            Assert.Equal(ValueKind.List, kind);
        }
Esempio n. 8
0
        protected bool TryConvertSerialized <T>(
            object serialized,
            ValueKind expectedKind,
            out T value)
        {
            if (Scalars.TryGetKind(serialized, out ValueKind kind) &&
                kind == expectedKind &&
                _converter.TryConvert(serialized, out T c))
            {
                value = c;
                return(true);
            }

            value = default !;
Esempio n. 9
0
        protected static bool TryConvertSerialized <T>(
            object serialized,
            ScalarValueKind expectedKind,
            out T value)
        {
            if (Scalars.TryGetKind(serialized, out ScalarValueKind kind) &&
                kind == expectedKind &&
                _converter.TryConvert <object, T>(serialized, out T c))
            {
                value = c;
                return(true);
            }

            value = default;
            return(false);
        }
Esempio n. 10
0
        public void TryGetKind_From_Nullable(
            object value,
            ValueKind expectedKind)
        {
            // arrange
            Type            type        = typeof(Nullable <>).MakeGenericType(value.GetType());
            ConstructorInfo constructor =
                type.GetConstructor(new[] { value.GetType() });
            object nullableValue = constructor.Invoke(new[] { value });

            // act
            bool isScalar = Scalars.TryGetKind(
                nullableValue, out ValueKind kind);

            // assert
            Assert.True(isScalar);
            Assert.Equal(expectedKind, kind);
        }