Exemple #1
0
        public void PerfomVanillaCompatibleTypeConvertion()
        {
            C1 c1 = new C1()
            {
                attr1 = 2, attr2 = "ciao Andrea"
            };
            MagicCloneConverter <C1, C2> mConv = MagicClone
                                                 .New <C1, C2>()
                                                 .Create();

            C2 res = mConv.DoTheMagic(c1);

            Assert.AreEqual(c1.attr1, res.attr1);
        }
Exemple #2
0
        public void InjectCustomConvertionBehaviorTest()
        {
            // SETUP
            Aclass aclass = new Aclass()
            {
                attr1 = 5
            };

            MagicCloneConverter <Aclass, Bclass> mConv = MagicClone.New <Aclass, Bclass>()
                                                         //.AddBehaviour<int, float>(a => a * 0.5f)
                                                         .AddBehaviour <int, float>(a => dummyBehave(a))
                                                         .Create();

            Dictionary <string, Func <Object, Object> > behaviors = new Dictionary <string, Func <Object, Object> >();

            // EXERCISE
            Bclass bclass = mConv.DoTheMagic(aclass);

            // ASSERT
            Assert.AreEqual(
                aclass.attr1.ToString() + ".5",
                bclass.attr1.ToString());
        }