public async Task StartAsync_WorkitemThrowsException_EmailIsSent() { EmailInfo sentEmailInfo = null; A.CallTo(() => _mailService.SendAsync(A <EmailInfo> ._)).Invokes(invocation => sentEmailInfo = invocation.GetArgument <EmailInfo>(0)); var backgroundTaskQueue = _container.Resolve <IBackgroundTaskQueue>(); backgroundTaskQueue.QueueBackgroundWorkItem((factory, token) => throw new ApplicationException("Error!!")); while (!backgroundTaskQueue.IsQueueEmpty()) { await Task.Delay(200); } sentEmailInfo.Should().NotBeNull(); sentEmailInfo.Subject.Should().Be("[DEVELOPMENT] Error occurred while executing queued workitem of application TestApplication"); }