// Constructors /// <summary> /// Initializes a new instance of this type. /// </summary> /// <param name="provider">Comparer provider this comparer is bound to.</param> /// <param name="comparisonRules">Comparison rules.</param> public WrappingComparer(IComparerProvider provider, ComparisonRules comparisonRules) : base(provider, comparisonRules) { ArgumentValidator.EnsureArgumentNotNull(provider, "provider"); BaseComparer1 = provider.GetComparer <TBase1>().ApplyRules(comparisonRules[0]); BaseComparer2 = provider.GetComparer <TBase2>().ApplyRules(comparisonRules[1]); }
private void Test <T>(IComparerProvider <T> builder) where T : INestedObject { var comparer = builder.GetComparer(); for (var i = 0; i < 10; i++) { var x = (T)(object)_fixture.Create <SealedNestedObject>(); var y = (T)(object)_fixture.Create <SealedNestedObject>(); var expected = string.CompareOrdinal(x.Text, y.Text).Normalize(); var actual = comparer.Compare(x, y).Normalize(); actual.Should().Be(expected, $"\nx: {x.ToJson()},\ny: {y.ToJson()}"); } }
private static void Test <T>(IComparerProvider comparersBuilder, IComparer <T> referenceComparer, int times, int count) { if (referenceComparer == null) { referenceComparer = Helper.DefaultComparer <T>(); } var typedComparer = comparersBuilder.GetComparer <T>(); Parallel.Invoke( () => { Comparison_of_null_with_object_produces_negative_value(referenceComparer, typedComparer); Comparison_of_object_with_null_produces_positive_value(referenceComparer, typedComparer); Comparison_when_both_null_produces_0(referenceComparer, typedComparer); Comparison_with_itself_produces_0(referenceComparer, typedComparer); Comparison_with_same_produces_0(referenceComparer, typedComparer); }, () => Comparisons_work_identical(referenceComparer, typedComparer, times), () => Sorting_must_work_the_same_as_for_reference_comparer(referenceComparer, typedComparer, count), () => Mutate_class_members_and_test_comparison(referenceComparer, typedComparer) ); }