示例#1
0
        public void TmplCopy_With_ComplexProperty_Test2()
        {
            var src = new TmplCopy <int>()
            {
                A = 1
            };
            var dst = new TmplCopy <MyItem_ImpliciteCast>();

            new DtoCopier().Copy(dst, typeof(TmplCopy <MyItem_ImpliciteCast>), src, typeof(TmplCopy <int>), false, null);

            dst.A.A.Should().Be(1);
        }
示例#2
0
        public void TmplCopy_Test()
        {
            var src = new TmplCopy <int>()
            {
                A = 1
            };
            var dst = new TmplCopy <int?>();

            new DtoCopier().Copy(dst, typeof(TmplCopy <int>), src, typeof(TmplCopy <int?>), false, null);

            dst.A.Should().Be(1);
        }
示例#3
0
        public void TmplCopy_With_CustomTypeCast_ForOtherTmpl_Test()
        {
            var src = new TmplCopy <MyItem_WithoutCast>()
            {
                A = new MyItem_WithoutCast()
                {
                    A = 1
                }
            };
            var dst = new TmplCopy <int>();

            var casts = new DtoCopierCastStorage();

            casts.Append(typeof(MyItem_WithoutCast).GetMethod(nameof(MyItem_WithoutCast.ToInt)), typeof(OtherTmplCopy <>));

            AssertionExtensions.Should(() => new DtoCopier(casts).Copy(dst, typeof(TmplCopy <int>), src, typeof(TmplCopy <MyItem_WithoutCast>), false, null))
            .Throw <InvalidOperationException>();
        }
示例#4
0
        public void TmplCopy_With_CustomTypeCast_Test()
        {
            var src = new TmplCopy <MyItem_WithoutCast>()
            {
                A = new MyItem_WithoutCast()
                {
                    A = 1
                }
            };
            var dst = new TmplCopy <int>();

            var casts = new DtoCopierCastStorage();

            casts.Append(typeof(MyItem_WithoutCast).GetMethod(nameof(MyItem_WithoutCast.ToInt)), typeof(TmplCopy <>));

            new DtoCopier(casts).Copy(dst, typeof(TmplCopy <int>), src, typeof(TmplCopy <MyItem_WithoutCast>), false, null);

            dst.A.Should().Be(1);
        }