public void Should_be_convertible_to_anonymous_type_with_same_property_order() { var objType = new { Int32Value, DoubleValue, StringValue }; var obj = dynamicObject.CreateObject(objType.GetType()); obj.ShouldNotBeNull(); }
public void Dynamic_object_should_result_in_list_of_string_when_mapped_back() { var list = dynamicObject.CreateObject().ShouldBeOfType <List <string> >(); list[0].ShouldBe("One"); list[1].ShouldBeNull(); }
public void Dynamic_object_should_result_in_string_array_when_mapped_back() { var array = dynamicObject.CreateObject().ShouldBeOfType <int[]>(); array[0].ShouldBe(1); array[1].ShouldBe(2); }
public void Dynamic_object_should_result_in_string_array_when_mapped_back() { var list = dynamicObject.CreateObject().ShouldBeOfType <List <int?> >(); list[0].ShouldBeNull(); list[1].ShouldBe(1); list[2].ShouldBe(11); }
public static T ShallowClone <T>(this T obj, params Expression <Func <T, object> >[] includedProperties) { includedProperties = includedProperties ?? new Expression <Func <T, object> > [0]; var dynamicObject = new DynamicObject(obj, new ShallowCopyDynamicObjectMapper(includedProperties.Select(p => obj.GetPropertyInfo(p)).ToArray())); return(dynamicObject.CreateObject <T>()); }
public When_converting_to_object_based_on_typeinfo() { var dynamicObject = new DynamicObject(typeof(CustomType)) { { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject() as CustomType; }
public When_converting_to_object_with_additional_properties() { var dynamicObject = new DynamicObject { { "Int32Value", Int32Value }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<CustomType>(); }
public When_converting_to_different_target_type() { var dynamicObject = new DynamicObject(typeof(SourceType)) { { "StringValue", StringValue }, { "Int32Value", Int32Value }, }; obj = dynamicObject.CreateObject(typeof(TargetType)) as TargetType; }
public When_converting_to_serializable_object_with_additional_properies() { var dynamicObject = new DynamicObject() { { "Int32Value", Int32Value }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<SerializableType>(); }
public void ShouldCreateObjectWithIndexerBasedOnDynamicObject() { var dynamicObject = new DynamicObject { { "Item", "ItemValue1" } }; var obj = dynamicObject.CreateObject<ClassWithIndexerAndItemProperty>(); obj.Item.ShouldBe("ItemValue1"); }
public When_converting_to_serializable_object_with_private_properties() { var dynamicObject = new DynamicObject { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<SerializableType>(); }
public When_converting_to_object_with_private_property_setter() { var dynamicObject = new DynamicObject { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<CustomType>(); }
public When_converting_to_type_requiring_ctor_and_property_setter() { var dynamicObject = new DynamicObject() { { "Id", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<Data>(); }
public When_converting_to_datetime_object() { sourceValue = DateTime.Now; dynamicObject = new DynamicObject(typeof(DateTime)) { Properties = new PropertySet { { string.Empty, sourceValue.ToString("o") }, }, }; value = dynamicObject.CreateObject() as DateTime?; }
public When_converting_to_object_with_missing_properties() { var dynamicObject = new DynamicObject { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "NullableDateTimeValue", NullableDateTimeValue }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<CustomType>(); }
public When_converting_to_object_with_different_property_types_assignable() { var dynamicObject = new DynamicObject { { "DoubleValue", Int32Value }, { "NullableIntValue", Int32Value }, { "Timestamp", Timestamp }, { "StringValue", StringValue }, }; obj = dynamicObject.CreateObject<CustomType>(); }
public When_converting_to_object_based_on_typeinfo() { var dynamicObject = new DynamicObject(typeof(CustomType)) { Properties = new PropertySet { { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject() as CustomType; }
public When_converting_to_serializable_object() { var dynamicObject = new DynamicObject() { Properties = new PropertySet { { "Int32Value", Int32Value }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <SerializableType>(); }
public When_converting_to_serializable_object_with_properties_ordered_differently() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "StringValue", StringValue }, { "Int32Value", Int32Value }, }, }; obj = dynamicObject.CreateObject <SerializableType>(); }
public When_converting_to_object_with_abstract_properties() { dynamicObject = new DynamicObject() { { "Ref", new DynamicObject(typeof(A)) }, { "Value1", "the value's pay load" }, { "Value2", 222 }, { "Value3", null }, { "Value4", new DynamicObject(typeof(object))}, }; obj = dynamicObject.CreateObject<ClassWithAbstractProperties>(); }
public When_converting_to_object_with_additional_properties() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "Int32Value", Int32Value }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <CustomType>(); }
public When_converting_to_different_target_type() { var dynamicObject = new DynamicObject(typeof(SourceType)) { Properties = new PropertySet { { "StringValue", StringValue }, { "Int32Value", Int32Value }, }, }; obj = dynamicObject.CreateObject(typeof(TargetType)) as TargetType; }
public When_converting_to_serializable_object_with_private_property_setters() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <SerializableType>(); }
public When_converting_to_type_requiring_ctor_and_property_setter() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "Id", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <Data>(); }
public void ShouldCreateObjectWithIndexerBasedOnDynamicObject() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "Item", "ItemValue1" }, }, }; var obj = dynamicObject.CreateObject <ClassWithIndexerAndItemProperty>(); obj.Item.ShouldBe("ItemValue1"); }
public When_converting_to_object_with_different_property_types_unassignable() { var dynamicObject = new DynamicObject { { "NumericValue", DoubleValue }, { "NullableDoubleValue", Longvalue }, { "StringValue", StringValue }, { "BProperty", new A() }, { "CProperty", new A() }, { "DProperty", new A() }, }; obj = dynamicObject.CreateObject<CustomType>(); }
public When_converting_to_serializable_object_with_missing_properties() { var dynamicObject = new DynamicObject() { Properties = new PropertySet { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "NullableDateTimeValue", NullableDateTimeValue }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <SerializableType>(); }
public When_converting_to_object_with_different_property_types_assignable() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "DoubleValue", Int32Value }, { "NullableIntValue", Int32Value }, { "Timestamp", _timestamp }, { "StringValue", StringValue }, }, }; obj = dynamicObject.CreateObject <CustomType>(); }
public When_converting_to_object_with_abstract_properties() { dynamicObject = new DynamicObject() { Properties = new PropertySet { { "Ref", new DynamicObject(typeof(A)) }, { "Value1", "the value's pay load" }, { "Value2", 222 }, { "Value3", null }, { "Value4", new DynamicObject(typeof(object)) }, }, }; obj = dynamicObject.CreateObject <ClassWithAbstractProperties>(); }
public When_converting_to_object_with_different_property_types_unassignable() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "NumericValue", DoubleValue }, { "NullableDoubleValue", Longvalue }, { "StringValue", StringValue }, { "BProperty", new A() }, { "CProperty", new A() }, { "DProperty", new A() }, }, }; obj = dynamicObject.CreateObject <CustomType>(); }
public When_converting_to_object_with_fields_and_properties() { var dynamicObject = new DynamicObject { Properties = new PropertySet { { "Int32Value", Int32Value }, { "DoubleValue", DoubleValue }, { "StringValue", StringValue1 }, { "RedundantValue", StringValue2 }, { "Date", Date }, { "PrivateStringValue", StringValue2 }, }, }; obj = dynamicObject.CreateObject <CustomType>(); }
public void Dynamic_object_should_result_in_empty_list_when_mapped_back() { dynamicObject.CreateObject() .ShouldBeOfType <List <string> >() .ShouldBeEmpty(); }