public void Expoising_internals_of_many_types() { var result = default(ComparisonBuilder); var versionProperties = default(PropertyReader[]); var uriProperties = default(PropertyReader[]); "Given a builder" .x(() => SUT = new ComparisonBuilder()); "When exposing the internals of Version" .x(() => result = SUT.ExposeInternalsOf(typeof(Version), typeof(Uri))); "And".x(() => versionProperties = ReflectionCache.GetProperties(new Version(1, 2, 3, 4))); "And".x(() => uriProperties = ReflectionCache.GetProperties(new Uri("http://google.com"))); "Then ReflectionCache should contain the private properties of Version" .x(() => versionProperties.ShouldContain(x => x.Name == "_Major")); "And ReflectionCache should contain the private properties of Uri" .x(() => uriProperties.ShouldContain(x => x.Name == "m_Syntax")); "And it should return the builder" .x(() => result.ShouldBeSameAs(SUT)); }
public void Ignoring_specific_properties() { var result = default(ComparisonBuilder); "Given a builder".x(() => SUT = new ComparisonBuilder() ); "When ignoring the Major property of Version".x(() => result = SUT.IgnoreProperty <Version>(x => x.Major) ); "Then it should add an IgnoredProperty".x(() => SUT.ComplexObjectComparison.IgnoredProperties.Count.ShouldBe(1) ); "And it should return true for the Major property of the Version type".x(() => SUT.ComplexObjectComparison.IgnoredProperties[0](new PropertyReader { DeclaringType = typeof(Version), Name = "Major" }).ShouldBe(true) ); "And it should return the builder".x(() => result.ShouldBeSameAs(SUT) ); }
public void Adding_a_custom_Comparison() { var result = default(ComparisonBuilder); var custom = default(IComparison); "Given a builder".x(() => SUT = new ComparisonBuilder() ); "And a custom comparison".x(() => custom = new Mock <IComparison>().Object ); "When adding the custom comparison".x(() => result = SUT.WithCustomComparison(custom) ); "Then there should be a custom comparison".x(() => SUT.CustomComparisons.Count.ShouldBe(1) ); "And it should be the correct comparison".x(() => SUT.CustomComparisons[0].ShouldBeSameAs(custom) ); "And it should return the builder".x(() => result.ShouldBeSameAs(SUT) ); }
public void KitchenSink() { var object1 = new { A = 1, B = UriKind.Absolute, C = new List <int> { 1, 2, 3 }, Float = 1.111_111_8f, Double = 1.111_111_111_111_118d, Inner = new { X = 1, Y = 2, Z = 3 }, Set = new[] { 3, 4, 2, 1 }, Dictionary = new Dictionary <int, int> { { 2, 3 }, { 123, 234 }, { 345, 456 } } }; var object2 = new { A = 1, B = "Absolute", C = new[] { 1, 2, 3 }, Float = 1.111_111_9m, Double = 1.111_111_111_111_119m, Inner = new TestType { X = 1, Y = 3, Z = 3 }, Set = new HashSet <int> { 1, 2, 3, 4 }, Dictionary = new Dictionary <int, int> { { 123, 234 }, { 345, 456 }, { 2, 3 } } }; var comparison = new ComparisonBuilder() .IgnoreProperty <TestType>(x => x.Y) .Create(); DeepAssert.AreEqual(object1, object2, comparison); }
public void Creating_a_builder() { "When creating a builder" .When(() => SUT = new ComparisonBuilder()); "Then there should be no custom comparisons" .Then(() => SUT.CustomComparisons.ShouldBeEmpty()); "And UnmatchedPropertiesIgnored should be false" .And(() => SUT.ComplexObjectComparison.IgnoreUnmatchedProperties.ShouldBe(false)); }
public void Default_floating_point_tolerance() { "Given a builder".x(() => SUT = new ComparisonBuilder() ); "Then the tolerance should be set".x(() => { SUT.DoubleTolerance.ShouldBe(1e-15d); SUT.SingleTolerance.ShouldBe(1e-6f); }); }
public void Creating_a_Comparison_and_ignoring_unmatched_properties() { var result = default(CompositeComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And we call IgnoreUnmatchedProperties" .And(() => SUT.IgnoreUnmatchedProperties()); "When calling Create" .When(() => result = SUT.Create()); "Then it not return null" .Then(() => result.ShouldNotBe(null)); "And the 1st comparer is the DefaultComparison" .And(() => result.Comparisons[0].ShouldBeTypeOf <DefaultComparison>()); "And the 2nd comparer is the EnumComparison" .And(() => result.Comparisons[1].ShouldBeTypeOf <EnumComparison>()); "And the 3rd comparer is the DictionaryComparison" .And(() => result.Comparisons[2].ShouldBeTypeOf <DictionaryComparison>()); "... with a DefaultComparison as the key comparer" .And(() => ((DictionaryComparison)result.Comparisons[2]).KeyComparer.ShouldBeTypeOf <DefaultComparison>()); "... and the value comparer is the result" .And(() => ((DictionaryComparison)result.Comparisons[2]).ValueComparer.ShouldBeSameAs(result)); "And the 4th comparer is the DictionaryComparison" .And(() => result.Comparisons[3].ShouldBeTypeOf <SetComparison>()); "... and the inner comparer is the result" .And(() => ((SetComparison)result.Comparisons[3]).Inner.ShouldBeSameAs(result)); "And the 5th comparer is the DictionaryComparison" .And(() => result.Comparisons[4].ShouldBeTypeOf <ListComparison>()); "... and the inner comparer is the result" .And(() => ((ListComparison)result.Comparisons[4]).Inner.ShouldBeSameAs(result)); "And the 6th comparer is the ComplexObjectComparison" .And(() => result.Comparisons[5].ShouldBeTypeOf <ComplexObjectComparison>()); "... and the inner comparer is the result" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).Inner.ShouldBeSameAs(result)); "... and IgnoreUnmatchedProperties should be true" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).IgnoreUnmatchedProperties.ShouldBe(true)); }
public void Creating_a_Comparison_and_ignoring_unmatched_properties() { var result = default (CompositeComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And we call IgnoreUnmatchedProperties" .And(() => SUT.IgnoreUnmatchedProperties()); "When calling Create" .When(() => result = SUT.Create()); "Then it not return null" .Then(() => result.ShouldNotBe(null)); "And the 1st comparer is the DefaultComparison" .And(() => result.Comparisons[0].ShouldBeTypeOf<DefaultComparison>()); "And the 2nd comparer is the EnumComparison" .And(() => result.Comparisons[1].ShouldBeTypeOf<EnumComparison>()); "And the 3rd comparer is the DictionaryComparison" .And(() => result.Comparisons[2].ShouldBeTypeOf<DictionaryComparison>()); "... with a DefaultComparison as the key comparer" .And(() => ((DictionaryComparison)result.Comparisons[2]).KeyComparer.ShouldBeTypeOf<DefaultComparison>()); "... and the value comparer is the result" .And(() => ((DictionaryComparison)result.Comparisons[2]).ValueComparer.ShouldBeSameAs(result)); "And the 4th comparer is the DictionaryComparison" .And(() => result.Comparisons[3].ShouldBeTypeOf<SetComparison>()); "... and the inner comparer is the result" .And(() => ((SetComparison)result.Comparisons[3]).Inner.ShouldBeSameAs(result)); "And the 5th comparer is the DictionaryComparison" .And(() => result.Comparisons[4].ShouldBeTypeOf<ListComparison>()); "... and the inner comparer is the result" .And(() => ((ListComparison)result.Comparisons[4]).Inner.ShouldBeSameAs(result)); "And the 6th comparer is the ComplexObjectComparison" .And(() => result.Comparisons[5].ShouldBeTypeOf<ComplexObjectComparison>()); "... and the inner comparer is the result" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).Inner.ShouldBeSameAs(result)); "... and IgnoreUnmatchedProperties should be true" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).IgnoreUnmatchedProperties.ShouldBe(true)); }
public void Test() { var object1 = new { A = 1, B = UriKind.Absolute, C = new List<int> {1, 2, 3}, Inner = new { X = 1, Y = 2, Z = 3 }, Set = new[] {3, 4, 2, 1}, Dictionary = new Dictionary<int, int> { {2, 3}, {123, 234}, {345, 456} } }; var object2 = new { A = 1, B = "Absolute", C = new[] {1, 2, 3}, Inner = new TestType { X = 1, Y = 3, Z = 3 }, Set = new HashSet<int> {1, 2, 3, 4}, Dictionary = new Dictionary<int, int> { {123, 234}, {345, 456}, {2, 3} } }; var comparison = new ComparisonBuilder() .IgnoreProperty<TestType>(x => x.Y) .Create(); DeepAssert.AreEqual(object1, object2, comparison); }
public void Ignoring_unmatched_properties() { var result = default(ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.IgnoreUnmatchedProperties()); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.ComplexObjectComparison.IgnoreUnmatchedProperties.ShouldBe(true)); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Skipping_default_comparison_for_types() { var result = default(ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.SkipDefault <Version>()); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.DefaultComparison.SkippedTypes.ShouldContain(typeof(Version))); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Ignoring_specific_properties() { var result = default(ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.IgnoreProperty <Version>(x => x.Major)); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.ComplexObjectComparison.IgnoredProperties[typeof(Version)].ShouldContain("Major")); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Skipping_default_comparison_for_types() { var result = default(ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When skipping the default comparison fer Version" .When(() => result = SUT.SkipDefault <Version>()); "Then SkippedTypes should contain Version" .Then(() => SUT.DefaultComparison.SkippedTypes.ShouldContain(typeof(Version))); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public static Expression <Func <T, bool> > GetRsqlPredicate <T>(string?rsql, ComparisonBuilder comparisonBuilder) { comparisonBuilder = comparisonBuilder ?? throw new ArgumentNullException(nameof(comparisonBuilder)); if (string.IsNullOrWhiteSpace(rsql)) { throw new ArgumentNullException(nameof(rsql)); } var antlrInputStream = new AntlrInputStream(rsql); var lexer = new RsqlLexer(antlrInputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new RsqlParser(commonTokenStream); var visitor = new RsqlVisitor <T>(comparisonBuilder); var predicate = visitor.Visit(parser.start()); return(predicate); }
public void Expoising_internals_of_a_given_type() { var result = default(ComparisonBuilder); var properties = default(PropertyReader[]); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When exposing the internals of Version" .When(() => result = SUT.ExposeInternalsOf <Version>()) .And("", () => properties = ReflectionCache.GetProperties(new Version(1, 2, 3, 4))); "Then ReflectionCache should contain the private properties of Version" .Then(() => properties.ShouldContain(x => x.Name == "_Major")); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Creating_a_Comparison_and_ignoring_unmatched_properties() { var result = default (CompositeComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And we call IgnoreUnmatchedProperties" .And(() => SUT.IgnoreUnmatchedProperties()); "When calling Create" .When(() => result = SUT.Create()); "Then the 6th comparer is the ComplexObjectComparison" .Then(() => result.Comparisons[5].ShouldBeTypeOf<ComplexObjectComparison>()); "... and IgnoreUnmatchedProperties should be true" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).IgnoreUnmatchedProperties.ShouldBe(true)); }
public void Creating_a_Comparison_and_ignoring_unmatched_properties() { var result = default(CompositeComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And we call IgnoreUnmatchedProperties" .And(() => SUT.IgnoreUnmatchedProperties()); "When calling Create" .When(() => result = SUT.Create()); "Then the 6th comparer is the ComplexObjectComparison" .Then(() => result.Comparisons[5].ShouldBeTypeOf <ComplexObjectComparison>()); "... and IgnoreUnmatchedProperties should be true" .And(() => ((ComplexObjectComparison)result.Comparisons[5]).IgnoreUnmatchedProperties.ShouldBe(true)); }
public void Creating_a_Comparison_with_custom_comparisons() { var result = default(CompositeComparison); var custom = default(IComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And a custom comparison" .And(() => { custom = new Mock <IComparison>().Object; SUT.WithCustomComparison(custom); }); "When calling Create" .When(() => result = SUT.Create()); "Then the 1st comparer is the custom comparison" .Then(() => result.Comparisons[0].ShouldBeSameAs(custom)); }
public static void When_exposing_internals_differences_in_internals_count() { var expected = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var actual = new ClassWithPrivates(321) { Id = 234, Name = "Joe", Internal = "!!!" }; var comparison = new ComparisonBuilder() .ExposeInternalsOf <ClassWithPrivates>() .Create(); DeepAssert.AreNotEqual(actual, expected, comparison); }
public static void When_exposing_internals_similar_objects_are_considered_the_same() { var expected = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var actual = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var comparison = new ComparisonBuilder() .ExposeInternalsOf <ClassWithPrivates>() .Create(); DeepAssert.AreEqual(actual, expected, comparison); }
public static void When_exposing_internals_similar_objects_are_considered_the_same() { var expected = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var actual = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var comparison = new ComparisonBuilder() .ExposeInternalsOf<ClassWithPrivates>() .Create(); DeepAssert.AreEqual(actual, expected, comparison); }
public static void When_exposing_internals_differences_in_internals_count() { var expected = new ClassWithPrivates(123) { Id = 234, Name = "Joe", Internal = "???" }; var actual = new ClassWithPrivates(321) { Id = 234, Name = "Joe", Internal = "!!!" }; var comparison = new ComparisonBuilder() .ExposeInternalsOf<ClassWithPrivates>() .Create(); DeepAssert.AreNotEqual(actual, expected, comparison); }
public void Setting_floating_point_tolerance() { var result = default(ComparisonBuilder); "Given a builder".x(() => SUT = new ComparisonBuilder() ); "When setting floating point tolerance".x(() => result = SUT.WithFloatingPointTolerance(0.001d, 0.2f) ); "Then the tolerance should be set".x(() => { SUT.DoubleTolerance.ShouldBe(0.001d); SUT.SingleTolerance.ShouldBe(0.2f); }); "And it should return the builder".x(() => result.ShouldBeSameAs(SUT) ); }
public void Adding_a_custom_Comparison() { var result = default (ComparisonBuilder); var custom = default (IComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And a custom comparison" .And(() => custom = new Mock<IComparison>().Object); "When adding the custom comparison" .When(() => result = SUT.WithCustomComparison(custom)); "Then there should be a custom comparison" .Then(() => SUT.CustomComparisons.Count.ShouldBe(1)); "And it should be the correct comparison" .And(() => SUT.CustomComparisons[0].ShouldBeSameAs(custom)); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void PersonEqualsTest() { Person mainPerson = SinglePerson; Person otherPerson = SinglePerson; Assert.IsTrue(mainPerson.IsDeepEqual(otherPerson)); otherPerson.Id = 5; Assert.IsFalse(mainPerson.IsDeepEqual(otherPerson)); otherPerson.FirstName = "Jim"; //mainPerson.WithDeepEqual(otherPerson).SkipDefault<Person>().IgnoreSourceProperty(x => x.Id).Assert(); var comparison = new ComparisonBuilder() .IgnoreProperty <Person>(x => x.Id) .Create(); DeepAssert.AreNotEqual(mainPerson, otherPerson, comparison); otherPerson.Id = mainPerson.Id; otherPerson.FirstName = mainPerson.FirstName; Assert.IsTrue(mainPerson.IsDeepEqual(otherPerson)); }
public static void ShouldDeepEqual( this object actual, object expected, IComparison comparison, IDifferenceFormatterFactory formatterFactory) { var builder = new ComparisonBuilder(); comparison = comparison ?? builder.Create(); formatterFactory = formatterFactory ?? builder.GetFormatterFactory(); var context = new ComparisonContext(); var(result, newContext) = comparison.Compare(context, actual, expected); if (result != ComparisonResult.Fail) { return; } var message = new DeepEqualExceptionMessageBuilder(newContext, formatterFactory).GetMessage(); throw new DeepEqualException(message, newContext); }
public void Creating_a_default_Comparison() { var result = default(CompositeComparison); "Given a builder".x(() => SUT = new ComparisonBuilder() ); "When calling Create".x(() => result = SUT.Create() ); "Then it not return null".x(() => result.ShouldNotBe(null) ); "And the 1st comparer is the DefaultComparison".x(() => result.Comparisons[0].ShouldBeAssignableTo <FloatComparison>() ); "And the 2nd comparer is the DefaultComparison".x(() => result.Comparisons[1].ShouldBeAssignableTo <DefaultComparison>() ); "And the 3rd comparer is the EnumComparison".x(() => result.Comparisons[2].ShouldBeAssignableTo <EnumComparison>() ); "And the 4th comparer is the DictionaryComparison".x(() => result.Comparisons[3].ShouldBeAssignableTo <DictionaryComparison>() ); "... with a DefaultComparison as the key comparer".x(() => ((DictionaryComparison)result.Comparisons[3]).KeyComparer.ShouldBeAssignableTo <DefaultComparison>() ); "... and the value comparer is the result".x(() => ((DictionaryComparison)result.Comparisons[3]).ValueComparer.ShouldBeSameAs(result) ); "And the 5th comparer is the DictionaryComparison".x(() => result.Comparisons[4].ShouldBeAssignableTo <SetComparison>() ); "... and the inner comparer is the result".x(() => ((SetComparison)result.Comparisons[4]).Inner.ShouldBeSameAs(result) ); "And the 6th comparer is the DictionaryComparison".x(() => result.Comparisons[5].ShouldBeAssignableTo <ListComparison>() ); "... and the inner comparer is the result".x(() => ((ListComparison)result.Comparisons[5]).Inner.ShouldBeSameAs(result) ); "And the 7th comparer is the ComplexObjectComparison".x(() => result.Comparisons[6].ShouldBeAssignableTo <ComplexObjectComparison>() ); "... and the inner comparer is the result".x(() => ((ComplexObjectComparison)result.Comparisons[6]).Inner.ShouldBeSameAs(result) ); "... and IgnoreUnmatchedProperties should be false".x(() => ((ComplexObjectComparison)result.Comparisons[6]).IgnoreUnmatchedProperties.ShouldBe(false) ); }
public void Creating_a_Comparison_with_custom_comparisons() { var result = default (CompositeComparison); var custom = default (IComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And a custom comparison" .And(() => { custom = new Mock<IComparison>().Object; SUT.WithCustomComparison(custom); }); "When calling Create" .When(() => result = SUT.Create()); "Then the 1st comparer is the custom comparison" .Then(() => result.Comparisons[0].ShouldBeSameAs(custom)); }
public void Skipping_default_comparison_for_types() { var result = default (ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When skipping the default comparison fer Version" .When(() => result = SUT.SkipDefault<Version>()); "Then SkippedTypes should contain Version" .Then(() => SUT.DefaultComparison.SkippedTypes.ShouldContain(typeof (Version))); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Dispose() { ComparisonBuilder.Reset(); }
public CompareSyntax(TActual actual, TExpected expected) { Actual = actual; Expected = expected; Builder = ComparisonBuilder.Get(); }
public void Ignoring_unmatched_properties() { var result = default (ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.IgnoreUnmatchedProperties()); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.ComplexObjectComparison.IgnoreUnmatchedProperties.ShouldBe(true)); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Expoising_internals_of_many_types() { var result = default (ComparisonBuilder); var versionProperties = default (PropertyReader[]); var uriProperties = default (PropertyReader[]); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When exposing the internals of Version" .When(() => result = SUT.ExposeInternalsOf(typeof(Version), typeof(Uri))) .And("", () => versionProperties = ReflectionCache.GetProperties(new Version(1, 2, 3, 4))) .And("", () => uriProperties = ReflectionCache.GetProperties(new Uri("http://google.com"))); "Then ReflectionCache should contain the private properties of Version" .Then(() => versionProperties.ShouldContain(x => x.Name == "_Major")); "And ReflectionCache should contain the private properties of Uri" .Then(() => uriProperties.ShouldContain(x => x.Name == "m_Syntax")); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Ignoring_specific_properties_2() { var result = default (ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring the Major property of Version" .When(() => result = SUT.IgnoreProperty(x => x.Name == "Major")); "Then it should add an IgnoredProperty" .Then(() => SUT.ComplexObjectComparison.IgnoredProperties.Count.ShouldBe(1)); "And it should return true for the Major property of the Version type" .Then(() => SUT.ComplexObjectComparison.IgnoredProperties[0](new PropertyReader { Name = "Major" }).ShouldBe(true)); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public static bool IsDeepEqual(this object actual, object expected) { var comparison = new ComparisonBuilder().Create(); return(IsDeepEqual(actual, expected, comparison)); }
public static void ShouldDeepEqual(this object actual, object expected, bool recursionProtection = true) { var comparison = new ComparisonBuilder().Create(); ShouldDeepEqual(actual, expected, comparison, recursionProtection); }
public void Creating_a_Comparison_with_custom_comparisons() { var result = default (CompositeComparison); var custom = default (IComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And a custom comparison" .And(() => { custom = new Mock<IComparison>().Object; SUT.WithCustomComparison(custom); }); "When calling Create" .When(() => result = SUT.Create()); "Then it not return null" .Then(() => result.ShouldNotBe(null)); "And the 1st comparer is the custom comparison" .And(() => result.Comparisons[0].ShouldBeSameAs(custom)); "And the 2nd comparer is the DefaultComparison" .And(() => result.Comparisons[1].ShouldBeTypeOf<DefaultComparison>()); "And the 3rd comparer is the EnumComparison" .And(() => result.Comparisons[2].ShouldBeTypeOf<EnumComparison>()); "And the 4th comparer is the DictionaryComparison" .And(() => result.Comparisons[3].ShouldBeTypeOf<DictionaryComparison>()); "... with a DefaultComparison as the key comparer" .And(() => ((DictionaryComparison)result.Comparisons[3]).KeyComparer.ShouldBeTypeOf<DefaultComparison>()); "... and the value comparer is the result" .And(() => ((DictionaryComparison)result.Comparisons[3]).ValueComparer.ShouldBeSameAs(result)); "And the 5th comparer is the DictionaryComparison" .And(() => result.Comparisons[4].ShouldBeTypeOf<SetComparison>()); "... and the inner comparer is the result" .And(() => ((SetComparison)result.Comparisons[4]).Inner.ShouldBeSameAs(result)); "And the 6th comparer is the DictionaryComparison" .And(() => result.Comparisons[5].ShouldBeTypeOf<ListComparison>()); "... and the inner comparer is the result" .And(() => ((ListComparison)result.Comparisons[5]).Inner.ShouldBeSameAs(result)); "And the 7th comparer is the ComplexObjectComparison" .And(() => result.Comparisons[6].ShouldBeTypeOf<ComplexObjectComparison>()); "... and the inner comparer is the result" .And(() => ((ComplexObjectComparison)result.Comparisons[6]).Inner.ShouldBeSameAs(result)); "... and IgnoreUnmatchedProperties should be false" .And(() => ((ComplexObjectComparison)result.Comparisons[6]).IgnoreUnmatchedProperties.ShouldBe(false)); }
public void Ignoring_specific_properties() { var result = default (ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.IgnoreProperty<Version>(x => x.Major)); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.ComplexObjectComparison.IgnoredProperties[typeof(Version)].ShouldContain("Major")); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public void Skipping_default_comparison_for_types() { var result = default (ComparisonBuilder); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When ignoring unmatched properties" .When(() => result = SUT.SkipDefault<Version>()); "Then UnmatchedPropertiesIgnored should be true" .Then(() => SUT.DefaultComparison.SkippedTypes.ShouldContain(typeof (Version))); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public static void ShouldDeepEqual(this object actual, object expected) { var comparison = new ComparisonBuilder().Create(); ShouldDeepEqual(actual, expected, comparison); }
public void Creating_a_Comparison_with_custom_comparisons() { var result = default(CompositeComparison); var custom = default(IComparison); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "And a custom comparison" .And(() => { custom = new Mock <IComparison>().Object; SUT.WithCustomComparison(custom); }); "When calling Create" .When(() => result = SUT.Create()); "Then it not return null" .Then(() => result.ShouldNotBe(null)); "And the 1st comparer is the custom comparison" .And(() => result.Comparisons[0].ShouldBeSameAs(custom)); "And the 2nd comparer is the DefaultComparison" .And(() => result.Comparisons[1].ShouldBeTypeOf <DefaultComparison>()); "And the 3rd comparer is the EnumComparison" .And(() => result.Comparisons[2].ShouldBeTypeOf <EnumComparison>()); "And the 4th comparer is the DictionaryComparison" .And(() => result.Comparisons[3].ShouldBeTypeOf <DictionaryComparison>()); "... with a DefaultComparison as the key comparer" .And(() => ((DictionaryComparison)result.Comparisons[3]).KeyComparer.ShouldBeTypeOf <DefaultComparison>()); "... and the value comparer is the result" .And(() => ((DictionaryComparison)result.Comparisons[3]).ValueComparer.ShouldBeSameAs(result)); "And the 5th comparer is the DictionaryComparison" .And(() => result.Comparisons[4].ShouldBeTypeOf <SetComparison>()); "... and the inner comparer is the result" .And(() => ((SetComparison)result.Comparisons[4]).Inner.ShouldBeSameAs(result)); "And the 6th comparer is the DictionaryComparison" .And(() => result.Comparisons[5].ShouldBeTypeOf <ListComparison>()); "... and the inner comparer is the result" .And(() => ((ListComparison)result.Comparisons[5]).Inner.ShouldBeSameAs(result)); "And the 7th comparer is the ComplexObjectComparison" .And(() => result.Comparisons[6].ShouldBeTypeOf <ComplexObjectComparison>()); "... and the inner comparer is the result" .And(() => ((ComplexObjectComparison)result.Comparisons[6]).Inner.ShouldBeSameAs(result)); "... and IgnoreUnmatchedProperties should be false" .And(() => ((ComplexObjectComparison)result.Comparisons[6]).IgnoreUnmatchedProperties.ShouldBe(false)); }
public void Expoising_internals_of_a_given_type() { var result = default (ComparisonBuilder); var properties = default (PropertyReader[]); "Given a builder" .Given(() => SUT = new ComparisonBuilder()); "When exposing the internals of Version" .When(() => result = SUT.ExposeInternalsOf<Version>()) .And("", () => properties = ReflectionCache.GetProperties(new Version(1, 2, 3, 4))); "Then ReflectionCache should contain the private properties of Version" .Then(() => properties.ShouldContain(x => x.Name == "_Major")); "And it should return the builder" .And(() => result.ShouldBeSameAs(SUT)); }
public static bool IsDeepEqual(this object actual, object expected, bool recursionProtection = true) { var comparison = new ComparisonBuilder().Create(); return(IsDeepEqual(actual, expected, comparison, recursionProtection)); }