public async Task PrepareToSendOrchestratorSuccessWithReplayingFlagTrueTest()
        {
            // Arrange
            Mock <NotificationDataEntity> mockNotificationDataEntity = new Mock <NotificationDataEntity>();
            NotificationDataEntity        notificationDataEntity     = new NotificationDataEntity()
            {
                Id = "notificationId",
            };

            this.mockContext
            .Setup(x => x.IsReplaying)
            .Returns(true);

            this.mockContext
            .Setup(x => x.GetInput <NotificationDataEntity>())
            .Returns(notificationDataEntity);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Returns(Task.CompletedTask);
            this.mockContext
            .Setup(x => x.CallSubOrchestratorWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Returns(Task.CompletedTask);

            // Act
            Func <Task> task = async() => await PrepareToSendOrchestrator.RunOrchestrator(this.mockContext.Object, this.mockLogger.Object);

            // Assert
            await task.Should().NotThrowAsync <Exception>();

            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.StoreMessageActivity)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SyncRecipientsOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.TeamsConversationOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SendQueueOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
        }
Example #2
0
        public async Task PrepareToSendOrchestratorSuccessTest()
        {
            // Arrange
            Mock <NotificationDataEntity> mockNotificationDataEntity = new Mock <NotificationDataEntity>();
            NotificationDataEntity        notificationDataEntity     = new NotificationDataEntity()
            {
                Id = "123",
            };
            var recipientsInfo = new RecipientsInfo(notificationDataEntity.Id)
            {
                HasRecipientsPendingInstallation = true,
            };

            recipientsInfo.BatchKeys.Add("batchKey");

            this.mockContext
            .Setup(x => x.IsReplaying)
            .Returns(false);
            this.mockContext
            .Setup(x => x.GetInput <NotificationDataEntity>())
            .Returns(notificationDataEntity);

            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Returns(Task.CompletedTask);
            this.mockContext
            .Setup(x => x.CallSubOrchestratorWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Returns(Task.CompletedTask);
            this.mockContext
            .Setup(x => x.CallSubOrchestratorWithRetryAsync <RecipientsInfo>(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .ReturnsAsync(recipientsInfo);

            // Act
            Func <Task> task = async() => await PrepareToSendOrchestrator.RunOrchestrator(this.mockContext.Object, this.mockLogger.Object);

            // Assert
            await task.Should().NotThrowAsync <Exception>();

            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.StoreMessageActivity)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.UpdateNotificationStatusActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Exactly(2));
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.DataAggregationTriggerActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.HandleFailureActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Never);
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync <RecipientsInfo>(It.Is <string>(x => x.Equals(FunctionNames.SyncRecipientsOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.TeamsConversationOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Exactly(recipientsInfo.BatchKeys.Count));
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SendQueueOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Exactly(recipientsInfo.BatchKeys.Count));
        }
Example #3
0
        public async Task PrepareToSendOrchestration_ExceptionThrownFromInvokedActivity_ShouldInvokeHandleFailureActivity()
        {
            // Arrange
            Mock <NotificationDataEntity> mockNotificationDataEntity = new Mock <NotificationDataEntity>();
            NotificationDataEntity        notificationDataEntity     = new NotificationDataEntity()
            {
                Id = "123",
            };
            RecipientsInfo recipientsInfo = default;

            this.mockContext
            .Setup(x => x.IsReplaying)
            .Returns(false);
            this.mockContext
            .Setup(x => x.GetInput <NotificationDataEntity>())
            .Returns(notificationDataEntity);

            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Throws(new Exception());
            this.mockContext
            .Setup(x => x.CallSubOrchestratorWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .Returns(Task.CompletedTask);
            this.mockContext
            .Setup(x => x.CallSubOrchestratorWithRetryAsync <RecipientsInfo>(It.IsAny <string>(), It.IsAny <RetryOptions>(), notificationDataEntity))
            .ReturnsAsync(recipientsInfo);

            // Act
            Func <Task> task = async() => await PrepareToSendOrchestrator.RunOrchestrator(this.mockContext.Object, this.mockLogger.Object);

            // Assert
            await task.Should().NotThrowAsync <Exception>();

            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.StoreMessageActivity)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Once());
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.UpdateNotificationStatusActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Never);
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.DataAggregationTriggerActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Never);
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.HandleFailureActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once);
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync <RecipientsInfo>(It.Is <string>(x => x.Equals(FunctionNames.SyncRecipientsOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()), Times.Never);
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.TeamsConversationOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Never);
            this.mockContext.Verify(x => x.CallSubOrchestratorWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SendQueueOrchestrator)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Never());
        }