Skip to content

Instantly share code, notes, and snippets.

@adamralph
Last active August 29, 2015 14:02
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 adamralph/ac0deea6448da5a93359 to your computer and use it in GitHub Desktop.
Save adamralph/ac0deea6448da5a93359 to your computer and use it in GitHub Desktop.
FluentAssertions enumerable assertion
IEnumerable<Foo> foos;
foos.Should().All(foo => foo.Bar.Should().Be("baz"));
// if an item does not satisfy the inner assertion, I'd like to be told which one.
// perhaps I could be told the index, and maybe a string representation of the item
@dennisdoomen
Copy link

What about this?

foos.Should().OnlyContain(foo => foo.Bar == "baz");

@adamralph
Copy link
Author

I've done that for simple cases, but in other cases, I want to do more than just an equality comparison. I'd like to use some of the much richer assertions that FluentAssertions provides.

@dennisdoomen
Copy link

So you essentially want to have some kind of nested assertions? If so, I think we can do that using the AssertionScope and the CollectingAssertionStrategy. Can you create a request on the FA for that?

@adamralph
Copy link
Author

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