Ejemplo n.º 1
0
        public void CollectionMapperCanHandleMappingCollectionToArray()
        {
            OpenType mappedType = mapper.MapType(typeof(IEnumerable <int>), MapType);

            Assert.AreEqual(OpenTypeKind.ArrayType, mappedType.Kind);

            ArrayType arrayType = (ArrayType)mappedType;

            Assert.AreEqual(1, arrayType.Dimension);
            Assert.AreEqual(SimpleType.Integer, arrayType.ElementType);

            List <int> value = new List <int>();

            value.Add(1);
            value.Add(2);
            value.Add(3);

            object mappedValue = mapper.MapValue(typeof(IEnumerable <int>), mappedType, value, MapValue);

            Assert.IsTrue(mappedValue is int[]);
            int[] array = (int[])mappedValue;
            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(1, array[0]);
            Assert.AreEqual(2, array[1]);
            Assert.AreEqual(3, array[2]);
        }
Ejemplo n.º 2
0
        public void PlainNetMapperCanHandleSimpleFlatTypes()
        {
            OpenTypeKind mapsTo;

            Assert.IsTrue(mapper.CanHandle(typeof(SimpleFlatType), out mapsTo, CanHandle));
            Assert.AreEqual(OpenTypeKind.CompositeType, mapsTo);

            OpenType mappedType = mapper.MapType(typeof(SimpleFlatType), MapType);

            Assert.AreEqual(OpenTypeKind.CompositeType, mappedType.Kind);

            CompositeType compositeType = (CompositeType)mappedType;

            Assert.AreEqual("SimpleFlatType", compositeType.TypeName);
            Assert.AreEqual("SimpleFlatType", compositeType.Description);
            Assert.IsTrue(compositeType.ContainsKey("IntValue"));
            Assert.IsTrue(compositeType.ContainsKey("StringValue"));
            Assert.AreEqual(2, compositeType.KeySet.Count);
            Assert.AreEqual(SimpleType.Integer, compositeType.GetOpenType("IntValue"));
            Assert.AreEqual(SimpleType.String, compositeType.GetOpenType("StringValue"));

            SimpleFlatType value = new SimpleFlatType();

            value.IntValue    = 5;
            value.StringValue = "A text";

            object mappedValue = mapper.MapValue(typeof(SimpleFlatType), mappedType, value, MapValue);

            Assert.IsTrue(mappedValue is ICompositeData);
            ICompositeData compositeData = (ICompositeData)mappedValue;

            Assert.IsTrue(compositeType.IsValue(compositeData));
            Assert.IsTrue(compositeData.ContainsKey("IntValue"));
            Assert.IsTrue(compositeData.ContainsKey("StringValue"));
            Assert.AreEqual(value.IntValue, compositeData["IntValue"]);
            Assert.AreEqual(value.StringValue, compositeData["StringValue"]);
            Assert.AreEqual(2, compositeData.Values.Count());
        }