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); }
public void Object_Is_Not_A_Serialized_Scalar() { // arrange object o = new object(); // act bool isScalar = Scalars.TryGetKind(o, out _); // assert Assert.False(isScalar); }
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); }
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); }
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); }
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); }
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); }
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 !;
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); }
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); }