public async Task HandleAsync_succeeds() { var queue = Mock.Of <IBackgroundHandleProxyQueue>(); var handler = new BackgroundNotificationHandler <Notification>(queue, new NotificationHandler()); Task handleTask = handler.HandleAsync(new Notification()); await handleTask; handleTask.IsCompleted.Should().BeTrue(); Mock.Get(queue) .Verify(w => w.EnqueueAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>()), Times.Once()); }
public async Task HandleAsync_succeeds() { var channelWriter = Mock.Of <ChannelWriter <HandleProxy> >(); var handler = new BackgroundNotificationHandler <Notification>(channelWriter, new NotificationHandler()); Task handleTask = handler.HandleAsync(new Notification()); await handleTask; handleTask.IsCompleted.Should().BeTrue(); Mock.Get(channelWriter) .Verify(w => w.WriteAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>()), Times.Once()); }
public void HandleAsync_throws_when_enqueue_fails() { var queue = Mock.Of <IBackgroundHandleProxyQueue>(); Mock.Get(queue) .Setup(w => w.EnqueueAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>())) .Throws(new InvalidOperationException("failed")); var handler = new BackgroundNotificationHandler <Notification>(queue, new NotificationHandler()); Func <Task> handleTask = () => handler.HandleAsync(new Notification()); handleTask.Should().ThrowAsync <InvalidOperationException>(); Mock.Get(queue) .Verify(w => w.EnqueueAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>()), Times.Once()); }
public void HandleAsync_throws_when_write_fails() { var channelWriter = Mock.Of <ChannelWriter <HandleProxy> >(); Mock.Get(channelWriter) .Setup(w => w.WriteAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>())) .Throws(new InvalidOperationException("failed")); var handler = new BackgroundNotificationHandler <Notification>(channelWriter, new NotificationHandler()); Func <Task> handleTask = () => handler.HandleAsync(new Notification()); handleTask.Should().ThrowAsync <InvalidOperationException>(); Mock.Get(channelWriter) .Verify(w => w.WriteAsync(It.IsAny <HandleProxy>(), It.IsAny <CancellationToken>()), Times.Once()); }