public Task ExecuteAsync(
            PostId newPostId,
            ChannelId channelId,
            ValidComment content,
            DateTime?sheduledPostDate,
            QueueId queueId,
            ValidPreviewText previewText,
            FileId previewImageId,
            IReadOnlyList <FileId> fileIds,
            int previewWordCount,
            int wordCount,
            int imageCount,
            int fileCount,
            int videoCount,
            DateTime now)
        {
            newPostId.AssertNotNull("newPostId");
            content.AssertNotNull("content");
            channelId.AssertNotNull("channelId");

            var post = new Post(
                newPostId.Value,
                channelId.Value,
                null,
                queueId == null ? (Guid?)null : queueId.Value,
                null,
                previewImageId == null ? (Guid?)null : previewImageId.Value,
                null,
                previewText == null ? null : previewText.Value,
                content.Value,
                previewWordCount,
                wordCount,
                imageCount,
                fileCount,
                videoCount,
                default(DateTime), // Live date assigned by sub-statements.
                now);

            var postFiles = fileIds.EmptyIfNull().Select(v => new PostFile(newPostId.Value, v.Value)).ToList();

            if (queueId != null)
            {
                return(this.subStatements.QueuePostAsync(post, postFiles));
            }

            return(this.subStatements.SchedulePostAsync(post, postFiles, sheduledPostDate, now));
        }
Exemplo n.º 2
0
        public async Task WhenPostingComment_ItShouldIssuePostCommentCommand()
        {
            var commentId = CommentId.Random();
            var content   = ValidComment.Parse("This is a valid comment");
            var timestamp = DateTime.UtcNow;

            this.guidCreator.Setup(v => v.CreateSqlSequential()).Returns(commentId.Value);
            this.timestampCreator.Setup(v => v.Now()).Returns(timestamp);
            this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester);
            this.postComment.Setup(v => v.HandleAsync(new CommentOnPostCommand(Requester, PostId, commentId, content, timestamp)))
            .Returns(Task.FromResult(0))
            .Verifiable();

            await this.target.PostComment(PostId.Value.EncodeGuid(), new CommentData(content.Value));

            this.postComment.Verify();
        }
Exemplo n.º 3
0
        public async Task WhenPostingFeedback_ItShouldIssueSubmitFeedbackCommand()
        {
            var requester = Requester.Authenticated(UserId.Random());

            this.requesterContext.Setup(v => v.GetRequesterAsync()).ReturnsAsync(requester);

            var registration = NewFeedbackData();
            var command      = new SubmitFeedbackCommand(
                requester,
                ValidComment.Parse(registration.Message));

            this.registerInterest.Setup(v => v.HandleAsync(command)).Returns(Task.FromResult(0));

            var result = await this.controller.PostFeedbackAsync(registration);

            Assert.IsInstanceOfType(result, typeof(OkResult));
            this.registerInterest.Verify(v => v.HandleAsync(command));
        }
Exemplo n.º 4
0
        public async Task ExecuteAsync(
            PostId postId,
            ValidComment content,
            ValidPreviewText previewText,
            FileId previewImageId,
            IReadOnlyList <FileId> fileIds,
            int previewWordCount,
            int wordCount,
            int imageCount,
            int fileCount,
            int videoCount)
        {
            postId.AssertNotNull("postId");
            fileIds.AssertNotNull("fileIds");

            var post = new Post(postId.Value)
            {
                // QueueId = command.QueueId.Value, - Removed as this would require a queue defragmentation if post is already queued. Unnecessary complexity for MVP.
                PreviewText      = previewText == null ? null : previewText.Value,
                PreviewImageId   = previewImageId == null ? (Guid?)null : previewImageId.Value,
                Content          = content == null ? null : content.Value,
                PreviewWordCount = previewWordCount,
                WordCount        = wordCount,
                ImageCount       = imageCount,
                FileCount        = fileCount,
                VideoCount       = videoCount
            };

            var postFiles = fileIds.Select(v => new PostFile(postId.Value, v.Value)).ToList();

            using (var transaction = TransactionScopeBuilder.CreateAsync())
            {
                using (var connection = this.connectionFactory.CreateConnection())
                {
                    // The order we access tables should match PostToChannelDbStatement.
                    var rowsUpdated = await connection.UpdateAsync(
                        post,
                        Post.Fields.PreviewText
                        | Post.Fields.PreviewImageId
                        | Post.Fields.Content
                        | Post.Fields.PreviewWordCount
                        | Post.Fields.WordCount
                        | Post.Fields.ImageCount
                        | Post.Fields.FileCount
                        | Post.Fields.VideoCount);

                    if (rowsUpdated > 0)
                    {
                        await connection.ExecuteAsync(
                            DeleteQuery,
                            new { PostId = postId.Value });

                        if (fileIds.Count > 0)
                        {
                            await connection.InsertAsync(postFiles);
                        }
                    }
                }

                transaction.Complete();
            }
        }