Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        public void TestCompareStructurePropertyEqualString()
        {
            var merger = new MyLittleMerger <NamedArrayObject>();

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

            var itemA = new NamedArrayObject {
                Name = "Item"
            };
            var instanceStructureA = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, itemA);
            var itemB = new NamedArrayObject {
                Name = "Item"
            };
            var instanceStructureB = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, itemB);

            var mergeStructure = new MergerCompareStructure <NamedArrayObject>(instanceStructureA, instanceStructureB);

            Assert.AreEqual(itemA, mergeStructure.Instance.Value);
            Assert.AreEqual(itemB, mergeStructure.Compare.Value);

            Assert.AreEqual(0, mergeStructure.Nodes.Count);
            Assert.AreEqual(2, mergeStructure.Properties.Count);

            Assert.AreEqual(MergerCompareResult.Equal, mergeStructure.Properties.First().Value.First().Result);
            Assert.AreEqual(MergerCompareResult.Equal, mergeStructure.Result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
        public void TestInitialize()
        {
            var merger = new MyLittleMerger <LittleObject>();

            Assert.IsFalse(merger.Initialized);
            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });

            Assert.IsTrue(merger.Initialized);
        }
        public void TestContactObjectStructure()
        {
            var merger = new MyLittleMerger <ContactObject>();

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

            Assert.AreEqual(typeof(ContactObject), merger.Structure.Type);
            Assert.AreEqual(5, merger.Structure.Nodes.Count);
            Assert.AreEqual(6, merger.Structure.Properties.Count);
        }
        public void TestLittleObjectPrint()
        {
            var merger = new MyLittleMerger <LittleObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var print = merger.Structure.Print();

            Assert.IsFalse(string.IsNullOrEmpty(print));
            Assert.IsTrue(print.Contains($"- {nameof(LittleObject)}"));
            Assert.IsTrue(print.Contains($"{nameof(LittleObject.LonelyProperty)} - String"));
        }
        public void TestLittleObjectStructure()
        {
            var merger = new MyLittleMerger <LittleObject>();

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

            Assert.AreEqual(typeof(LittleObject), merger.Structure.Type);
            Assert.AreEqual(0, merger.Structure.Nodes.Count);
            Assert.AreEqual(1, merger.Structure.Properties.Count);
            Assert.AreEqual(typeof(string), merger.Structure.Properties[0].Type);
        }
Ejemplo n.º 9
0
        public void TestFindByPropertyFail()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var lonelyProperty = typeof(LittleObject).GetProperty(nameof(LittleObject.LonelyProperty));

            var success = merger.Structure.TryFind(lonelyProperty, out var result);

            Assert.IsFalse(success);
            Assert.IsNull(result);
        }
Ejemplo n.º 10
0
        public void TestFindByStringFail()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var foobarPath = $"{nameof(ContactObject)}.{nameof(ContactObject.Addresses)}.Foobar";

            var success = merger.Structure.TryFind(foobarPath, out var result);

            Assert.IsFalse(success);
            Assert.IsNull(result);
        }
Ejemplo n.º 11
0
        public void TestFindByStringPropertyCity()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var cityPath = $"{nameof(ContactObject)}.{nameof(ContactObject.Addresses)}.{nameof(AddressObject.City)}";

            var success = merger.Structure.TryFind(cityPath, out var result);

            Assert.IsTrue(success);
            Assert.IsNotNull(result);
            Assert.AreEqual(nameof(AddressObject.City), result.Identifier);
        }
Ejemplo n.º 12
0
        public void TestFindByPropertyPropertyCity()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var cityProperty = typeof(AddressObject).GetProperty(nameof(AddressObject.City));

            var success = merger.Structure.TryFind(cityProperty, out var result);

            Assert.IsTrue(success);
            Assert.IsNotNull(result);
            Assert.AreEqual(cityProperty?.Name, result.Identifier);
        }
Ejemplo n.º 13
0
        public void TestCompareStructureNode()
        {
            var merger = new MyLittleMerger <ContactObject>();

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

            var instanceStructureA = new MergerInstanceStructure <ContactObject>(merger.Structure, ContactData.David);
            var instanceStructureB = new MergerInstanceStructure <ContactObject>(merger.Structure, ContactData.Jennifer);
            var mergeStructure     = new MergerCompareStructure <ContactObject>(instanceStructureA, instanceStructureB);
            var print = mergeStructure.Print();

            Assert.IsTrue(print.Contains($"{ContactData.David.FirstName} <> {ContactData.Jennifer.FirstName}: {MergerCompareResult.Different}"));
        }
        public void TestPropertyNullArray()
        {
            var merger = new MyLittleMerger <NamedArrayObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var item = new NamedArrayObject()
            {
                Name = "Test", Items = null
            };
            var instanceStructure = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, item);
            var print             = instanceStructure.Print();

            Assert.IsTrue(print.Contains($"{nameof(NamedArrayObject.Name)} - {nameof(String)}: {item.Name}"));
            Assert.IsTrue(print.Contains($"{nameof(NamedArrayObject.Items)} - {nameof(String)}[]"));
        }
        public void TestPropertyNullString()
        {
            var merger = new MyLittleMerger <LittleObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var item = new LittleObject()
            {
                LonelyProperty = null
            };
            var instanceStructure = new MergerInstanceStructure <LittleObject>(merger.Structure, item);
            var print             = instanceStructure.Print();

            Assert.IsNull(instanceStructure.Properties.First().Value.First().Value);
            Assert.IsFalse(instanceStructure.Properties.First().Value.First().HasValue);
            Assert.IsTrue(print.Contains($"{nameof(LittleObject.LonelyProperty)} - {nameof(String)}: NULL"));
        }
Ejemplo n.º 16
0
        public void TestCompareStructurePropertyOnlyRightString()
        {
            var merger = new MyLittleMerger <NamedArrayObject>();

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

            var instanceStructureA = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, null);
            var itemB = new NamedArrayObject {
                Name = "ItemB"
            };
            var instanceStructureB = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, itemB);
            var mergeStructure     = new MergerCompareStructure <NamedArrayObject>(instanceStructureA, instanceStructureB);

            Assert.AreEqual(MergerCompareResult.OnlyRight, mergeStructure.Properties.First().Value.First().Result);
            Assert.AreEqual(MergerCompareResult.OnlyRight, mergeStructure.Result);
        }
Ejemplo n.º 17
0
        public void TestContactObjectPrint()
        {
            var merger = new MyLittleMerger <ContactObject>();

            merger.Initialize(new MergerOptions
            {
                AutoAddTypeAssembly = true
            });
            var print = merger.Structure.Print();

            Assert.IsFalse(string.IsNullOrEmpty(print));
            Assert.IsTrue(print.Contains($"- {nameof(ContactObject)}"));
            Assert.IsTrue(print.Contains($"{nameof(ContactObject.Id)} - {nameof(Guid)}"));
            Assert.IsTrue(print.Contains($"{nameof(ContactObject.FirstName)} - {nameof(String)}"));
            Assert.IsTrue(print.Contains($"{nameof(ContactObject.Friends)} - {nameof(String)}[]"));
            Assert.IsTrue(print.Contains($"{nameof(ContactObject.Birthday)} - {nameof(DateTime)}?"));
            Assert.IsTrue(print.Contains($"+ {nameof(ContactObject.Gender)} - {nameof(GenderEnum)}?"));
            Assert.IsTrue(print.Contains($"+ {nameof(ContactObject.Addresses)} - {nameof(AddressObject)}[]"));
            Assert.IsTrue(print.Contains($"+ {nameof(AddressObject.County)} - {nameof(CountryObject)}"));
        }
Ejemplo n.º 18
0
        public void TestCompareStructurePropertyOnlyRightProperty()
        {
            var merger = new MyLittleMerger <NamedArrayObject>();

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

            var itemA = new NamedArrayObject {
                Name = null, Items = new[] { "A1", "C", "A3" }
            };
            var instanceStructureA = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, itemA);
            var itemB = new NamedArrayObject {
                Name = "ItemB", Items = new[] { "B1", "C", "B3" }
            };
            var instanceStructureB = new MergerInstanceStructure <NamedArrayObject>(merger.Structure, itemB);
            var mergeStructure     = new MergerCompareStructure <NamedArrayObject>(instanceStructureA, instanceStructureB);

            Assert.AreEqual(MergerCompareResult.OnlyRight, mergeStructure.Properties.First().Value.First().Result);
            Assert.AreEqual(MergerCompareResult.Different, mergeStructure.Properties.Second().Value.First().Result);
            Assert.AreEqual(MergerCompareResult.Equal, mergeStructure.Properties.Second().Value.Second().Result);
            Assert.AreEqual(MergerCompareResult.Different, mergeStructure.Result);
        }