protected override void EndProcessing() { InputObjects.Sort(Compare); IEnumerable <PSObject> outputObjects = InputObjects; if (Unique.ToBool()) { PropertyEqualityComparer comparer = new PropertyEqualityComparer(null); if (Property != null) { comparer.Properties = Property.Select(p => p.ToString()).ToList(); } PSObject prevObj = null; foreach (PSObject obj in InputObjects) { if (!comparer.Equals(obj, prevObj)) { WriteObject(obj); } prevObj = obj; } } else { foreach (PSObject obj in InputObjects) { WriteObject(obj); } } }
protected override void EndProcessing() { InputObjects.Sort(Compare); IEnumerable<PSObject> outputObjects = InputObjects; if (Unique.ToBool()) { PropertyEqualityComparer comparer = new PropertyEqualityComparer(null); if (Property != null) comparer.Properties = Property.Select(p => p.ToString()).ToList(); PSObject prevObj = null; foreach (PSObject obj in InputObjects) { if (!comparer.Equals(obj, prevObj)) WriteObject(obj); prevObj = obj; } } else { foreach (PSObject obj in InputObjects) { WriteObject(obj); } } }
public void throws_exception_if_selector_is_null() { Assert.Throws <ArgumentNullException>(() => { PropertyEqualityComparer.For <string>(null); }); }
public void ReturnsTrue_IfBothParametersAreNull() { var subject = new PropertyEqualityComparer <TestClass, int>(x => x.IntValue); var results = subject.Equals(null, null); results.ShouldBeTrue(); }
public void compare_two_string_by_length_using_equals() { const string string1 = "lorem"; const string string2 = "ipsum"; var comparer = PropertyEqualityComparer.For <string>(x => x.Length); comparer.Equals(string1, string2).ShouldBeTrue(); }
public void compare_two_string_by_length_using_get_hash_code() { const string string1 = "lorem"; const string string2 = "ipsum"; var comparer = PropertyEqualityComparer.For <string>(x => x.Length); comparer.GetHashCode(string1) .ShouldBe(comparer.GetHashCode(string2)); }
public static IEnumerable <TSource> Except <TSource, TKey>(this IEnumerable <TSource> first, IEnumerable <TSource> second, Func <TSource, TKey> keyGetter) { var comparer = new PropertyEqualityComparer <TSource, TKey>(keyGetter); var firstTuples = first.Select(comparer.Wrap); var secondTuples = second.Select(comparer.Wrap); return(firstTuples.Except(secondTuples, comparer) .Select(comparer.Unwrap)); }
public void DoesNotThrowException_IfCalledWithObjectWhoseProjectionIsNull() { var test = new TestClass { StrValue = null }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue); Should.NotThrow(() => { subject.GetHashCode(test); }); }
public void ReturnsFalse_IfEitherButNotBothParametersAreNull() { var test = new TestClass(); var subject = new PropertyEqualityComparer <TestClass, int>(x => x.IntValue); var results1 = subject.Equals(null, test); var results2 = subject.Equals(test, null); results1.ShouldBeFalse(); results2.ShouldBeFalse(); }
public void IsReflexive_IfCalledWithoutComparer() { var test = new TestClass { StrValue = "testing" }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue); var results = subject.Equals(test, test); results.ShouldBeTrue(); }
public void ReturnsSameValue_IfCalledMultipleSubsequentTimesWithComparer() { var test = new TestClass { StrValue = "This is a test." }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue, StringComparer.Ordinal); var results1 = subject.GetHashCode(test); var results2 = subject.GetHashCode(test); results1.ShouldBe(results2); }
public void ReturnsTrue_IfProjectionsOfBothParametersAreEqual() { var test1 = new TestClass { IntValue = 99 }; var test2 = new TestClass { IntValue = 99 }; var subject = new PropertyEqualityComparer <TestClass, int>(x => x.IntValue); var results = subject.Equals(test1, test2); results.ShouldBeTrue(); }
public void ReturnsTrue_IfProjectionsOfBothParametersAreNull() { var test1 = new TestClass { StrValue = null }; var test2 = new TestClass { StrValue = null }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue); var results = subject.Equals(test1, test2); results.ShouldBeTrue(); }
public void ReturnsFalse_IfProjectionsOfBothParametersAreNotEqualWithComparer() { var test1 = new TestClass { StrValue = "TESTING" }; var test2 = new TestClass { StrValue = "testing" }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue, StringComparer.Ordinal); var results = subject.Equals(test1, test2); results.ShouldBeFalse(); }
public void ReturnsFalse_IfProjectionsOfEitherButNotBothParametersAreNull() { var test1 = new TestClass { StrValue = "testing" }; var test2 = new TestClass { StrValue = null }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue); var results1 = subject.Equals(test1, test2); var results2 = subject.Equals(test2, test1); results1.ShouldBeFalse(); results2.ShouldBeFalse(); }
public void ReturnsSameValue_IfProjectionsOfDifferentObjectsAreEqualWithComparer() { var test1 = new TestClass { StrValue = "TESTING" }; var test2 = new TestClass { StrValue = "testing" }; var subject = new PropertyEqualityComparer <TestClass, string>(x => x.StrValue, StringComparer.OrdinalIgnoreCase); var results1 = subject.GetHashCode(test1); var results2 = subject.GetHashCode(test2); var results3 = subject.Equals(test1, test2); results3.ShouldBeTrue(); results1.ShouldBe(results2); }
public void PropertyEqualityComparerTest() { var list1 = new List <GenericItem> { new GenericItem { ID = 1, Name = "John", Value = "1" }, new GenericItem { ID = 1, Name = "Marc", Value = "2" }, new GenericItem { ID = 2, Name = null, Value = "3" } }; var list2 = new List <GenericItem> { new GenericItem { ID = 1, Name = null, Value = "1" } }; var result = list1.Except(list2, PropertyEqualityComparer <GenericItem> .ByProperty(x => x.Name, false)); }
public void DoesNotThrowException_IfCalledWithNullObject() { var subject = new PropertyEqualityComparer <TestClass, int>(x => x.IntValue); Should.NotThrow(() => { subject.GetHashCode(null); }); }