public async Task <ActionResult> PreviewDraftNotificationAsync(
            [FromBody] DraftNotificationPreviewRequest draftNotificationPreviewRequest)
        {
            if (draftNotificationPreviewRequest == null ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.DraftNotificationId) ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.TeamsTeamId) ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.TeamsChannelId))
            {
                return(this.BadRequest());
            }

            var notificationEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.DraftNotificationsPartition,
                draftNotificationPreviewRequest.DraftNotificationId);

            if (notificationEntity == null)
            {
                return(this.BadRequest($"Notification {draftNotificationPreviewRequest.DraftNotificationId} not found."));
            }

            var teamDataEntity = new TeamDataEntity();

            teamDataEntity.TenantId   = this.HttpContext.User.FindFirstValue(Common.Constants.ClaimTypeTenantId);
            teamDataEntity.ServiceUrl = await this.appSettingsService.GetServiceUrlAsync();

            var result = await this.draftNotificationPreviewService.SendPreview(
                notificationEntity,
                teamDataEntity,
                draftNotificationPreviewRequest.TeamsChannelId);

            return(this.StatusCode((int)result));
        }
        public async Task PreviewDraft_InvalidInput_ReturnsBadRequest(DraftNotificationPreviewRequest draftNotificationPreviewRequest, string draftNotificationId, string teamsTeamId, string teamsChannelId)
        {
            // Arrange
            if (draftNotificationPreviewRequest != null)
            {
                draftNotificationPreviewRequest.DraftNotificationId = draftNotificationId;
                draftNotificationPreviewRequest.TeamsTeamId         = teamsTeamId;
                draftNotificationPreviewRequest.TeamsChannelId      = teamsChannelId;
            }

            var controller = this.GetDraftNotificationsController();

            // Act
            var result = await controller.PreviewDraftNotificationAsync(draftNotificationPreviewRequest);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Example #3
0
        public async Task <ActionResult> PreviewDraftNotificationAsync(
            [FromBody] DraftNotificationPreviewRequest draftNotificationPreviewRequest)
        {
            if (draftNotificationPreviewRequest == null ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.DraftNotificationId) ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.TeamsTeamId) ||
                string.IsNullOrWhiteSpace(draftNotificationPreviewRequest.TeamsChannelId))
            {
                return(this.BadRequest());
            }

            var notificationEntity = await this.notificationDataRepository.GetAsync(
                NotificationDataTableNames.DraftNotificationsPartition,
                draftNotificationPreviewRequest.DraftNotificationId);

            if (notificationEntity == null)
            {
                return(this.BadRequest($"Notification {draftNotificationPreviewRequest.DraftNotificationId} not found."));
            }

            var teamDataEntity = await this.teamDataRepository.GetAsync(
                TeamDataTableNames.TeamDataPartition,
                draftNotificationPreviewRequest.TeamsTeamId);

            if (teamDataEntity == null)
            {
                return(this.BadRequest($"Team {draftNotificationPreviewRequest.TeamsTeamId} not found."));
            }

            var result = await this.draftNotificationPreviewService.SendPreview(
                notificationEntity,
                teamDataEntity,
                draftNotificationPreviewRequest.TeamsChannelId);

            return(this.StatusCode((int)result));
        }