Wednesday, 14 August 2013

FluentAssertiions ShouldNotThrow is not recognised for an async method/Func

FluentAssertiions ShouldNotThrow is not recognised for an async method/Func

I am trying to check an async method throws concrete exception.
For that I am using MSTEST and FluentAssertions 2.0.1.
I have checked this one to see how work with async-exception methods:
https://fluentassertions.codeplex.com/SourceControl/changeset/view/c1bc29ff258e622fac71730955bd1ea066880874#Main/FluentAssertions.Net45.Specs/AsyncFunctionExceptionAssertionSpecs.cs
After a while trying to work with my 'production' code I have switched off
to the Fluentassertions fake aync class and my resulting code is like this
(put this code inside a [TestClass]:
[TestMethod]
public void TestThrowFromAsyncMethod()
{
var asyncObject = new AsyncClass();
Action action = () =>
{
Func<Task> asyncFunction = async () =>
{
await asyncObject.ThrowAsync<ArgumentException>();
};
asyncFunction.ShouldNotThrow();
};
}
internal class AsyncClass
{
public async Task ThrowAsync<TException>()
where TException : Exception, new()
{
await Task.Factory.StartNew(() =>
{
throw new TException();
});
}
public async Task SucceedAsync()
{
await Task.FromResult(0);
}
}
The problem is that ShouldNotThrow is not valid:
ShouldNotThrow method is not recognised by the code. If I try to compile,
it gives me this error: 'System.Func' does not contain a definition for
'ShouldNotThrow' and the best extension method overload
'FluentAssertions.AssertionExtensions.ShouldNotThrow(System.Action,
string, params object[])' has some invalid arguments

No comments:

Post a Comment