/// <summary> /// Compares two primitives. /// </summary> /// <param name="current"></param> /// <param name="next"></param> /// <returns></returns> /// <remarks>Cases when at least one is null, or they are different types are handled in <see cref="CreateDifferenceTree"/>.</remarks> public static DifferenceItem FromPrimitive(PrimitiveObjectTreeItem current, PrimitiveObjectTreeItem next) { // first check is currently redundant, but it might come handy if StateFormatter cached objects if (!ReferenceEquals(current, next) && !ReferenceEquals(current.Source, next.Source) && !Equals(current.Value, next.Value)) { return(new DifferenceItem(current, next, DiffType.Modified)); } return(null); }
public void WhenSameSourceSamePropertySameValue_ReturnsNull() { var source = new PrimitiveData("tn", 1); var current = new PrimitiveObjectTreeItem(source.Value, null, "pn", source); var next = new PrimitiveObjectTreeItem(source.Value, null, "pn", source); var actual = TreeComparer.FromPrimitive(current, next); Assert.That(actual, Is.Null); }
public void WhenDifferentSourceSamePropertyDifferentValue_DifferenceItemIsMarkedAsModified() { var currentSource = new PrimitiveData("tn", 1); var nextSource = new PrimitiveData("tn", 2); var current = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource); var next = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource); var actual = TreeComparer.FromPrimitive(current, next); Assert.That(actual.DiffType, Is.EqualTo(DiffType.Modified)); }
public void WhenDifferentSourceSamePropertyDifferentValue_ReturnsDifferenceItem() { var currentSource = new PrimitiveData("tn", 1); var nextSource = new PrimitiveData("tn", 2); var current = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource); var next = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource); var actual = TreeComparer.FromPrimitive(current, next); Assert.That(actual, Is.Not.Null); }
public void WhenDifferentSourceSamePropertyDifferentValue_DifferenceItemContainsBothItems() { var currentSource = new PrimitiveData("tn", 1); var nextSource = new PrimitiveData("tn", 2); var current = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource); var next = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource); var actual = TreeComparer.FromPrimitive(current, next); Assert.That(actual.Current, Is.SameAs(current)); Assert.That(actual.Next, Is.SameAs(next)); }