I'm trying to assert an exception which happens in an async method.
Unfortunately, the assertion doesn't work.
I've made sure via debugging, that the throw new Exception(...)
is called in the SaveCategoriesAsync(...)
method.
The method with the Action
normally works for unit tests... but it seems that it doesn't work with async.
I'm using FakeItEasy as mocking framework and FluentAssertions as assertion framework.
[TestMethod]
public void SaveCategoriesAsync_When_Then()
{
A.CallTo(() => this.articleRepository.GetArticles(A<IList<long>>._)).Returns(new List<ArticleModel>());
Action action = async () => await this.testee.SaveCategoriesAsync(new List<int>());
action.ShouldThrow<Exception>();
}
What do I have to change to be able to assert the exception?
Thanks in advance