Exemplo n.º 1
0
        public async Task RunAsync(
            [ActivityTrigger] NotificationDataEntity notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var templateID          = notification.TemplateID;
            var templateDataforcard = await this.templateDataRepository.GetAsync("Default", templateID);

            var serializedContent = string.Empty;

            serializedContent = this.adaptiveCardCreator.CreateAdaptiveCardWithoutHeader(notification, templateDataforcard.TemplateJSON);

            var sendingNotification = new SendingNotificationDataEntity
            {
                PartitionKey   = NotificationDataTableNames.SendingNotificationsPartition,
                RowKey         = notification.RowKey,
                NotificationId = notification.Id,
                Channel        = notification.Channel,
                TemplateID     = notification.TemplateID,
                Content        = serializedContent,
            };

            await this.sendingNotificationDataRepository.CreateOrUpdateAsync(sendingNotification);
        }
        /// <summary>
        /// Generate an adaptive card in json.
        /// </summary>
        /// <param name="rowKey">The row key.</param>
        /// <param name="notificationEntity">The notification entity to create as a draft.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        public async Task CreateAsync(string rowKey, NotificationDataEntity notificationEntity)
        {
            var cardString = this.adaptiveCardCreator.CreateAdaptiveCard(notificationEntity, rowKey).ToJson();

            var sendingNotification = new SendingNotificationDataEntity
            {
                PartitionKey   = PartitionKeyNames.NotificationDataTable.SendingNotificationsPartition,
                RowKey         = rowKey,
                NotificationId = rowKey,
                Content        = cardString,
            };

            await this.sendingNotificationDataRepository.CreateOrUpdateAsync(sendingNotification);
        }
        public async Task RunAsync(
            [ActivityTrigger] NotificationDataEntity notification)
        {
            var serializedContent = this.adaptiveCardCreator.CreateAdaptiveCard(notification).ToJson();

            var sendingNotification = new SendingNotificationDataEntity
            {
                PartitionKey   = NotificationDataTableNames.SendingNotificationsPartition,
                RowKey         = notification.RowKey,
                NotificationId = notification.Id,
                Content        = serializedContent,
            };

            await this.sendingNotificationDataRepository.CreateOrUpdateAsync(sendingNotification);
        }
        public async Task CreateSendingNotificationAsync(
            [ActivityTrigger] NotificationDataEntity notificationDataEntity)
        {
            var cardString = this.adaptiveCardCreator.CreateAdaptiveCard(notificationDataEntity).ToJson();

            var sendingNotification = new SendingNotificationDataEntity
            {
                PartitionKey   = NotificationDataTableNames.SendingNotificationsPartition,
                RowKey         = notificationDataEntity.RowKey,
                NotificationId = notificationDataEntity.RowKey,
                Content        = cardString,
            };

            await this.sendingNotificationDataRepository.CreateOrUpdateAsync(sendingNotification);
        }
        public async Task SendNotificationResponseThrottledTest()
        {
            // Arrange
            var sendFunctionInstance = this.GetSendFunction();
            SendMessageResponse sendMessageResponse = new SendMessageResponse()
            {
                ResultType = SendMessageResult.Throttled,
            };
            string data = "{\"NotificationId\":\"notificationId\",\"RecipientData\": {\"RecipientId\" : \"TestResp\", \"UserData\": { \"UserId\" : \"userId\",\"ConversationId\":\"conversationId\",\"UserType\":\"Member\"}}}";
            SendQueueMessageContent messageContent = JsonConvert.DeserializeObject <SendQueueMessageContent>(data);

            this.notificationService
            .Setup(x => x.IsPendingNotification(It.IsAny <SendQueueMessageContent>()))
            .ReturnsAsync(true);
            this.notificationService
            .Setup(x => x.UpdateSentNotification(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            this.notificationService
            .Setup(x => x.IsSendNotificationThrottled())
            .ReturnsAsync(false);
            this.sendQueue
            .Setup(x => x.SendDelayedAsync(It.IsAny <SendQueueMessageContent>(), It.IsAny <double>()))
            .Returns(Task.CompletedTask);

            var notificatioData = new SendingNotificationDataEntity()
            {
                Content = "{\"text\":\"Welcome\",\"displayText\":\"Hello\"}"
            };

            this.notificationRepo.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(notificatioData);
            this.messageService.Setup(x => x.SendMessageAsync(It.IsAny <IMessageActivity>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), this.logger.Object)).ReturnsAsync(sendMessageResponse);
            this.notificationService.Setup(x => x.UpdateSentNotification(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.CompletedTask);

            // Act
            Func <Task> task = async() => await sendFunctionInstance.Run(data, this.deliveryCount, this.dateTime, string.Empty, this.logger.Object, new ExecutionContext());

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

            this.sendQueue.Verify(x => x.SendDelayedAsync(It.IsAny <SendQueueMessageContent>(), It.IsAny <double>()));
        }