Beispiel #1
0
 private static void Init()
 {
     Clean();
     ExpressionMapper.CreateMap <ClassSource, ClassDest>().ForMember(s => s.PropString1, d => d.PropString2).ReverseMap();
     ExpressionMapper.CreateMap <ClassDest2, ClassSource2>().ForMember(s => s.PropString2, d => d.PropString1).ReverseMap();
     ExpressionMapper.Initialize();
 }
Beispiel #2
0
 public void Map_NoActionException_Exception()
 {
     ExpressionMapper.GetMapper <ClassSource, ClassDest>().AfterMap(null);
     ExpressionMapper.Initialize();
     new ClassSource().Map <ClassSource, ClassDest>();
     Clean();
 }
Beispiel #3
0
        public void GetPropertiesNotMapped_ReturnProperties_Success()
        {
            ExpressionMapper.Initialize();
            PropertiesNotMapped actual = ExpressionMapper.GetPropertiesNotMapped <ClassSource, ClassDest>();

            Assert.True(actual.SourceProperties.Count > 0);
            Assert.True(actual.TargetProperties.Count > 0);
        }
Beispiel #4
0
        public void GetQuery_ReturnFunc()
        {
            Init();
            ExpressionMapper.Initialize();

            System.Func <ClassSource, ClassDest> actual = ExpressionMapper.GetQuery <ClassSource, ClassDest>();

            Assert.Null(actual);
        }
Beispiel #5
0
        public void GetQuery_ReturnFunc()
        {
            Init(null);
            ExpressionMapper.Initialize();

            var actual = ExpressionMapper.GetQuery <ClassSource, ClassDest>();

            Assert.IsNotNull(actual);
        }
Beispiel #6
0
 public void Map_NoActionException_Exception()
 {
     Assert.Throws <NoActionAfterMappingException>(() =>
     {
         ExpressionMapper.GetMapper <ClassSource, ClassDest>().AfterMap(null);
         ExpressionMapper.Initialize();
         new ClassSource().Map <ClassSource, ClassDest>();
         Clean();
     });
 }
Beispiel #7
0
        public void GetQueryExpression_ReturnExpression()
        {
            Clean();
            ExpressionMapper.CreateMap <ClassSource, ClassDest>().ForMember(s => s.PropString1, d => d.PropString2);
            ExpressionMapper.Initialize();

            System.Linq.Expressions.Expression <System.Func <ClassSource, ClassDest> > actual = ExpressionMapper.GetQueryExpression <ClassSource, ClassDest>();

            Assert.Null(actual);
        }
Beispiel #8
0
        public void GetQueryExpression_ReturnExpression()
        {
            Clean();
            ExpressionMapper.CreateMap <ClassSource, ClassDest>().ForMember(s => s.PropString1, d => d.PropString2);
            ExpressionMapper.Initialize();

            var actual = ExpressionMapper.GetQueryExpression <ClassSource, ClassDest>();

            Assert.IsNotNull(actual);
        }
        public void ThenBy_Success()
        {
            ExpressionMapper.CreateMap <ClassSource, ClassDest>().ForMember(s => s.PropString1, d => d.PropString2);
            ExpressionMapper.Initialize();

            QueryableImplTest <ClassSource> expected = new QueryableImplTest <ClassSource>();

            IQueryable <ClassSource> actual = expected.OrderByDescending <ClassSource, ClassDest>("PropInt1").ThenBy <ClassSource, ClassDest>("PropInt1");

            Assert.IsTrue(CheckExpressionMethod(actual.Expression, nameof(QueryableExtentions.ThenBy)));
        }
        public void GetDestinationType_WithServiceConstructor()
        {
            ExpressionMapper.ConstructServicesUsing((x) => new ClassDest2());

            var mapper = ExpressionMapper.CreateMap <ClassSource2, IClassDest2>().ConstructUsingServiceLocator();

            ExpressionMapper.Initialize();
            var actual = mapper.GetDestinationType();

            Assert.AreEqual(actual, typeof(ClassDest2));
            ExpressionMapper.Reset();
        }
        public void GetDestinationType_WithServiceConstructor()
        {
            ExpressionMapper.ConstructServicesUsing((x) => new ClassDest2());

            MapperConfiguration <ClassSource2, IClassDest2> mapper = ExpressionMapper.CreateMap <ClassSource2, IClassDest2>().ConstructUsingServiceLocator();

            ExpressionMapper.Initialize();
            Type actual = mapper.GetDestinationType();

            Assert.IsType <ClassDest2>(actual);
            ExpressionMapper.Reset();
        }
        public void CheckAndConfigureMappingTest_List_SameType_Success()
        {
            ExpressionMapper.Reset();
            ExpressionMapper.CreateMap <ClassSource2, ClassDest2>();

            MapperConfigurationTestContainer expected = new MapperConfigurationTestContainer();

            MapperConfigurationCollectionContainer.Instance.Add(expected);
            ExpressionMapper.Initialize();
            Expression <Func <ClassSource, object> >     source = s => s.ListString;
            Expression <Func <ClassDest, object> >       target = d => d.ListString;
            Tuple <Expression, Expression, bool, string> tuple  = Tuple.Create(source.Body, target.Body, false, string.Empty);

            expected.CheckAndConfigureMappingTest(tuple);
            Assert.IsNotNull(expected.GetDelegate());
        }
Beispiel #13
0
        public void Map_ReturnDestinationObject_Success()
        {
            ExpressionMapper.Initialize();

            ClassSource expected = new ClassSource()
            {
                PropInt1       = 1,
                PropSourceInt1 = 1,
                PropString1    = "test"
            };

            var actual = expected.Map <ClassSource, ClassDest>();

            Assert.Equal(actual.PropInt1, expected.PropInt1);
            Assert.Equal(actual.PropString2, expected.PropString1);
            Assert.Equal(0, actual.PropInt2);
        }
 public static void Init(TestContext context)
 {
     Clean();
     ExpressionMapper.CreateMap <ClassSource, ClassDest>().ForMember(s => s.PropString1, d => d.PropString2).ReverseMap();
     ExpressionMapper.Initialize();
 }