Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Created February 28, 2014 17:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwilson/9276064 to your computer and use it in GitHub Desktop.
Save bradwilson/9276064 to your computer and use it in GitHub Desktop.
Using Expression<T> with data theories for better output display in xUnit.net
public static IEnumerable<object[]> ExpirationMethods
{
get
{
return new TheoryDataSet<Expression<Action<Cache>>>
{
cache => cache.Clock.UtcNow.Returns(BaseTime + cache.Duration),
cache => cache.Expire()
};
}
}
[Theory]
[PropertyData("ExpirationMethods")]
public async void MyTheory(Expression<Action<Cache>> expireMethod)
{
// ...
}
// Yields:
// Test 'MyClass.MyTheory(expireMethod: cache => cache.Expire())' failed:
// NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment