public void Comparison2EqualComplextObjectsShouldHaveNoDifference() { var complexObject = new ComplexObject(true); var compareResult = new JTokenComparer(new IndexArrayKeySelector()).Compare(complexObject, complexObject); compareResult.ComparisonResult.Should().Be(ComparisonResult.Identical, because: "The JObjects are created from the same CLR object instance"); }
public void Compare2EqualObjectsShouldNotHaveDifference() { var simpleObject = new SimpleObject(); var compareResult = new JTokenComparer(new IndexArrayKeySelector()).Compare(simpleObject, simpleObject); compareResult.ComparisonResult.Should().Be(ComparisonResult.Identical, because: "The JObjects are created from the same CLR object instance"); }
private void AssertJson(string expected, string actual) { var compare = new JTokenComparer(new IndexArrayKeySelector()); var result = compare.Compare(JObject.Parse(expected), JObject.Parse(actual)); Assert.AreEqual(ComparisonResult.Identical, result.ComparisonResult); }
public void WhenfilteringAllNotDifferenceShouldReported() { var jobject = JToken.FromObject(new SimpleObject()); var jobject2 = JToken.FromObject(new SimpleObject { Id = "12321", IntProperty = 214354 }); var compareResult = new JTokenComparer(new IndexArrayKeySelector(), new FilterAll()).Compare(jobject, jobject2); compareResult.ComparisonResult.Should().Be(ComparisonResult.Filtered, because: "I Filtered everything"); }
public void Comparison2EqualComplextObjectsWithOnlyWhiteSpaceShouldBeEqualWhenUsingTrimmedValueConverter() { var complexObject1 = new ComplexObject(true); var complexObject2 = new ComplexObject(true); complexObject2.StringProperty += " "; complexObject2.Children.ElementAt(0).StringProperty += " "; var compareResult = new JTokenComparer(new IndexArrayKeySelector(), Enumerable.Empty <IComparisonFilter>(), new TrimmingValueconverter()).Compare(complexObject1, complexObject2); compareResult.ComparisonResult.Should().Be(ComparisonResult.Identical, because: "The JObjects are only different in whitespace, but this should be trimmed."); }
public void Compare2EqualObjectsShouldNotHaveDifference() { dynamic simpleObject1 = new ExpandoObject(); simpleObject1.AAA = ""; dynamic simpleObject2 = new ExpandoObject(); simpleObject2.BBB = ""; var compareResult = new JTokenComparer(new IndexArrayKeySelector(), Enumerable.Empty <IComparrisonFilter>(), new ComparisonResult[] { ComparisonResult.MissingInSource2 }, new NonConvertingConverter()).Compare(simpleObject1, simpleObject2); compareResult.ComparrisonResult.Should().Be(ComparisonResult.Identical, because: "The JObjects are created from the same CLR object instance"); }
public void Compare2EqualArraysShouldHaveNoDifference() { var array = new SimpleObject[] { new SimpleObject(), new SimpleObject(), new SimpleObject(), }; var compareResult = new JTokenComparer(new IndexArrayKeySelector()).Compare(array, array); compareResult.ComparisonResult.Should().Be(ComparisonResult.Identical, because: "The JObjects are created from the same CLR object instance"); }
public void ObjectsWithDifferentValueForDateTimeShouldBeDifferent() { var compareResult = new JTokenComparer(new IndexArrayKeySelector()).Compare( new SimpleObject { DateTimeProperty = new DateTime(2345, 1, 1) }, new SimpleObject { DateTimeProperty = new DateTime(2000, 1, 1) }); compareResult.ComparrisonResult.Should().Be(ComparisonResult.Different, because: "The JObjects are created with different datetime"); }
public void Compare2EqualObjectsShouldNotHaveDifference() { dynamic simpleObject1 = new ExpandoObject(); simpleObject1.AAA = ""; dynamic simpleObject2 = new ExpandoObject(); simpleObject2.AAA = ""; var compareResult = new JTokenComparer(new IndexArrayKeySelector(), Enumerable.Empty <IComparisonFilter>(), new ComparisonResult[] { ComparisonResult.MissingInSource2 }, new NonConvertingConverter()).Compare(simpleObject1, simpleObject2); Assert.True(((JObjectComparisonResult)compareResult).ComparisonResult.Equals(ComparisonResult.Identical), "The JObjects have the same key names"); }
public void WhenfilteringPropertyOnlyNonFilteredShouldReported() { var jobject1 = JObject.FromObject(new SimpleObject()); var jobject2 = JObject.FromObject(new SimpleObject { IntProperty = 214354 }); var compareResult = new JTokenComparer(new IndexArrayKeySelector(), new FilterPropertyByName("IntProperty")).CompareObjects("root", jobject1, jobject2); compareResult.ComparisonResult.Should().Be(ComparisonResult.Identical, because: "Every different property is filtered."); compareResult.PropertyComparisons .Count(x => x.ComparisonResult == ComparisonResult.Different) .Should().Be(0, because: "There is 1 different propertybut it is filtered."); }
public void DeleteAllMatching(JToken key) { var comparer = new JTokenComparer(); foreach (var toRemove in bagsInMem .Where(x => comparer.Compare(x.Key, key)==0) .ToArray()) { bagsInMem.Remove(toRemove); } foreach (var treeNode in bags.ScanFromInclusive(key) .TakeWhile(x => comparer.Compare(key, x.NodeKey) == 0)) { bags.Remove(treeNode.NodeKey); } }
public void FilterPropertyByNameShouldFilterPropertyWithGivenName() { var jobject1 = JObject.FromObject(new SimpleObject()); var jobject2 = JObject.FromObject(new SimpleObject { IntProperty = 214354, DateTimeProperty = new DateTime(2000, 10, 10), StringProperty = "dfdshjfg" }); var filters = new List <IComparrisonFilter> { new FilterPropertyByName("IntProperty"), new FilterPropertyByName("DateTimeProperty"), }; var compareResult = new JTokenComparer(new IndexArrayKeySelector(), filters).CompareObjects("root", jobject1, jobject2); compareResult.ComparrisonResult.Should().Be(ComparisonResult.Different, because: "not everything should be filtered."); compareResult.PropertyComparrisons .Count(x => x.ComparrisonResult == ComparisonResult.Different) .Should().Be(1, because: "1 changed property is filtered."); }
public void IfAllPropertiesAreFilteredTheObjectShouldBeIdentical() { var jobject1 = JObject.FromObject(new SimpleObject()); var jobject2 = JObject.FromObject(new SimpleObject { IntProperty = 214354, DateTimeProperty = new DateTime(2000, 10, 10), StringProperty = "dfdshjfg" }); var filters = new List <IComparrisonFilter> { new FilterPropertyByName("IntProperty"), new FilterPropertyByName("DateTimeProperty"), new FilterPropertyByName("StringProperty"), }; var compareResult = new JTokenComparer(new IndexArrayKeySelector(), filters).CompareObjects("root", jobject1, jobject2); compareResult.ComparrisonResult.Should().Be(ComparisonResult.Identical, because: "not everything should be filtered."); compareResult.PropertyComparrisons .Count(x => x.ComparrisonResult == ComparisonResult.Different) .Should().Be(0, because: "All differences should be filtered."); }
private static void Main(string[] args) { try { var item1 = NewRecursiveClass(0); var item2 = NewRecursiveClass(0); var jObject1 = JToken.FromObject(item1); var jObject2 = JToken.FromObject(item2); var comparer = new JTokenComparer(); for (int i = 0; i < 100000; i++) { comparer.CompareTokens("root", jObject1, jObject2); } } catch (Exception e) { var a = e; } }