Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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());
        }