private static IEnumerable <DynamicObject> ReMapCollection(DynamicObject dynamicObject) { var mapper = new DynamicObjectMapper(); var items = mapper.Map(dynamicObject); return(mapper.MapCollection(items)); }
public When_mapping_dynamic_objects_to_list_of_known_types() { dynamicObjects = new[] { new DynamicObject(typeof(CustomReferenceType)) { Properties = new PropertySet { { string.Empty, new CustomReferenceType { Int32Property = 1, StringProperty = "One" } }, }, }, new DynamicObject(typeof(CustomReferenceType)) { Properties = new PropertySet { { string.Empty, new CustomReferenceType { Int32Property = 2, StringProperty = "Two" } }, }, }, }; var mapper = new DynamicObjectMapper(isKnownTypeProvider: new IsKnownTypeProvider()); recreatedObjectLists = mapper.Map <CustomReferenceType>(dynamicObjects); }
public void Sum() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { Value1 = 1, Value2 = 2.1M, Value3 = 3.01D }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["SumConfig"] }); Assert.Equal(6.11M, object2.TotalSumValue); }
public void Concat() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { FirstName = "Foo", LastName = "Bar", MiddleName = "J" }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["ConcatConfig"] }); Assert.Equal("Foo J Bar", object2.Name); }
public void Second_element_should_be_null() { dynamicObjects.ElementAt(1).ShouldBeNull(); var mapper = new DynamicObjectMapper(); var value = dynamicObjects.Select(x => mapper.Map(x)).ElementAt(1); value.ShouldBeNull(); }
public void Int() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { Age = 10 }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["IntConfig"] }); Assert.Equal(10, object2.Age); }
public void FlattenToCsv() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { Things = new[] { "Thing1", "Thing2", "Thing3" } }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["FlattenToCsvConfig"] }); Assert.Equal("Thing1,Thing2,Thing3", object2.FlattenedThings); }
public void Enum() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { TestEnum = TestEnum.Black }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["EnumConfig"] }); Assert.Equal(TestEnum.Black, object2.MyColor); }
public void String() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); TestObject testObject = new TestObject { FirstName = "Foo", LastName = "Bar" }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["StringFirstNameConfig"], _testConfigDictionary["StringLastNameConfig"] }); Assert.Equal("Foo", object2.FName); Assert.Equal("Bar", object2.LName); }
public void Guid() { var mapper = new DynamicObjectMapper<TestObject>(commandHandlers); Guid id = new Guid("9d020be8-3f97-4674-aeec-afc2735f64d5"); TestObject testObject = new TestObject { Id = id }; dynamic object2 = mapper.Map(testObject, new[] { _testConfigDictionary["GuidConfig"] }); Assert.Equal(id, object2.Identification); }
public void Should_silently_skip_unmatching_value_when_allowing_type_validation() { var mapper = new DynamicObjectMapper(new DynamicObjectMapperSettings { SilentlySkipUnassignableMembers = true }); var obj = mapper.Map <CustomType>(dynamicObject); obj.ShouldNotBeNull(); }
public void First_element_should_be_int32_value() { var element = dynamicObjects.ElementAt(0); element.Type.ToType().ShouldBe(typeof(int)); element[string.Empty].ShouldBe(1); var mapper = new DynamicObjectMapper(); var value = dynamicObjects.Select(x => mapper.Map(x)).ElementAt(0); value.ShouldBe(1); }
public void Third_element_should_be_string_value() { var element = dynamicObjects.ElementAt(2); element.Type.ToType().ShouldBe(typeof(string)); element[string.Empty].ShouldBe("test"); var mapper = new DynamicObjectMapper(); var value = dynamicObjects.Select(x => mapper.Map(x)).ElementAt(2); value.ShouldBe("test"); }
public void Should_throw_when_preventing_type_validation() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var mapper = new DynamicObjectMapper(new DynamicObjectMapperSettings { SilentlySkipUnassignableMembers = false }); var ex = Assert.Throws <DynamicObjectMapperException>(() => mapper.Map <CustomType>(dynamicObject)); ex.Message.ShouldBe("Object of type 'System.Int64' cannot be converted to type 'System.Int32'."); }
public void Should_serialize_DateTimeOffset_as_property_when_using_string_formatting2() { var mapperSettings = new DynamicObjectMapperSettings { FormatNativeTypesAsString = true }; var mapper = new DynamicObjectMapper(mapperSettings); var dto1 = new DateTimeOffset(2, 1, 2, 10, 0, 0, 300, new TimeSpan(1, 30, 0)); var dtoDynamic = mapper.MapObject(dto1); var dto2 = mapper.Map <DateTimeOffset>(dtoDynamic); dto2.ShouldBe(dto1); }
public void Fourth_element_should_be_dynamicobject_for_customtype() { var element = dynamicObjects.ElementAt(3); element.Type.ToType().ShouldBe(typeof(CustomType)); element["Int64Property"].ShouldBe(42L); var mapper = new DynamicObjectMapper(); var value = dynamicObjects.Select(x => mapper.Map(x)).ElementAt(3); value.ShouldBeOfType <CustomType>(); ((CustomType)value).Int64Property.ShouldBe(42L); }
public void Should_serialize_DateTimeOffset_as_property_when_using_string_formatting2() { Skip.If(this.TestIs <JsonSerializer>(), "DateTimeOffset not supported by JsonSerializer"); var mapperSettings = new DynamicObjectMapperSettings { FormatNativeTypesAsString = true }; var mapper = new DynamicObjectMapper(mapperSettings); var dto1 = new DateTimeOffset(2, 1, 2, 10, 0, 0, 300, new TimeSpan(1, 30, 0)); var dtoDynamic = mapper.MapObject(dto1); var dto2 = mapper.Map <DateTimeOffset>(dtoDynamic); dto2.ShouldBe(dto1); }
public void Map_type_should_return_a_null_element_for_null_dynamic_object_enumerable_element() { var dynamicObjects = new DynamicObject[] { new DynamicObject(new CustomClass()), null, new DynamicObject(new CustomClass()), }; var mapper = new DynamicObjectMapper(); var result = dynamicObjects.Select(x => mapper.Map(x, typeof(CustomClass))); result.ShouldNotBeNull(); result.Count().ShouldBe(3); result.ElementAt(0).ShouldBeOfType <CustomClass>(); result.ElementAt(1).ShouldBeNull(); result.ElementAt(2).ShouldBeOfType <CustomClass>(); }
public void Map(GeocacheActivity @object) { Mapper.Map(@object, (new Constants()).GetRandomProperties()); }
public void Map(GeocacheActivity @object) { Mapper.Map(@object, "referenceCode", "activityOwner", "dateTimeCreatedUtc", "activityDate", "isArchived", "activityText", "url", "activityType", "updatedLatitude", "updatedLongitude", "isTextRot13", "isApproved", "cannotDelete", "geocache"); }
public void Map(SimpleObject @object) { Mapper.Map(@object, "Id", "Name"); }