Skip to content

Instantly share code, notes, and snippets.

@bitbonk
Last active February 5, 2016 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitbonk/4b8d8ae69c57db5f5fc1 to your computer and use it in GitHub Desktop.
Save bitbonk/4b8d8ae69c57db5f5fc1 to your computer and use it in GitHub Desktop.
slow assertion
// The Property Culture is of type CultureInfo
enumarableOfComplexObject.ShouldAllBeEquivalentTo(
new[]
{
new { RefText = "Ref1", Culture = Invariant, Text = "Ref1 en", Component = string.Empty },
new { RefText = "Ref3", Culture = Invariant, Text = "Ref3 en", Component = string.Empty },
new { RefText = "Ref1", Culture = German, Text = "Ref1 de", Component = string.Empty },
new { RefText = "Ref3", Culture = German, Text = "Ref3 de", Component = string.Empty },
new { RefText = "Ref1", Culture = English, Text = "Ref1 en", Component = string.Empty },
new { RefText = "Ref3", Culture = English, Text = "Ref3 en", Component = string.Empty },
new { RefText = "Ref1", Culture = GermanGermany, Text = "Ref1 de", Component = string.Empty },
new { RefText = "Ref3", Culture = GermanGermany, Text = "Ref3 de", Component = string.Empty },
new { RefText = "Ref1", Culture = EnglishUs, Text = "Ref1 en", Component = string.Empty },
new { RefText = "Ref3", Culture = EnglishUs, Text = "Ref3 en", Component = string.Empty },
new { RefText = "Ref1", Culture = Invariant, Text = "Ref1 en", Component = "Comp1" },
new { RefText = "Ref3", Culture = Invariant, Text = "Ref3 en", Component = "Comp1" },
new { RefText = "Ref1", Culture = EnglishUs, Text = "Ref1 en", Component = "Comp1" },
new { RefText = "Ref3", Culture = EnglishUs, Text = "Ref3 en", Component = "Comp1" }
},
o => o.ExcludingMissingMembers().ComparingByValue<CultureInfo>());
@bitbonk
Copy link
Author

bitbonk commented Feb 5, 2016

This is what the performance profiler says. Its a deep recursion. Could it be the CultureInfo instances? Is it not comparing them by value as it should? CultureInfo has a deeply nested structure, I think.
capture

@dennisdoomen
Copy link

I would have to analyze it myself. The comparison is trying to some smart things when comparing collections though.

@bitbonk
Copy link
Author

bitbonk commented Feb 5, 2016

Interesting:

o => o.ExcludingMissingMembers().ExcludingNestedObjects() makes it fast and it asserts correctly (but I would have preferred .ComparingByValue<CultureInfo>());

Even more interesting (this looks like a bug to me):

o => o.Including(t => t.Culture)); will never fail, even if the cutltures differ!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment