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_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_NotificationStorageFailed_ThrowsInvalidOperationException() { // Arrange NotificationStorage .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification)) .ReturnsAsync(false); // Act await Target.Value.SendAsync(DispatchedNotification, CancellationToken).ShouldThrowAsync <InvalidOperationException>(); }
public async Task SendAsync_FailedNotification_SendsToStorage() { // Arrange NotificationStorage .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification)) .ReturnsAsync(true) .Verifiable(); // Act await Target.Value.SendAsync(FailedNotification, CancellationToken); // Assert NotificationStorage.Verify(); }
public async Task ProcessMessageAsync_ValidMessageFailedNotification_ReturnsNotification() { // Arrange NotificationStorage .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>())) .ReturnsAsync(true); // Act var notificationTask = Target.Value.ProcessMessageAsync(TextMessage, WaitUntilEvent, CancellationToken); await Target.Value.SendAsync(AcceptedNotification, CancellationToken); await Target.Value.SendAsync(FailedNotification, CancellationToken); // Assert var actual = await notificationTask; actual.ShouldBe(FailedNotification); }
public async Task ProcessCommandAsync_ValidCommand_ReturnsResponse() { // Arrange NotificationStorage .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>())) .ReturnsAsync(true); // Act var commandTask = Target.Value.ProcessCommandAsync(PresenceRequestCommand, CancellationToken); await Target.Value.SendAsync(PresenceResponseCommand, CancellationToken); // Assert var actual = await commandTask; actual.ShouldBe(PresenceResponseCommand); // Check for the removal of the pending notification NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Never()); await Target.Value.SendAsync(DispatchedNotification, CancellationToken); NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Once()); }
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()); }
public async Task ProcessMessageAsync_ValidMessage_ReturnsNotification() { // Arrange NotificationStorage .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>())) .ReturnsAsync(true); // Act var notificationTask = Target.Value.ProcessMessageAsync(TextMessage, WaitUntilEvent, CancellationToken); await Target.Value.SendAsync(AcceptedNotification, CancellationToken); await Target.Value.SendAsync(DispatchedNotification, CancellationToken); // Assert var actual = await notificationTask; actual.ShouldBe(DispatchedNotification); // Check for the removal of the pending notification NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Never()); await Target.Value.SendAsync(DispatchedNotification, CancellationToken); NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Once()); }