public async Task SendAsync_OrderedNotificationsUpdateFailed_ThrowsInvalidOperationException() { // Arrange NotificationStorage .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification)) .ReturnsAsync(false) .Verifiable(); NotificationStorage .Setup(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), DispatchedNotification.Id)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .SetupSequence(m => m.GetEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification.Id)) .Returns(Task.FromResult <Notification>(null)) .Returns(Task.FromResult <Notification>(DispatchedNotification)); // Act await Target.Value.SendAsync(DispatchedNotification, CancellationToken); await Target.Value.SendAsync(FailedNotification, CancellationToken).ShouldThrowAsync <InvalidOperationException>(); }
public async Task SendAsync_OrderedNotifications_UpdatesOnStorage() { // Arrange NotificationStorage .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .Setup(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), DispatchedNotification.Id)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .SetupSequence(m => m.GetEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification.Id)) .Returns(Task.FromResult <Notification>(null)) .Returns(Task.FromResult <Notification>(DispatchedNotification)); // Act await Target.Value.SendAsync(DispatchedNotification, CancellationToken); await Target.Value.SendAsync(FailedNotification, CancellationToken); // Assert NotificationStorage.Verify(); }
public async Task SendAsync_UnorderedNotificationsWithFailed_KeepsTheLastestOnStorage() { // Arrange NotificationStorage .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification)) .ReturnsAsync(true) .Verifiable(); NotificationStorage .SetupSequence(m => m.GetEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification.Id)) .Returns(Task.FromResult <Notification>(null)) .Returns(Task.FromResult <Notification>(FailedNotification)); // Act await Target.Value.SendAsync(FailedNotification, CancellationToken); await Target.Value.SendAsync(AcceptedNotification, CancellationToken); // Assert NotificationStorage.Verify(); NotificationStorage.Verify(m => m.StoreEnvelopeAsync(AcceptedNotification.To.ToIdentity(), AcceptedNotification), Times.Never()); NotificationStorage.Verify(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification.Id), Times.Never()); }