Exemplo n.º 1
0
        public static void AssertDynamicModel(IList <Mapping> mappings)
        {
            Assert.Equal(6, mappings.Count);

            var dynamicNestedPropertyMapping = mappings[0] as NestedMapping;

            Assert.NotNull(dynamicNestedPropertyMapping);
            Assert.IsRuntimeType <object>(dynamicNestedPropertyMapping.Type);
            Assert.True(dynamicNestedPropertyMapping.IsDynamicType);
            Assert.Empty(dynamicNestedPropertyMapping.InternalMappings);
            Assert.Equal("DynamicNestedProperty", dynamicNestedPropertyMapping.LocalName);

            var dynamicPrimitivePropertyMapping = mappings[1] as NestedMapping;

            Assert.NotNull(dynamicPrimitivePropertyMapping);
            Assert.IsRuntimeType <object>(dynamicPrimitivePropertyMapping.Type);
            Assert.True(dynamicPrimitivePropertyMapping.IsDynamicType);
            Assert.Empty(dynamicPrimitivePropertyMapping.InternalMappings);
            Assert.Equal("DynamicPrimitiveProperty", dynamicPrimitivePropertyMapping.LocalName);

            var dynamicListMapping = mappings[2] as CollectionMapping;

            Assert.NotNull(dynamicListMapping);
            Assert.IsRuntimeType <IList <object> >(dynamicListMapping.Type);
            Assert.IsRuntimeType <object>(dynamicListMapping.CollectionType);
            Assert.True(dynamicListMapping.IsElementDynamicType);
            Assert.Empty(dynamicListMapping.InternalMappings);
            Assert.Equal("DynamicList", dynamicListMapping.LocalName);

            var dynamicArrayMapping = mappings[3] as CollectionMapping;

            Assert.NotNull(dynamicArrayMapping);
            Assert.IsRuntimeType <object[]>(dynamicArrayMapping.Type);
            Assert.IsRuntimeType <object>(dynamicArrayMapping.CollectionType);
            Assert.True(dynamicArrayMapping.IsElementDynamicType);
            Assert.Empty(dynamicArrayMapping.InternalMappings);
            Assert.Equal("DynamicArray", dynamicArrayMapping.LocalName);

            var dynamicEnumerableMapping = mappings[4] as CollectionMapping;

            Assert.NotNull(dynamicEnumerableMapping);
            Assert.IsRuntimeType <IEnumerable <object> >(dynamicEnumerableMapping.Type);
            Assert.IsRuntimeType <object>(dynamicEnumerableMapping.CollectionType);
            Assert.True(dynamicEnumerableMapping.IsElementDynamicType);
            Assert.Empty(dynamicEnumerableMapping.InternalMappings);
            Assert.Equal("DynamicEnumerable", dynamicEnumerableMapping.LocalName);

            var dynamicDictionaryMapping = mappings[5] as DictionaryMapping;

            Assert.NotNull(dynamicDictionaryMapping);
            Assert.IsRuntimeType <IDictionary <object, object> >(dynamicDictionaryMapping.Type);
            Assert.IsRuntimeType <object>(dynamicDictionaryMapping.KeyType);
            Assert.IsRuntimeType <object>(dynamicDictionaryMapping.ValueType);
            Assert.True(dynamicDictionaryMapping.IsKeyDynamicType);
            Assert.True(dynamicDictionaryMapping.IsValueDynamicType);
            Assert.Empty(dynamicDictionaryMapping.KeyMappings);
            Assert.Empty(dynamicDictionaryMapping.ValueMappings);
            Assert.Equal("DynamicDictionary", dynamicDictionaryMapping.LocalName);
        }
Exemplo n.º 2
0
        public static void AssertEModel(IList <Mapping> mappings)
        {
            Assert.Equal(1, mappings.Count);

            var intValueMapping = mappings[0] as PropertyMapping;

            Assert.NotNull(intValueMapping);
            Assert.IsRuntimeType <int>(intValueMapping.Type);
            Assert.Equal("IntValue", intValueMapping.LocalName);
        }
Exemplo n.º 3
0
        public static void AssertCModel(IList <Mapping> mappings)
        {
            Assert.Equal(1, mappings.Count);

            var floatValueMapping = mappings[0] as PropertyMapping;

            Assert.NotNull(floatValueMapping);
            Assert.IsRuntimeType <float>(floatValueMapping.Type);
            Assert.Equal("FloatValue", floatValueMapping.LocalName);
        }
Exemplo n.º 4
0
        public static void AssertDModel(IList <Mapping> mappings)
        {
            Assert.Equal(8, mappings.Count);

            var byteValueMapping = mappings[0] as PropertyMapping;

            Assert.NotNull(byteValueMapping);
            Assert.IsRuntimeType <byte>(byteValueMapping.Type);
            Assert.Equal("ByteValue", byteValueMapping.LocalName);

            var shortValueMapping = mappings[1] as PropertyMapping;

            Assert.NotNull(shortValueMapping);
            Assert.IsRuntimeType <short>(shortValueMapping.Type);
            Assert.Equal("ShortValue", shortValueMapping.LocalName);

            var intValueMapping = mappings[2] as PropertyMapping;

            Assert.NotNull(intValueMapping);
            Assert.IsRuntimeType <int>(intValueMapping.Type);
            Assert.Equal("IntValue", intValueMapping.LocalName);

            var longValueMapping = mappings[3] as PropertyMapping;

            Assert.NotNull(longValueMapping);
            Assert.IsRuntimeType <long>(longValueMapping.Type);
            Assert.Equal("LongValue", longValueMapping.LocalName);

            var guidValueMapping = mappings[4] as PropertyMapping;

            Assert.NotNull(guidValueMapping);
            Assert.IsRuntimeType <Guid>(guidValueMapping.Type);
            Assert.Equal("GuidValue", guidValueMapping.LocalName);

            var dateTimeValueMapping = mappings[5] as PropertyMapping;

            Assert.NotNull(dateTimeValueMapping);
            Assert.IsRuntimeType <DateTime>(dateTimeValueMapping.Type);
            Assert.Equal("DateTimeValue", dateTimeValueMapping.LocalName);

            var timespanValueMapping = mappings[6] as PropertyMapping;

            Assert.NotNull(timespanValueMapping);
            Assert.IsRuntimeType <TimeSpan>(timespanValueMapping.Type);
            Assert.Equal("TimeSpanValue", timespanValueMapping.LocalName);

            var someTypeMapping = mappings[7] as PropertyMapping;

            Assert.NotNull(someTypeMapping);
            Assert.IsRuntimeType <SomeTypes>(someTypeMapping.Type);
            Assert.Equal("SomeType", someTypeMapping.LocalName);
        }
Exemplo n.º 5
0
        public void check_json_can_convert_object_with_dictionary()
        {
            var serializer   = new JsonSerializer(_mappingRegistry);
            var deserializer = new JsonDeserializer(_mappingRegistry, _typeCreator);

            var obj = new ContainsDictionary {
                Something = "blah"
            };

            obj.Proxy.Add(1, 2);
            obj.Proxy.Add(3, 4);

            var data = serializer.Serialize(obj);

            _testOutputHelper.WriteLine("Outputted Json: ");
            _testOutputHelper.WriteLine(data.AsString);

            var actualModel = deserializer.Deserialize <ContainsDictionary>(data);

            Assert.NotNull(actualModel);
        }
Exemplo n.º 6
0
        public static void AssertBModel(IList <Mapping> mappings)
        {
            Assert.Equal(3, mappings.Count);

            var stringValueMapping = mappings[0] as PropertyMapping;

            Assert.NotNull(stringValueMapping);
            Assert.IsRuntimeType <string>(stringValueMapping.Type);
            Assert.Equal("StringValue", stringValueMapping.LocalName);

            var intValueMapping = mappings[1] as PropertyMapping;

            Assert.NotNull(intValueMapping);
            Assert.IsRuntimeType <int>(intValueMapping.Type);
            Assert.Equal("IntValue", intValueMapping.LocalName);

            var nestedArrayMapping = mappings[2] as CollectionMapping;

            Assert.NotNull(nestedArrayMapping);
            Assert.IsRuntimeType <C[]>(nestedArrayMapping.Type);
            Assert.Equal("NestedArray", nestedArrayMapping.LocalName);

            AssertCModel(nestedArrayMapping.InternalMappings);
        }