public void After_clean_custom_comparer_for_value_type_dynamic_comparer_should_be_created() { var x = _fixture.Create <SampleObject <SampleStruct <string> > >(); var y = _fixture.Create <SampleObject <SampleStruct <string> > >(); var reference = new SampleObjectComparer <SampleStruct <string> >(new SampleStructComparer <string>()); var expected = reference.Compare(x, y); var builder = new ComparerBuilder(c => c.SetCustomComparer <SampleStructCustomComparer>()); var comparer1 = builder.GetComparer <SampleObject <SampleStruct <string> > >(); var comparer2 = builder.Configure(c => c.SetCustomComparer <SampleStruct <string> >(null)) .GetComparer <SampleObject <SampleStruct <string> > >(); using (new AssertionScope()) { comparer1.Compare(x, y).Should().Be(0); comparer2.Compare(x, y).Normalize().Should().Be(expected.Normalize()); } }
public void After_change_custom_comparer_new_dynamic_comparer_should_be_created() { Test(() => { var x = _fixture.Create <Tuple <int, string> >(); var y = _fixture.Create <Tuple <int, string> >(); var expected1 = x.Item1.CompareTo(y.Item1); var expected2 = x.Item2?.CompareTo(y.Item2) ?? -y.Item2?.CompareTo(null) ?? 0; var builder = new ComparerBuilder(c => c.SetCustomComparer(new CustomizableComparer <string>((__, _) => 0))); var comparer1 = builder.GetComparer <Tuple <int, string> >(); var comparer2 = builder.Configure(c => c.SetCustomComparer <string>(null) .SetCustomComparer(new CustomizableComparer <int>((__, _) => 0))) .GetComparer <Tuple <int, string> >(); using (new AssertionScope()) { comparer1.Compare(x, y).Normalize().Should().Be(expected1.Normalize()); comparer2.Compare(x, y).Normalize().Should().Be(expected2.Normalize()); } }); }
public IComparer <T> GetComparer() => _subject.GetComparer <T>();