Example #1
0
        public async Task <IHttpActionResult> PostReply(string commentHandle, [FromBody] PostReplyRequest request)
        {
            string className  = "CommentRepliesController";
            string methodName = "PostReply";
            string logEntry   = $"CommentHandle = {commentHandle}";

            this.LogControllerStart(this.log, className, methodName, logEntry);

            var commentEntity = await this.commentsManager.ReadComment(commentHandle);

            if (commentEntity == null)
            {
                return(this.NotFound(ResponseStrings.CommentNotFound));
            }

            if (commentEntity.AppHandle != this.AppHandle)
            {
                return(this.Unauthorized(ResponseStrings.NotAllowed));
            }

            string replyHandle = this.handleGenerator.GenerateShortHandle();

            await this.repliesManager.CreateReply(
                ProcessType.Frontend,
                replyHandle,
                request.Text,
                request.Language,
                this.UserHandle,
                commentHandle,
                commentEntity.UserHandle,
                commentEntity.TopicHandle,
                DateTime.UtcNow,
                ReviewStatus.Active,
                this.AppHandle,
                null);

            var response = new PostReplyResponse()
            {
                ReplyHandle = replyHandle
            };

            logEntry += $", ReplyHandle = {replyHandle}";
            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.Created <PostReplyResponse>(new Uri(this.Request.RequestUri.AbsoluteUri + "/" + commentHandle), response));
        }
Example #2
0
        /// <summary>
        /// Create synthetic replies by having each of the supplied users post the given number of replies
        /// on comments chosen randomly with replacement
        /// </summary>
        /// <param name="client">a valid SocialPlusClient</param>
        /// <param name="users">a list of UserInfo objects representing the users who will post comments</param>
        /// <param name="commentHandles">a list of comment handles corresponding to the comments to be replied to</param>
        /// <param name="numRepliesPerUser">the number of replies each user should post</param>
        /// <returns>a list of reply handles for the created replies</returns>
        private static async Task <List <string> > CreateReplies(SocialPlusClient client, List <UserInfo> users, List <string> commentHandles, int numRepliesPerUser)
        {
            List <string> replyHandles = new List <string>();

            for (int userIndex = 0; userIndex < users.Count; userIndex++)
            {
                for (int i = 0; i < numRepliesPerUser; i++)
                {
                    string           commentHandle = commentHandles[GenerateRandomInt(0, commentHandles.Count)];
                    string           text          = "A reply to a comment";
                    PostReplyRequest request       = new PostReplyRequest(text);
                    HttpOperationResponse <PostReplyResponse> response = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle, request, users[userIndex].BearerToken);

                    replyHandles.Add(response.Body.ReplyHandle);
                }
            }

            return(replyHandles);
        }
        /// <summary>
        /// Helper routine for posting a generic reply
        /// </summary>
        /// <param name="client">Client object</param>
        /// <param name="auth">authorization header value</param>
        /// <param name="commentHandle">The comment handle for the reply.</param>
        /// <returns>A post comment response</returns>
        public static async Task <PostReplyResponse> PostGenericReply(SocialPlusClient client, string auth, string commentHandle)
        {
            if (string.IsNullOrEmpty(commentHandle))
            {
                throw new ArgumentNullException("PostGenericReply called with empty commentHandle");
            }

            string uniqueSuffix = TestUtilities.CreateUniqueDigits();
            string text         = "The text of a reply" + uniqueSuffix;
            string language     = "en-US";

            PostReplyRequest postCommentRequest = new PostReplyRequest(text: text, language: language);
            var httpResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postCommentRequest, authorization : auth);

            if (httpResponse == null || httpResponse.Response == null || !httpResponse.Response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException(string.Format("PostGenericReply failed for  auth {0}", auth));
            }

            return(httpResponse.Body);
        }
        public async Task ManualReportTesting()
        {
            // WARNING: do not run this test unless you are doing a test where you can tolerate 1-3 days of latency
            // and can manually verify the result by inspecting Azure Tables
            Assert.IsTrue(false);

            // create two users with benign profiles
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

            string           auth1             = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);
            PostUserResponse postUserResponse2 = await TestUtilities.PostGenericUser(client);

            string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);

            // issue a Threats / Cyberbullying / Harassment report from user 2 on user 1
            PostReportRequest postReportRequest1 = new PostReportRequest(Reason.ThreatsCyberbullyingHarassment);
            HttpOperationResponse <object> postUserReportOperationResponse1 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest1, authorization : auth2);

            // issue a Content Infringment report from user 2
            PostReportRequest postReportRequest2 = new PostReportRequest(Reason.ContentInfringement);
            HttpOperationResponse <object> postUserReportOperationResponse2 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest2, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postUserReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postUserReportOperationResponse2.Response.IsSuccessStatusCode);

            // create a threatening topic from user 1
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: "I am going to beat you up.", title: "You're in big trouble.", blobType: BlobType.Custom, blobHandle: null, categories: null, language: null, deepLink: null, friendlyName: null, group: null);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth1);

            string topicHandle = null;

            if (postTopicOperationResponse != null && postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }

            // issue a Threats / Cyberbullying / Harassment report from user 2
            PostReportRequest postTopicReportRequest1 = new PostReportRequest(Reason.ThreatsCyberbullyingHarassment);
            HttpOperationResponse <object> postTopicReportOperationResponse1 = await client.TopicReports.PostReportWithHttpMessagesAsync(topicHandle : topicHandle, postReportRequest : postTopicReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postTopicReportOperationResponse1.Response.IsSuccessStatusCode);

            // create a benign comment from user 1
            var postCommentOperationResponse = await TestUtilities.PostGenericComment(client, auth1, topicHandle);

            var commentHandle = postCommentOperationResponse.CommentHandle;

            // issue a Child Endangerment / Exploitation report from user 2
            PostReportRequest postCommentReportRequest1 = new PostReportRequest(Reason.ChildEndangermentExploitation);
            HttpOperationResponse <object> postCommentReportOperationResponse1 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postCommentReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postCommentReportOperationResponse1.Response.IsSuccessStatusCode);

            // create a profanity laden reply from user 1
            PostReplyRequest postReplyRequest = new PostReplyRequest(text: "f**k. shit.");
            HttpOperationResponse <PostReplyResponse> postReplyOperationResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest, authorization : auth1);

            string replyHandle = null;

            if (postReplyOperationResponse != null && postReplyOperationResponse.Response.IsSuccessStatusCode)
            {
                replyHandle = postReplyOperationResponse.Body.ReplyHandle;
            }

            // issue an Offensive Content report from user 2
            PostReportRequest postReplyReportRequest1 = new PostReportRequest(Reason.OffensiveContent);
            HttpOperationResponse <object> postReplyReportOperationResponse1 = await client.ReplyReports.PostReportWithHttpMessagesAsync(replyHandle : replyHandle, postReportRequest : postReplyReportRequest1, authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postReplyOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postReplyReportOperationResponse1.Response.IsSuccessStatusCode);

            // do NOT clean up the users after the test ends
        }
Example #5
0
        /// <summary>
        /// Helper routine to perform the main actions of the test
        /// Create a topic, comment and reply.  Like the comment and the reply. Then delete
        /// both the comment like and the reply like.
        /// </summary>
        /// <param name="appPublished">flag to indicate if topic is app published</param>
        /// <param name="appHandle">app handle</param>
        /// <returns>Fail if an exception is hit</returns>
        public async Task LikeCommentReplyDeleteTestHelper(bool appPublished, string appHandle)
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse;
            string           firstName = "R2D2";
            string           lastName  = "Robot";
            string           bio       = string.Empty;

            postUserResponse = await TestUtilities.DoLogin(client, firstName, lastName, bio);

            string auth       = AuthHelper.CreateSocialPlusAuth(postUserResponse.SessionToken);
            string userHandle = postUserResponse.UserHandle;

            if (appPublished)
            {
                // add user as admin
                bool added = ManageAppsUtils.AddAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                if (!added)
                {
                    // delete the user and fail the test
                    await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                    Assert.Fail("Failed to set user as administrator");
                }
            }

            string   topicTitle   = "Topic for Like Reply Test";
            string   topicText    = "Verify the Like Reply!";
            BlobType blobType     = BlobType.Unknown;
            string   blobHandle   = "http://myBlobHandle/";
            string   language     = "en-US";
            string   deepLink     = "Like It!";
            string   categories   = "#likes; #reply";
            string   friendlyName = "LT";
            string   group        = "mygroup";

            string topicHandle      = string.Empty;
            var    postTopicRequest = new PostTopicRequest()
            {
                Title = topicTitle, Text = topicText, BlobType = blobType, BlobHandle = blobHandle, Language = language, DeepLink = deepLink, Categories = categories, FriendlyName = friendlyName, Group = group
            };

            if (appPublished)
            {
                postTopicRequest.PublisherType = PublisherType.App;
            }
            else
            {
                postTopicRequest.PublisherType = PublisherType.User;
            }

            var postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            if (postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                // extract topic handle from the response
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }
            else
            {
                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Post topic failed.");
            }

            // Post a comment to topic
            string commentHandle      = string.Empty;
            var    postCommentRequest = new PostCommentRequest()
            {
                Text = "My First Comment!", Language = "en-US"
            };
            var postCommentOperationResponse = await client.TopicComments.PostCommentWithHttpMessagesAsync(topicHandle : topicHandle, request : postCommentRequest, authorization : auth);

            if (postCommentOperationResponse.Response.IsSuccessStatusCode)
            {
                commentHandle = postCommentOperationResponse.Body.CommentHandle;
            }
            else
            {
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Post comment failed.");
            }

            // Post a reply to the comment to topic
            string replyHandle      = string.Empty;
            var    postReplyRequest = new PostReplyRequest()
            {
                Text = "My First Reply", Language = "en-US"
            };
            var postReplyOperationResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle, request : postReplyRequest, authorization : auth);

            if (postReplyOperationResponse.Response.IsSuccessStatusCode)
            {
                replyHandle = postReplyOperationResponse.Body.ReplyHandle;
            }
            else
            {
                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Post reply failed.");
            }

            // Post a like on the Comment
            var postLikeOperationResponse = await client.CommentLikes.PostLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            if (!postLikeOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Post like on comment failed.");
            }

            // Post a like on the Reply
            var postLikeOperationResponse2 = await client.ReplyLikes.PostLikeWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            if (!postLikeOperationResponse2.Response.IsSuccessStatusCode)
            {
                await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Post like on reply failed.");
            }

            // Get topic to later verify
            var getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (!getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.ReplyLikes.DeleteLikeWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Get topic failed.");
            }

            // Get comment to later verify the like is there
            var getCommentOperationResponse = await client.Comments.GetCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            if (!getCommentOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.ReplyLikes.DeleteLikeWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Get comment failed.");
            }

            // Get reply to later verify the like is there
            var getReplyOperationResponse = await client.Replies.GetReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            if (!getReplyOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.ReplyLikes.DeleteLikeWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Get reply failed.");
            }

            var deleteReplyLikeOperationResult = await client.ReplyLikes.DeleteLikeWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            if (!deleteReplyLikeOperationResult.Response.IsSuccessStatusCode)
            {
                await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Delete reply like failed.");
            }

            var deleteCommentLikeOperationResult = await client.CommentLikes.DeleteLikeWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            if (!deleteCommentLikeOperationResult.Response.IsSuccessStatusCode)
            {
                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Delete comment like failed.");
            }

            // Get comment a second time to verify the like is gone
            var getCommentOperationResponse2 = await client.Comments.GetCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            if (!getCommentOperationResponse2.Response.IsSuccessStatusCode)
            {
                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Get comment failed.");
            }

            // Get reply a second time to verify the like is gone
            var getReplyOperationResponse2 = await client.Replies.GetReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            if (!getReplyOperationResponse2.Response.IsSuccessStatusCode)
            {
                await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

                await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Get reply failed.");
            }

            // perform standard cleanup of the operations before checking assertions
            await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (appPublished)
            {
                ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
            }

            await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            var getTopicResponse    = getTopicOperationResponse.Body;
            var getCommentResponse  = getCommentOperationResponse.Body;
            var getReplyResponse    = getReplyOperationResponse.Body;
            var getCommentResponse2 = getCommentOperationResponse2.Body;
            var getReplyResponse2   = getReplyOperationResponse2.Body;

            // Verify topic info
            Assert.AreEqual(getTopicResponse.Liked, false);
            Assert.AreEqual(getTopicResponse.Text, topicText);
            Assert.AreEqual(getTopicResponse.BlobType, BlobType.Unknown);
            Assert.AreEqual(getTopicResponse.BlobHandle, blobHandle);
            Assert.AreEqual(getTopicResponse.Language, language);
            Assert.AreEqual(getTopicResponse.DeepLink, deepLink);
            Assert.AreEqual(getTopicResponse.Categories, categories);
            Assert.AreEqual(getTopicResponse.FriendlyName, friendlyName);
            Assert.AreEqual(getTopicResponse.Group, group);
            Assert.AreEqual(getTopicResponse.TotalComments, 1);
            Assert.AreEqual(getTopicResponse.TotalLikes, 0);

            // Verify comment info
            Assert.AreEqual(getCommentResponse.Liked, true);
            Assert.AreEqual(getCommentResponse.Text, "My First Comment!");
            Assert.AreEqual(getCommentResponse.Language, "en-US");
            Assert.AreEqual(getCommentResponse.TotalReplies, 1);
            Assert.AreEqual(getCommentResponse.TotalLikes, 1);

            // Verify reply info
            Assert.AreEqual(getReplyResponse.Liked, true);
            Assert.AreEqual(getReplyResponse.Text, "My First Reply");
            Assert.AreEqual(getReplyResponse.Language, "en-US");
            Assert.AreEqual(getReplyResponse.TotalLikes, 1);

            // Verify comment info
            Assert.AreEqual(getCommentResponse2.Liked, false);
            Assert.AreEqual(getCommentResponse2.Text, "My First Comment!");
            Assert.AreEqual(getCommentResponse2.Language, "en-US");
            Assert.AreEqual(getCommentResponse2.TotalReplies, 1);
            Assert.AreEqual(getCommentResponse2.TotalLikes, 0);

            // Verify reply info
            Assert.AreEqual(getReplyResponse2.Liked, false);
            Assert.AreEqual(getReplyResponse2.Text, "My First Reply");
            Assert.AreEqual(getReplyResponse2.Language, "en-US");
            Assert.AreEqual(getReplyResponse2.TotalLikes, 0);
        }
        public async Task PostGetRepliesTest()
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            string auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);

            // throw an error if null
            Assert.IsFalse(string.IsNullOrEmpty(auth), "User creation failed");

            HttpOperationResponse <object> deleteUserOperationResponse = null;

            // create topic, cleanup and throw an error if null
            var postTopicResponse = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle = postTopicResponse.TopicHandle;
            HttpOperationResponse <object> deleteTopicResponse = null;

            if (string.IsNullOrWhiteSpace(topicHandle))
            {
                deleteUserOperationResponse = await TestUtilities.DeleteUser(client, auth);

                Assert.Fail("Topic posting failed, or handle was invalid.");
            }

            // Post a comment to Topic
            var postCommentResponse = await TestUtilities.PostGenericComment(client, auth, topicHandle);

            string commentHandle = postCommentResponse.CommentHandle;
            HttpOperationResponse <object> deleteCommentResponse = null;

            if (string.IsNullOrWhiteSpace(commentHandle))
            {
                deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

                deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

                Assert.Fail("Comment posting failed, or handle was invalid.");
            }

            // Get comment before reply
            HttpOperationResponse <CommentView> getCommentResponse = await client.Comments.GetCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            // Post a Reply
            string           replyString      = "Hail to the Queen!";
            string           replyLanguage    = "EN-GB";
            PostReplyRequest postReplyRequest = new PostReplyRequest(text: replyString, language: replyLanguage);
            HttpOperationResponse <PostReplyResponse> postReplyResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest, authorization : auth);

            // Get Comment after reply
            HttpOperationResponse <CommentView> getCommentResponse2 = await client.Comments.GetCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            // cleanup and throw an error if null
            if (postReplyResponse == null || !postReplyResponse.Response.IsSuccessStatusCode || string.IsNullOrWhiteSpace(postReplyResponse.Body.ReplyHandle))
            {
                deleteCommentResponse = await TestUtilities.DeleteComment(client : client, commentHandle : commentHandle, authorization : auth);

                deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

                deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

                Assert.Fail("Reply posting failed, or handle was invalid.");
            }

            // Get Reply info
            string replyHandle = postReplyResponse.Body.ReplyHandle;
            HttpOperationResponse <ReplyView> getReplyResponse = await client.Replies.GetReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth);

            // Clean up first before verifying
            HttpOperationResponse <object> deleteReplyResponse = await TestUtilities.DeleteReply(client : client, replyHandle : replyHandle, authorization : auth);

            deleteCommentResponse = await TestUtilities.DeleteComment(client : client, commentHandle : commentHandle, authorization : auth);

            deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

            deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

            // Verify after cleaning up so don't leave junk behind if fails

            // Double check comment to show it counts right
            Assert.AreEqual(getCommentResponse.Body.TotalReplies, 0);  // before
            Assert.AreEqual(getCommentResponse2.Body.TotalReplies, 1); // after reply

            // Verify reply info
            Assert.AreEqual(getReplyResponse.Body.CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse.Body.ContentStatus, ContentStatus.Active);
            Assert.AreEqual(getReplyResponse.Body.Language, replyLanguage);
            Assert.AreEqual(getReplyResponse.Body.Liked, false);
            Assert.AreEqual(getReplyResponse.Body.ReplyHandle, postReplyResponse.Body.ReplyHandle);
            Assert.AreEqual(getReplyResponse.Body.Text, replyString);
            Assert.AreEqual(getReplyResponse.Body.TopicHandle, topicHandle);
            Assert.AreEqual(getReplyResponse.Body.TotalLikes, 0);

            // Verify deletion
            Assert.IsTrue(deleteReplyResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
        public async Task DeleteRepliesTest()
        {
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);
            HttpOperationResponse <object> deleteUserOperationResponse = null;

            // create topic, cleanup and throw an error if null
            var postTopicResponse = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle = postTopicResponse.TopicHandle;
            HttpOperationResponse <object> deleteTopicResponse = null;

            if (string.IsNullOrWhiteSpace(topicHandle))
            {
                deleteUserOperationResponse = await TestUtilities.DeleteUser(client, auth);

                Assert.Fail("Topic posting failed, or handle was invalid.");
            }

            // Post a comment to Topic
            var postCommentResponse = await TestUtilities.PostGenericComment(client, auth, topicHandle);

            string commentHandle = postCommentResponse.CommentHandle;
            HttpOperationResponse <object> deleteCommentResponse = null;

            if (string.IsNullOrWhiteSpace(commentHandle))
            {
                deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

                deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

                Assert.Fail("Comment posting failed, or handle was invalid.");
            }

            // Post reply
            string replyString   = "May the force be with!";
            string replyLanguage = "YodaSpeak1000";
            HttpOperationResponse <PostReplyResponse>       postReplyResponse   = null;
            HttpOperationResponse <FeedResponseCommentView> getCommentsResponse = null;
            HttpOperationResponse <FeedResponseReplyView>   getReplyResponse    = null;

            PostReplyRequest postReplyRequest = new PostReplyRequest(text: replyString, language: replyLanguage);

            postReplyResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest, authorization : auth);

            // Get Comment after reply
            getCommentsResponse = await client.TopicComments.GetTopicCommentsWithHttpMessagesAsync(topicHandle : topicHandle, cursor : null, limit : 5, authorization : auth);

            // Get Replies
            getReplyResponse = await client.CommentReplies.GetRepliesWithHttpMessagesAsync(commentHandle : commentHandle, cursor : null, limit : 2, authorization : auth);

            // Delete Reply - Cleanup method checks validity of the handle
            HttpOperationResponse <object> deleteReplyResponse = await TestUtilities.DeleteReply(client : client, postReplyResponse : postReplyResponse, authorization : auth);

            // get the Comment and double check info showing up in comment
            HttpOperationResponse <FeedResponseCommentView> getCommentsResponse2 = await client.TopicComments.GetTopicCommentsWithHttpMessagesAsync(topicHandle : topicHandle, cursor : null, limit : 5, authorization : auth);

            // Get Replies after delete
            HttpOperationResponse <FeedResponseReplyView> getReplyResponse2 = await client.CommentReplies.GetRepliesWithHttpMessagesAsync(commentHandle : commentHandle, cursor : null, limit : 2, authorization : auth);

            // Clean up first before verifying
            deleteCommentResponse = await TestUtilities.DeleteComment(client : client, commentHandle : commentHandle, authorization : auth);

            deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

            deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

            // Verify after cleaning up so don't leave junk behind if fails

            // Verify comment count from GetTopic ... before and after delete
            Assert.AreEqual(getCommentsResponse.Body.Data.Count, 1);
            Assert.AreEqual(getCommentsResponse.Body.Data[0].TotalReplies, 1);
            Assert.AreEqual(getCommentsResponse2.Body.Data[0].TotalReplies, 0);

            // Also verify the GetReplies part
            Assert.AreEqual(getReplyResponse.Body.Data.Count, 1);
            Assert.AreEqual(getReplyResponse2.Body.Data.Count, 0);  // after the delete

            // Verify deletion
            Assert.IsTrue(deleteReplyResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
        public async Task GetRepliesForACommentTest()
        {
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

            var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken);
            HttpOperationResponse <object> deleteUserOperationResponse = null;

            // create topic, cleanup and throw an error if null
            var postTopicResponse = await TestUtilities.PostGenericTopic(client, auth);

            string topicHandle = postTopicResponse.TopicHandle;
            HttpOperationResponse <object> deleteTopicResponse = null;

            if (string.IsNullOrWhiteSpace(topicHandle))
            {
                deleteUserOperationResponse = await TestUtilities.DeleteUser(client, auth);

                Assert.Fail("Topic posting failed, or handle was invalid.");
            }

            // Post a comment
            var postCommentResponse = await TestUtilities.PostGenericComment(client, auth, topicHandle);

            string commentHandle = postCommentResponse.CommentHandle;
            HttpOperationResponse <object> deleteCommentResponse = null;

            if (string.IsNullOrWhiteSpace(commentHandle))
            {
                deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

                deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

                Assert.Fail("Comment posting failed, or handle was invalid.");
            }

            string           replyString      = "Ciao!!!!!!";
            string           replyLanguage    = "ItalianLanguage";
            PostReplyRequest postReplyRequest = new PostReplyRequest(text: replyString, language: replyLanguage);
            HttpOperationResponse <PostReplyResponse> postReplyResponse = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest, authorization : auth);

            string           replyString2      = "Guten Tag!!!!!!";
            string           replyLanguage2    = "GermanLanguage";
            PostReplyRequest postReplyRequest2 = new PostReplyRequest(text: replyString2, language: replyLanguage2);
            HttpOperationResponse <PostReplyResponse> postReplyResponse2 = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest2, authorization : auth);

            string           replyString3      = "Yee Ha!!!!!!";
            string           replyLanguage3    = "CowboyLanguage";
            PostReplyRequest postReplyRequest3 = new PostReplyRequest(text: replyString3, language: replyLanguage3);
            HttpOperationResponse <PostReplyResponse> postReplyResponse3 = await client.CommentReplies.PostReplyWithHttpMessagesAsync(commentHandle : commentHandle, request : postReplyRequest3, authorization : auth);

            // Get Replies for only 1
            HttpOperationResponse <FeedResponseReplyView> getReplyResponse = await client.CommentReplies.GetRepliesWithHttpMessagesAsync(commentHandle : commentHandle, cursor : null, limit : 1, authorization : auth);

            // Get 2 Replies using cursor from first one
            HttpOperationResponse <FeedResponseReplyView> getReplyResponse2 = await client.CommentReplies.GetRepliesWithHttpMessagesAsync(commentHandle : commentHandle, cursor : getReplyResponse.Body.Cursor, limit : 2, authorization : auth);

            // Get all 3 replies
            HttpOperationResponse <FeedResponseReplyView> getReplyResponse3 = await client.CommentReplies.GetRepliesWithHttpMessagesAsync(commentHandle : commentHandle, cursor : null, limit : 10, authorization : auth);

            // Get comment afterwards
            HttpOperationResponse <CommentView> getCommentResponse = await client.Comments.GetCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth);

            // Clean up first before verifying
            // delete replies - the cleanup method checks replyHandle for null
            HttpOperationResponse <object> deleteReplyResponse = await TestUtilities.DeleteReply(client : client, postReplyResponse : postReplyResponse, authorization : auth);

            HttpOperationResponse <object> deleteReplyResponse2 = await TestUtilities.DeleteReply(client : client, postReplyResponse : postReplyResponse2, authorization : auth);

            HttpOperationResponse <object> deleteReplyResponse3 = await TestUtilities.DeleteReply(client : client, postReplyResponse : postReplyResponse3, authorization : auth);

            deleteCommentResponse = await TestUtilities.DeleteComment(client : client, commentHandle : commentHandle, authorization : auth);

            deleteTopicResponse = await TestUtilities.DeleteTopic(client : client, topicHandle : topicHandle, authorization : auth);

            deleteUserOperationResponse = await TestUtilities.DeleteUser(client : client, authorization : auth);

            // Verify after cleaning up so don't leave junk behind if fails

            // Double check Comment
            Assert.AreEqual(getCommentResponse.Body.Liked, false);
            Assert.AreEqual(getCommentResponse.Body.TopicHandle, topicHandle);
            Assert.AreEqual(getCommentResponse.Body.TotalReplies, 3);
            Assert.AreEqual(getCommentResponse.Body.TotalLikes, 0);

            // Verify Reply info from first Reply
            Assert.AreEqual(getReplyResponse.Body.Data[0].Liked, false);
            Assert.AreEqual(getReplyResponse.Body.Data[0].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse.Body.Data[0].TotalLikes, 0);
            Assert.AreEqual(getReplyResponse.Body.Data[0].ContentStatus, ContentStatus.Active);

            Assert.AreEqual(getReplyResponse.Body.Data[0].Language, replyLanguage3);
            Assert.AreEqual(getReplyResponse.Body.Data[0].Text, replyString3);
            Assert.AreEqual(getReplyResponse.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getReplyResponse.Body.Data[0].User.UserHandle, user.UserHandle);
            Assert.AreEqual(getReplyResponse.Body.Data[0].User.Visibility, Visibility.Public);

            // Verify Reply from the Second Get (using cursor from first one)
            Assert.AreEqual(getReplyResponse2.Body.Data[0].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse2.Body.Data[0].Language, replyLanguage2);
            Assert.AreEqual(getReplyResponse2.Body.Data[0].Text, replyString2);
            Assert.AreEqual(getReplyResponse2.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getReplyResponse2.Body.Data[1].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse2.Body.Data[1].Language, replyLanguage);
            Assert.AreEqual(getReplyResponse2.Body.Data[1].Text, replyString);
            Assert.AreEqual(getReplyResponse2.Body.Data[1].TopicHandle, topicHandle);

            // Verify Reply from Third Get (getting all comments)
            Assert.AreEqual(getReplyResponse3.Body.Data[0].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse3.Body.Data[0].Language, replyLanguage3);
            Assert.AreEqual(getReplyResponse3.Body.Data[0].Text, replyString3);
            Assert.AreEqual(getReplyResponse3.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getReplyResponse3.Body.Data[1].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse3.Body.Data[1].Language, replyLanguage2);
            Assert.AreEqual(getReplyResponse3.Body.Data[1].Text, replyString2);
            Assert.AreEqual(getReplyResponse3.Body.Data[1].TopicHandle, topicHandle);
            Assert.AreEqual(getReplyResponse3.Body.Data[2].CommentHandle, commentHandle);
            Assert.AreEqual(getReplyResponse3.Body.Data[2].Language, replyLanguage);
            Assert.AreEqual(getReplyResponse3.Body.Data[2].Text, replyString);
            Assert.AreEqual(getReplyResponse3.Body.Data[2].TopicHandle, topicHandle);

            // Verify deletion
            Assert.IsTrue(deleteReplyResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteReplyResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteReplyResponse3.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
Example #9
0
        /// <summary>
        /// Create a new reply
        /// </summary>
        /// <param name='commentHandle'>
        /// Comment handle
        /// </param>
        /// <param name='request'>
        /// Post reply request
        /// </param>
        /// <param name='authorization'>
        /// Format is: "Scheme CredentialsList". Possible values are:
        ///
        /// - Anon AK=AppKey
        ///
        /// - SocialPlus TK=SessionToken
        ///
        /// - Facebook AK=AppKey|TK=AccessToken
        ///
        /// - Google AK=AppKey|TK=AccessToken
        ///
        /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
        ///
        /// - Microsoft AK=AppKey|TK=AccessToken
        ///
        /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <PostReplyResponse> > PostReplyWithHttpMessagesAsync(string commentHandle, PostReplyRequest request, string authorization, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (commentHandle == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "commentHandle");
            }
            if (request == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "request");
            }
            if (request != null)
            {
                request.Validate();
            }
            if (authorization == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "authorization");
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("commentHandle", commentHandle);
                tracingParameters.Add("request", request);
                tracingParameters.Add("authorization", authorization);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "PostReply", tracingParameters);
            }
            // Construct URL
            var _baseUrl = this.Client.BaseUri.AbsoluteUri;
            var _url     = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v0.7/comments/{commentHandle}/replies").ToString();

            _url = _url.Replace("{commentHandle}", Uri.EscapeDataString(commentHandle));
            // Create HTTP transport objects
            HttpRequestMessage  _httpRequest  = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("POST");
            _httpRequest.RequestUri = new Uri(_url);
            // Set Headers
            if (authorization != null)
            {
                if (_httpRequest.Headers.Contains("Authorization"))
                {
                    _httpRequest.Headers.Remove("Authorization");
                }
                _httpRequest.Headers.TryAddWithoutValidation("Authorization", authorization);
            }
            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (request != null)
            {
                _requestContent      = SafeJsonConvert.SerializeObject(request, this.Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 201 && (int)_statusCode != 400 && (int)_statusCode != 401 && (int)_statusCode != 404 && (int)_statusCode != 500)
            {
                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <PostReplyResponse>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            // Deserialize Response
            if ((int)_statusCode == 201)
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    _result.Body = SafeJsonConvert.DeserializeObject <PostReplyResponse>(_responseContent, this.Client.DeserializationSettings);
                }
                catch (JsonException ex)
                {
                    _httpRequest.Dispose();
                    if (_httpResponse != null)
                    {
                        _httpResponse.Dispose();
                    }
                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
                }
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
Example #10
0
 /// <summary>
 /// Create a new reply
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='commentHandle'>
 /// Comment handle
 /// </param>
 /// <param name='request'>
 /// Post reply request
 /// </param>
 /// <param name='authorization'>
 /// Format is: "Scheme CredentialsList". Possible values are:
 ///
 /// - Anon AK=AppKey
 ///
 /// - SocialPlus TK=SessionToken
 ///
 /// - Facebook AK=AppKey|TK=AccessToken
 ///
 /// - Google AK=AppKey|TK=AccessToken
 ///
 /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
 ///
 /// - Microsoft AK=AppKey|TK=AccessToken
 ///
 /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PostReplyResponse> PostReplyAsync(this ICommentReplies operations, string commentHandle, PostReplyRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostReplyWithHttpMessagesAsync(commentHandle, request, authorization, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Example #11
0
 /// <summary>
 /// Create a new reply
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='commentHandle'>
 /// Comment handle
 /// </param>
 /// <param name='request'>
 /// Post reply request
 /// </param>
 /// <param name='authorization'>
 /// Format is: "Scheme CredentialsList". Possible values are:
 ///
 /// - Anon AK=AppKey
 ///
 /// - SocialPlus TK=SessionToken
 ///
 /// - Facebook AK=AppKey|TK=AccessToken
 ///
 /// - Google AK=AppKey|TK=AccessToken
 ///
 /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
 ///
 /// - Microsoft AK=AppKey|TK=AccessToken
 ///
 /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
 /// </param>
 public static PostReplyResponse PostReply(this ICommentReplies operations, string commentHandle, PostReplyRequest request, string authorization)
 {
     return(Task.Factory.StartNew(s => ((ICommentReplies)s).PostReplyAsync(commentHandle, request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }