コード例 #1
0
        public void TestResolveWrongType()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var executed = false;

            merger.RegisterResolver("ContactObject.FirstName", (left, right) =>
            {
                left.Value = 12;
                executed   = true;
                return(left);
            });
            var instance = ContactData.David;
            var compare  = ContactData.Jennifer;

            try
            {
                merger.Resolve(instance, compare);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(executed);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
コード例 #2
0
        public void TestResolveStructureNonRun()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var executed = false;

            merger.RegisterResolver <SocialMediaObject>("ContactObject.TwitterAccount", (left, right) =>
            {
                left.Value = new SocialMediaObject()
                {
                    Name = "NEW"
                };
                executed = true;
                return(left);
            });
            var instance = ContactData.David;
            var compare  = ContactData.Jennifer;

            merger.Resolve(instance, compare);

            Assert.IsFalse(executed);
            Assert.AreEqual(ContactData.David.TwitterAccount.Name, instance.TwitterAccount.Name);
        }
コード例 #3
0
        public void TestResolveStringPropertyTyped()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var executed = false;

            merger.RegisterResolver <string>("ContactObject.FirstName", (left, right) =>
            {
                left.Value += right.Value;
                executed    = true;
                return(left);
            });
            var instance = ContactData.David;
            var compare  = ContactData.Jennifer;

            merger.Resolve(instance, compare);

            Assert.IsTrue(executed);
            Assert.AreEqual(ContactData.David.FirstName + ContactData.Jennifer.FirstName, instance.FirstName);
            Assert.AreEqual(ContactData.Jennifer.FirstName, compare.FirstName);
        }