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); }
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); }
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); }
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); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="DiffCollectionGenerator{T}" /> class. /// </summary> /// <param name="keyProperties"></param> public DiffCollectionGenerator(params string[] keyProperties) { Argument.Assert.IsNotNull(keyProperties, nameof(keyProperties)); Argument.Assert.IsNotZeroLength(keyProperties, nameof(keyProperties)); keys = new string[keyProperties.Length]; keyProperties.CopyTo(keys, 0); diffGenerator = new DiffGenerator <T>(true, keys); }
public void PhoneNumberDiff() { PhoneNumber baseNumber = PhoneNumber.Parse("222-222-2222"); PhoneNumber newNumber = PhoneNumber.Parse("222-111-2222"); DiffGenerator <PhoneNumber> diffGenerator = new DiffGenerator <PhoneNumber>(); Diff <PhoneNumber> diff = diffGenerator.Generate(baseNumber, newNumber); Assert.AreEqual(1, diff.Entries.Count); }
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); }
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); }
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); }
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); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="DiffCollectionGenerator{T}" /> class. /// </summary> /// <param name="keyProperty1"></param> /// <param name="keyProperty2"></param> /// <param name="keyProperty3"></param> public DiffCollectionGenerator(string keyProperty1, string keyProperty2, string keyProperty3) { keys = new[] { keyProperty1, keyProperty2, keyProperty3 }; diffGenerator = new DiffGenerator <T>(true, keys); }