Example #1
0
        public void DiffEngineOneChangeWithPropertyFormat()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2223");

            const string             phoneFormat       = "{{AreaCode}}||{{Exchange}}||{{Number}}";
            FormattedProperty        formattedProperty = new FormattedProperty("PhoneNumber", phoneFormat);
            List <FormattedProperty> formats           = new List <FormattedProperty>();

            formats.Add(formattedProperty);

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>(formats);
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(1, diff.Entries.Count);
            Assert.AreEqual("Phone Number", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.PhoneNumber.ToString(phoneFormat), diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.PhoneNumber.ToString(phoneFormat), diff.Entries[0].NewValue);
            Assert.AreEqual("DiffObject", diff.Name);
        }
Example #2
0
        public void DiffEngineTwoChanges()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            diffObject2.Name    = "Brian Scott";
            diffObject2.Address = "150 Main Street";

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(2, diff.Entries.Count);
            Assert.AreEqual("Name", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.Name, diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.Name, diff.Entries[0].NewValue);
            Assert.AreEqual("Address", diff.Entries[1].Name);
            Assert.AreEqual(baseDiffObject.Address, diff.Entries[1].BaselineValue);
            Assert.AreEqual(diffObject2.Address, diff.Entries[1].NewValue);
        }
Example #3
0
        public void DiffWithBaselineFromPropertDiffBaselineClass()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffBaseline baseDiff = DiffBaseline.Create(diffObject2);

            Assert.AreEqual(NumberOfProperties, baseDiff.Entries.Count);

            diffObject2.Address     = "222 Main Street";
            diffObject2.PhoneNumber = PhoneNumber.Parse("444-444-4444");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiff, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(2, diff.Entries.Count);
            Assert.AreEqual("Address", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.Address, diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.Address, diff.Entries[0].NewValue);
            Assert.AreEqual("Phone Number", diff.Entries[1].Name);
            Assert.AreEqual(baseDiffObject.PhoneNumber.ToString(), diff.Entries[1].BaselineValue);
            Assert.AreEqual(diffObject2.PhoneNumber.ToString(), diff.Entries[1].NewValue);
        }
Example #4
0
        public void DiffWithNonAtrributedPropertyChange()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            diffObject2.Name     = "Brian Scott";
            diffObject2.Position = "Lead Developer";

            Diff <DiffObject> diff = baseDiffObject.CreateDiff(diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(2, diff.Entries.Count);
            Assert.AreEqual("Name", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.Name, diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.Name, diff.Entries[0].NewValue);
            Assert.AreEqual("Position", diff.Entries[1].Name);
            Assert.AreEqual(baseDiffObject.Position, diff.Entries[1].BaselineValue);
            Assert.AreEqual(diffObject2.Position, diff.Entries[1].NewValue);
        }
Example #5
0
        public void DiffWithVisableAndNonVisablePropertyChange()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            diffObject2.Address = "150 Main Street";
            diffObject2.Office  = "South";

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(1, diff.Entries.Count);
            Assert.AreEqual("Address", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.Address, diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.Address, diff.Entries[0].NewValue);
        }
Example #6
0
        public void DiffableInterfaceOnStruct()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            diffObject2.Address   = "150 Main Street";
            diffObject2.BirthDate = DateTime.Parse("1/1/1976");

            Diff <DiffObject> diff = baseDiffObject.CreateDiff(diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(2, diff.Entries.Count);
            Assert.AreEqual("Address", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.Address, diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.Address, diff.Entries[0].NewValue);
            Assert.AreEqual("BirthDate", diff.Entries[1].Name);
            Assert.AreEqual(baseDiffObject.BirthDate.ToString(), diff.Entries[1].BaselineValue);
            Assert.AreEqual(diffObject2.BirthDate.ToString(), diff.Entries[1].NewValue);
        }
Example #7
0
        public void DiffEngineChangeDateWithFriendlyName()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            baseDiffObject.HireDate = DateTime.Parse("06/22/2006 06:22");
            diffObject2.HireDate    = DateTime.Parse("12/12/2006 12:22");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(1, diff.Entries.Count);
            Assert.AreEqual("Hire Date", diff.Entries[0].Name);
            Assert.AreEqual("06-22-06", diff.Entries[0].BaselineValue);
            Assert.AreEqual("12-12-06", diff.Entries[0].NewValue);
        }
Example #8
0
        public void InvalidItemInPropertyList()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>("XAddressX");

            diffGenerator.Generate(baseDiffObject, diffObject2);
        }
Example #9
0
        public void AttemptDiffWithNullBaselineObject()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();

            diffGenerator.Generate(baseDiffObject, null);
        }
Example #10
0
        public void CreateBaseDiff()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            DiffBaseline diff = diffGenerator.GenerateBaseline(baseDiffObject);

            Assert.AreEqual(NumberOfProperties, diff.Entries.Count);
        }
Example #11
0
        public void DiffEngineChangeWithFriendlyName()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-4444");

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>();
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(1, diff.Entries.Count);
            Assert.AreEqual("Phone Number", diff.Entries[0].Name);
            Assert.AreEqual(baseDiffObject.PhoneNumber.ToString("{{AreaCode}}.{{Exchange}}.{{Number}}"), diff.Entries[0].BaselineValue);
            Assert.AreEqual(diffObject2.PhoneNumber.ToString("{{AreaCode}}.{{Exchange}}.{{Number}}"), diff.Entries[0].NewValue);
        }
Example #12
0
        public void OneChangeNotInExplicitPropertyList()
        {
            DiffObject baseDiffObject = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            baseDiffObject.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            DiffObject diffObject2 = new DiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject2.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            SubDiffObject diffObject3 = new SubDiffObject("Brian", "Developer", "111 Main Street", DateTime.Parse("1/1/1973"), "North");

            diffObject3.PhoneNumber = PhoneNumber.Parse("222-222-2222");

            diffObject2.Address = "150 Main Street";

            DiffGenerator <DiffObject> diffGenerator = new DiffGenerator <DiffObject>("Name");
            Diff <DiffObject>          diff          = diffGenerator.Generate(baseDiffObject, diffObject2);

            Assert.IsNotNull(diff);
            Assert.AreEqual(0, diff.Entries.Count);
        }
Example #13
0
 public Diff <DiffObject> CreateDiff(DiffObject other)
 {
     return(diffGenerator.Generate(this, other));
 }