Exemple #1
0
        public void Test1()
        {
            ThingProfile.CtorCount = 0;
            Assert.AreEqual(0, ThingProfile.CtorCount);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ThingProfile1>();
            });

            Assert.AreEqual(1, ThingProfile.CtorCount);
            Assert.AreEqual(0, MemberValueResolver.CtorCount);

            var mapper = config.CreateMapper();

            Assert.AreEqual(1, ThingProfile.CtorCount);
            Assert.AreEqual(0, MemberValueResolver.CtorCount);

            var thingA = new ThingA {
                ValueInt = 42, ValueString = "foo"
            };
            var thingB = mapper.Map <ThingA, ThingB>(thingA);

            Assert.AreEqual(42, thingB.ValueInt);
            Assert.AreEqual("!!foo!!", thingB.ValueString);

            mapper.Map <ThingA, ThingB>(thingA);
            mapper.Map <ThingA, ThingB>(thingA);
            mapper.Map <ThingA, ThingB>(thingA);
            Assert.AreEqual(1, ThingProfile.CtorCount);        // one single profile
            Assert.AreEqual(4, MemberValueResolver.CtorCount); // many resolvers
        }
    static void Main(string[] args)
    {
        var b = new ThingB
        {
            A = 1,
            B = 3
        };
        //c is ThingB
        var c  = b.DeepCopy();
        var b1 = new ThingA
        {
            A = 1,
        };
        //c1 is ThingA
        var c1 = b1.DeepCopy();

        Debugger.Break();
    }
Exemple #3
0
        public void Test3()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ThingProfile3>();
            });

            var mapper = config.CreateMapper();

            var thingA = new ThingA {
                ValueInt = 42, ValueString = "foo"
            };
            var thingB = mapper.Map <ThingA, ThingB>(thingA);

            Assert.AreEqual(42, thingB.ValueInt);
            Assert.AreEqual("!!foo!!", thingB.ValueString);

            mapper.Map <ThingA, ThingB>(thingA);
            mapper.Map <ThingA, ThingB>(thingA);
            mapper.Map <ThingA, ThingB>(thingA);
        }