Ejemplo n.º 1
0
        public void Create_WhenInputDataCorrect_ShouldReturnCorrectFunction()
        {
            //arrange
            ExpressionTreeGenerator <Source, Destination> underTest = new ExpressionTreeGenerator <Source, Destination>();
            var    valueToTest = TestDataFactory.CreatePropertyList();
            Source parameter   = new Source()
            {
                EqualValueTypeProperty = 12,
                CastValueTypeProperty  = 13.5F,
                NotCastTypeProperty    = 48,

                EqualRefTypeProperty     = new List <int>(),
                BaseRefTypeProperty      = new List <int>(),
                DifferentRefTypeProperty = new DateTime()
            };
            Expression <Func <Source, Destination> > expectedBehavior = source => new Destination()
            {
                EqualValueTypeProperty = source.EqualValueTypeProperty,
                CastValueTypeProperty  = source.CastValueTypeProperty,

                EqualRefTypeProperty = source.EqualRefTypeProperty,
                BaseRefTypeProperty  = source.BaseRefTypeProperty
            };

            //act
            var actualBehavior = underTest.Create(valueToTest);

            //assert
            var actual = actualBehavior.Compile().Invoke(parameter);
            var expect = expectedBehavior.Compile().Invoke(parameter);

            Assert.Equal(actual, expect, Destination.DestinationComparer);
        }
Ejemplo n.º 2
0
        public void Create_WhenInputDataIncorrect_ShouldThrowException()
        {
            //arrange
            ExpressionTreeGenerator <Source, Destination> underTest = new ExpressionTreeGenerator <Source, Destination>();

            //assert
            Assert.Throws <ArgumentNullException>(() => underTest.Create(null));
        }
        public Func <TSource, TDestination> CompileMappingFunction <TSource, TDestination>() where TDestination : new()
        {
            ExpressionTreeGenerator <TSource, TDestination> expressionTreeGenerator = new ExpressionTreeGenerator <TSource, TDestination>();
            PropertyMapper <TSource, TDestination>          propertyMapper          = new PropertyMapper <TSource, TDestination>();

            IEnumerable <MappingPair> mapPairs = propertyMapper.PerformMapping();

            return(expressionTreeGenerator.Create(mapPairs).Compile());
        }