Esempio n. 1
0
        public void Map_ReturnDestinationObject_Success()
        {

            Mapper.Initialize();

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

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

            Assert.AreEqual(actual.PropInt1, expected.PropInt1);
            Assert.AreEqual(actual.PropString2, expected.PropString1);
            Assert.AreEqual(actual.PropInt2, 0);
        }
Esempio n. 2
0
        public void Map_MapperNotInitialise_Exception()
        {

            Mapper.CreateMap<ClassSource, ClassDest>()
               .ForMember(s => s.PropString1, d => d.PropString2);
            ClassDest actual = null;
            ClassSource expected = new ClassSource() { PropInt1 = 1, PropSourceInt1 = 1, PropString1 = "test" };
            using (ShimsContext.Create())
            {
                MapperExpression.Core.Fakes.ShimMapperConfiguration<ClassSource, ClassDest>.AllInstances.GetFuncDelegate = (s) =>
                {
                    throw new MapperNotInitializedException(typeof(ClassSource), typeof(ClassDest));
                };

                actual = Mapper.Map<ClassSource, ClassDest>(expected);
            }
        }
Esempio n. 3
0
        public void Map_Return_null()
        {
            ClassDest actual = null;
            ClassSource expected = new ClassSource() { PropInt1 = 1, PropSourceInt1 = 1, PropString1 = "test" };
            using (ShimsContext.Create())
            {
                MapperExpression.Core.Fakes.ShimMapperConfiguration<ClassSource, ClassDest>.AllInstances.GetFuncDelegate = (s) => { return null; };

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


            Assert.IsNull(actual);
        }