public async Task SafelyHandleErrorAsync_CallsHandlerOnAsyncErrorAsync() { await SafeErrorUtil.SafelyHandleErrorAsync(async () => { await Task.Yield(); throw new TestException(); }, handler); handler.Received().Invoke(Arg.Is<Exception>(e => e is TestException)); }
public async Task SafelyHandleErrorAsync_CallsHandlerOnSynchronousErrorAsync() { // Use a delegate to bypass warning that we don't use await. Func<Task> throwSynchronously = delegate { throw new TestException(); }; await SafeErrorUtil.SafelyHandleErrorAsync(throwSynchronously, handler); handler.Received().Invoke(Arg.Is<Exception>(e => e is TestException)); }
public async Task SafelyHandleErrorAsync_HandlerThrowsAsync() { handler.When(x => x.Invoke(Arg.Any<Exception>())).Throw<HandlerException>(); await SafeErrorUtil.SafelyHandleErrorAsync( () => Task.FromException(new TestException()), handler); }
public async Task SafelyHandleErrorAsync_DoesNotCallHandlerOnSuccessAsync() { await SafeErrorUtil.SafelyHandleErrorAsync(() => Task.CompletedTask, handler); handler.DidNotReceiveWithAnyArgs().Invoke(null); }