Assert.ThrowsExceptionAsync isn't working
What is the correct way to use Assert.ThrowsExceptionAsync?
You're not calling ThrowsExceptionAsync
. You're calling ThrowsException
. The proper way to call ThrowsExceptionAsync
is to await
its result.
This should work:
public async Task GetPlaylistByIdAsync_NonExistingPlaylist_ThrowsPlaylistNotFoundException()
{
var playlistId = Guid.NewGuid().ToString();
var manager = PlaylistTargetsFakeFactory.GetPlaylistTargetFusionManager();
await Assert.ThrowsExceptionAsync<PlaylistNotFoundException>(async () =>
{
await manager.GetPlaylistByIdAsync(playlistId);
});
}
or, more simply:
await Assert.ThrowsExceptionAsync<PlaylistNotFoundException>(() =>
manager.GetPlaylistByIdAsync(playlistId));