Skip to content

Instantly share code, notes, and snippets.

@ssboisen
Created February 21, 2012 17:49
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 ssboisen/1877672 to your computer and use it in GitHub Desktop.
Save ssboisen/1877672 to your computer and use it in GitHub Desktop.
public static void ShouldBeStructurallyEqualTo<T, U>(this IEnumerable<T> actual, IEnumerable<U> expected)
{
var actualList = actual.ToList();
var expectedList = expected.ToList();
actualList.Should().HaveCount(expectedList.Count());
bool isArrayOfValueType = typeof (T).IsArray && typeof (T).GetElementType().IsValueType;
foreach (var pair in actualList.Zip(expectedList, Tuple.Create))
{
if (isArrayOfValueType)
(pair.Item1 as IEnumerable).Should().BeEquivalentTo(pair.Item2 as IEnumerable);
else
pair.Item1.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(pair.Item2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment