public async Task TeamsConversationOrchestrator_NoRecipients_ShouldNotInvokeTeamsConversationActivity()
        {
            // Arrange
            string notificationId = "notificationId:1";
            IEnumerable <SentNotificationDataEntity> notification = new List <SentNotificationDataEntity>();

            this.mockContext
            .Setup(x => x.GetInput <string>())
            .Returns(notificationId);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <string>()))
            .ReturnsAsync(notification);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask);

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

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

            this.mockContext.Verify(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.Is <string>(x => x.Equals(FunctionNames.GetPendingRecipientsActivity)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Once);
            this.mockContext.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.TeamsConversationActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Never);
        }
        public async Task TeamsConversationRunOrchestratorTest()
        {
            // Arrange
            string batchPartitionKey = "notificationId:1";
            IEnumerable <SentNotificationDataEntity> recipients = new List <SentNotificationDataEntity>()
            {
                new SentNotificationDataEntity()
                {
                    ConversationId = "conversationId1", PartitionKey = batchPartitionKey
                },

                new SentNotificationDataEntity()
                {
                    ConversationId = "conversationId2", PartitionKey = batchPartitionKey
                },
            };

            var notificationId = PartitionKeyUtility.GetNotificationIdFromBatchPartitionKey(batchPartitionKey);

            this.mockContext
            .Setup(x => x.GetInput <string>())
            .Returns(batchPartitionKey);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <string>()))
            .ReturnsAsync(recipients);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask);

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

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

            this.mockContext.Verify(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.Is <string>(x => x.Equals(FunctionNames.GetPendingRecipientsActivity)), It.IsAny <RetryOptions>(), It.IsAny <string>()), Times.Once);
            this.mockContext
            .Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.TeamsConversationActivity)), It.IsAny <RetryOptions>(), It.Is <(string notificationId, string batchPartitionKey, SentNotificationDataEntity recipients)>(x => x.recipients.PartitionKey.Equals(notificationId))), Times.Exactly(recipients.Count()));
        }
Exemplo n.º 3
0
        public async Task TeamsConversationRunOrchestratorTest()
        {
            // Arrange
            NotificationDataEntity notificationDataEntity = new NotificationDataEntity()
            {
                Id = "notificationId",
            };
            IEnumerable <SentNotificationDataEntity> notification = new List <SentNotificationDataEntity>()
            {
                new SentNotificationDataEntity()
                {
                    ConversationId = "conversationId1"
                },

                new SentNotificationDataEntity()
                {
                    ConversationId = "conversationId2"
                },
            };

            this.mockContext
            .Setup(x => x.GetInput <NotificationDataEntity>())
            .Returns(notificationDataEntity);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()))
            .ReturnsAsync(notification);
            this.mockContext
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask);

            // Act
            Func <Task> task = async() => await TeamsConversationOrchestrator.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.TeamsConversationActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Exactly(notification.Count()));
        }