Esempio n. 1
0
        public void Mapper_should_procude_expected_default(Type type)
        {
            var dynamicObject   = DynamicObject.CreateDefault(type);
            var expectedDefault = CreateDefaultForType(type);

            var mapperResult = new DynamicObjectMapper().Map(dynamicObject);

            mapperResult.ShouldBe(expectedDefault);
        }
        public void Should_map_as_valuetype()
        {
            var obj = new DynamicObject {
                IsNull = true
            };

            var result = new DynamicObjectMapper().Map <int>(obj);

            result.ShouldBe(0);
        }
Esempio n. 3
0
        public void Third_element_should_be_string_value()
        {
            var element = dynamicObjects.ElementAt(2);

            element.Type.Type.ShouldBe(typeof(string));
            element[string.Empty].ShouldBe("test");

            var value = new DynamicObjectMapper().Map(dynamicObjects).Cast <object>().ElementAt(2);

            value.ShouldBe("test");
        }
Esempio n. 4
0
        public void First_element_should_be_int32_value()
        {
            var element = dynamicObjects.ElementAt(0);

            element.Type.Type.ShouldBe(typeof(int));
            element[string.Empty].ShouldBe(1);

            var value = new DynamicObjectMapper().Map(dynamicObjects).Cast <object>().ElementAt(0);

            value.ShouldBe(1);
        }
Esempio n. 5
0
        public void Should_serialize_dynamic_object(Type type, object value)
        {
            SkipUnsupportedDataType(type, value);

            var dynamicObject = new DynamicObjectMapper().MapObject(value);

            var config = CreateModelFor(type);
            var copy   = dynamicObject.Serialize(config);

            copy?.Get().ShouldBe(dynamicObject?.Get(), $"type: {type} value: {value}");

            var c = new DynamicObjectMapper().Map(copy);

            c.ShouldBe(value);
        }
Esempio n. 6
0
        public void Should_serialize_dynamic_object(Type type, object value, CultureInfo culture)
        {
            SkipUnsupportedDataType(type, value);

            using var cultureContext = culture.CreateContext();

            var dynamicObject = new DynamicObjectMapper().MapObject(value);
            var copy          = dynamicObject.Serialize();

            copy?.Get().ShouldBe(dynamicObject?.Get(), $"type: {type} value: {value}");

            var c = new DynamicObjectMapper().Map(copy);

            c.ShouldBe(value);
        }