コード例 #1
0
        public void NullableToNullable()
        {
            var source = new NullableBuiltInTypes();
            var target = new NullableBuiltInTypes();

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
コード例 #2
0
        public void NullableToBuiltIn()
        {
            var source = new NullableBuiltInTypes()
            {
                Boolean = true,
                Byte    = 0x1,
                Char    = '2',
                Decimal = 3,
                Double  = 4.0,
                Int16   = 5,
                Int32   = 6,
                Int64   = 7,
                SByte   = 0x9,
                Single  = 10,
                String  = "11",
                UInt16  = 12,
                UInt32  = 13,
                UInt64  = 14
            };

            var target = new BuiltInTypes()
            {
                Boolean = false,
                Byte    = 15,
                Char    = (char)16,
                Decimal = 17,
                Double  = 18,
                Int16   = 19,
                Int32   = 20,
                Int64   = 21,
                SByte   = 0x23,
                Single  = 24,
                String  = "25",
                UInt16  = 26,
                UInt32  = 27,
                UInt64  = 28
            };

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
コード例 #3
0
        public void BuiltInToNullable()
        {
            var source = new BuiltInTypes();
            var target = new NullableBuiltInTypes();

            var ultraMapper = new Mapper
                              (
                cfg =>
            {
                cfg.MapTypes <BuiltInTypes, NullablePrimitiveTypes>()
                .MapMember(s => s.Int32, s => s.Char);
            }
                              );

            ultraMapper.Map(source, target);

            bool isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }
コード例 #4
0
        public void NullNullablesToDefaultPrimitives()
        {
            var source = new NullableBuiltInTypes();
            var target = new BuiltInTypes()
            {
                Boolean = true,
                Byte    = 0x1,
                Char    = (char)2,
                Decimal = 3,
                Double  = 4.0,
                Int16   = 5,
                Int32   = 6,
                Int64   = 7,
                SByte   = 0x9,
                Single  = 10f,
                String  = "11",
                UInt16  = 12,
                UInt32  = 13,
                UInt64  = 14,
            };

            //each property must be set to null
            Assert.IsTrue(source.GetType().GetProperties()
                          .All(p => p.GetValue(source) == null));

            //each property must be set to a non-default value
            Assert.IsTrue(target.GetType().GetProperties()
                          .All(p =>
            {
                object defaultValue = p.PropertyType.GetDefaultValueViaActivator();
                return(!p.GetValue(target).Equals(defaultValue));
            }));

            var ultraMapper = new Mapper();

            ultraMapper.Map(source, target);

            var isResultOk = ultraMapper.VerifyMapperResult(source, target);

            Assert.IsTrue(isResultOk);
        }