Ejemplo n.º 1
0
        public void TestMappingTwoToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();

            mapper.Register <Class1From, Class2From, ClassTo>((p, q) => new ClassTo
            {
                ValueInt    = p.ValueInt,
                ValueString = p.ValueString + q.ValueString,
                ValueDouble = q.ValueDouble
            });

            var classFrom1 = new Class1From
            {
                ValueInt    = ConstValueInt,
                ValueString = ConstValueString1
            };

            var classFrom2 = new Class2From
            {
                ValueDouble = ConstValueDouble,
                ValueString = ConstValueString2
            };

            // Act
            ClassTo classTo = mapper.Map <Class1From, Class2From, ClassTo>(classFrom1, classFrom2);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, 3);
            Assert.AreEqual(classTo.ValueDouble, ConstValueDouble);
            Assert.AreEqual(classTo.ValueString, ConstValueString1 + ConstValueString2);
        }
Ejemplo n.º 2
0
        public void TestMappingOneToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();

            mapper.Register <Class1From, ClassTo>(p => new ClassTo
            {
                ValueInt    = p.ValueInt,
                ValueString = p.ValueString
            });

            var classFrom = new Class1From
            {
                ValueInt    = ConstValueInt,
                ValueString = ConstValueString1
            };

            // Act
            ClassTo classTo = mapper.Map <Class1From, ClassTo>(classFrom);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, ConstValueInt);
            Assert.AreEqual(classTo.ValueString, ConstValueString1);
        }
Ejemplo n.º 3
0
        public void TestMappingTwoToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();
            mapper.Register<Class1From, Class2From, ClassTo>((p, q) => new ClassTo
                {
                    ValueInt = p.ValueInt,
                    ValueString = p.ValueString + q.ValueString,
                    ValueDouble = q.ValueDouble
                });

            var classFrom1 = new Class1From
                {
                    ValueInt = ConstValueInt,
                    ValueString = ConstValueString1
                };

            var classFrom2 = new Class2From
                {
                    ValueDouble = ConstValueDouble,
                    ValueString = ConstValueString2
                };

            // Act
            ClassTo classTo = mapper.Map<Class1From, Class2From, ClassTo>(classFrom1, classFrom2);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, 3);
            Assert.AreEqual(classTo.ValueDouble, ConstValueDouble);
            Assert.AreEqual(classTo.ValueString, ConstValueString1 + ConstValueString2);
        }
        public override object Execute(Expression expression)
        {
            object returnedObject = null;

            foreach (var dataAdapter in _dataAdapters)
            {
                var query = new QueryBuilder(dataAdapter, expression).Build();

                if (query == null)
                {
                    continue;
                }

                var collection = typeof(IDataAdapter)
                                 .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                                 .First(m => m.Name == "GetEntities")
                                 .MakeGenericMethod(new Type[]
                {
                    query.EntityType
                })
                                 .Invoke(dataAdapter, null);

                var queryExecuteResult     = query.Execute((IQueryable)collection);
                var queryExecuteResultType = queryExecuteResult.GetType();

                if (typeof(IEnumerable).IsAssignableFrom(queryExecuteResultType))
                {
                    queryExecuteResultType = queryExecuteResultType.GetGenericArguments()[0];
                }

                if (!queryExecuteResultType.IsClass || queryExecuteResultType == typeof(string))
                {
                    returnedObject = queryExecuteResult;
                    continue;
                }

                if (typeof(DynamicClass).IsAssignableFrom(queryExecuteResultType))
                {
                    returnedObject = queryExecuteResult;
                    continue;
                }

                var destinationType = expression.Type;

                if (typeof(IEnumerable).IsAssignableFrom(destinationType))
                {
                    destinationType = destinationType.GetGenericArguments()[0];
                }

                returnedObject = _mapper.Map(query.EntityType, destinationType, queryExecuteResult);
            }

            return(returnedObject);
        }
Ejemplo n.º 5
0
        public void TestMappingOneToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();
            mapper.Register<Class1From, ClassTo>(p => new ClassTo
                {
                    ValueInt = p.ValueInt,
                    ValueString = p.ValueString
                });

            var classFrom = new Class1From
                {
                    ValueInt = ConstValueInt,
                    ValueString = ConstValueString1
                };

            // Act
            ClassTo classTo = mapper.Map<Class1From, ClassTo>(classFrom);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, ConstValueInt);
            Assert.AreEqual(classTo.ValueString, ConstValueString1);
        }