public async Task RunOrchestratorTest()
        {
            // Arrange
            var durableOrchestrationContextMock = new Mock <IDurableOrchestrationContext>();
            var mockLogger = new Mock <ILogger>();

            NotificationDataEntity notificationDataEntity = new NotificationDataEntity()
            {
                Id = "notificationId",
            };

            IEnumerable <SentNotificationDataEntity> sentNotificationDataEntitiesList = new List <SentNotificationDataEntity>();

            List <SentNotificationDataEntity> datalist = new List <SentNotificationDataEntity>();

            for (int i = 0; i <= 100; i++)
            {
                datalist.Add(new SentNotificationDataEntity());
            }

            sentNotificationDataEntitiesList = datalist;
            durableOrchestrationContextMock
            .Setup(x => x.GetInput <NotificationDataEntity>())
            .Returns(notificationDataEntity);

            durableOrchestrationContextMock
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask);

            durableOrchestrationContextMock
            .Setup(x => x.CallActivityWithRetryAsync <(IEnumerable <SentNotificationDataEntity>, TableContinuationToken)>(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <NotificationDataEntity>()))
            .ReturnsAsync((sentNotificationDataEntitiesList, new TableContinuationToken()));

            // Act
            Func <Task> task = async() => await SendQueueOrchestrator.RunOrchestrator(durableOrchestrationContextMock.Object, mockLogger.Object);

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

            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.UpdateNotificationStatusActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync <(IEnumerable <SentNotificationDataEntity>, TableContinuationToken)>(It.Is <string>(x => x.Equals(FunctionNames.GetRecipientsActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync <(IEnumerable <SentNotificationDataEntity>, TableContinuationToken)>(It.Is <string>(x => x.Equals(FunctionNames.GetRecipientsByTokenActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.DataAggregationTriggerActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SendBatchMessagesActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.AtLeast(1));
        }
Esempio n. 2
0
        public async Task RunOrchestratorTest()
        {
            // Arrange
            var    durableOrchestrationContextMock = new Mock <IDurableOrchestrationContext>();
            var    mockLogger        = new Mock <ILogger>();
            string batchPartitionKey = "1234:1";

            var recipients = new List <SentNotificationDataEntity>();

            for (int i = 0; i <= 100; i++)
            {
                recipients.Add(new SentNotificationDataEntity());
            }

            durableOrchestrationContextMock
            .Setup(x => x.GetInput <string>())
            .Returns(batchPartitionKey);

            durableOrchestrationContextMock
            .Setup(x => x.CallActivityWithRetryAsync(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask);

            durableOrchestrationContextMock
            .Setup(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.IsAny <string>(), It.IsAny <RetryOptions>(), It.IsAny <string>()))
            .ReturnsAsync(recipients);

            var totalBatchesCount = recipients.AsBatches(SendQueue.MaxNumberOfMessagesInBatchRequest).ToList().Count;

            // Act
            Func <Task> task = async() => await SendQueueOrchestrator.RunOrchestrator(durableOrchestrationContextMock.Object, mockLogger.Object);

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

            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync <IEnumerable <SentNotificationDataEntity> >(It.Is <string>(x => x.Equals(FunctionNames.GetRecipientsActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Once());
            durableOrchestrationContextMock.Verify(x => x.CallActivityWithRetryAsync(It.Is <string>(x => x.Equals(FunctionNames.SendBatchMessagesActivity)), It.IsAny <RetryOptions>(), It.IsAny <object>()), Times.Exactly(totalBatchesCount));
        }