public async Task SearchTopicsTestUsingEmptyString()
        {
            // ***********************************************
            // ** NOTE ** - Verification might change if design is set to not return anything vs return everything
            // ***********************************************
            SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse;
            string           firstName = "FirstUser";
            string           lastName  = "FirstUserLastName";
            string           bio       = string.Empty;

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

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

            // First Topic
            string           topicTitle       = "My Favorite Topic";
            string           topicText        = "Sports. ";
            BlobType         blobType         = BlobType.Image;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = "en-US";
            string           deepLink         = "Sports!";
            string           categories       = "sports, ncurrency";
            string           friendlyName     = "Game On!";
            string           group            = "mygroup";
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // If the post topic operation failed, clean up
            if (postTopicOperationResponse == null || postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to post topic");
            }

            // Delay a bit to allow data to get into the search
            await Task.Delay(TestConstants.SearchDelay);

            // Only one result
            HttpOperationResponse <FeedResponseTopicView> search1 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : string.Empty, cursor : null, limit : 5, authorization : auth);

            // Clean up topic
            HttpOperationResponse <object> deleteTopic1 = await client1.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : postTopicOperationResponse.Body.TopicHandle, authorization : auth);

            // Clean up first user
            HttpOperationResponse <object> deleteUser1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Verify now - get info
            Assert.AreEqual(search1.Response.StatusCode, HttpStatusCode.BadRequest);

            // Verify deletions
            Assert.IsTrue(deleteTopic1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUser1.Response.IsSuccessStatusCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a topic
        /// </summary>
        /// <param name="publisherType">publisher type</param>
        /// <returns>result of create topic operation</returns>
        public async Task <IHttpActionResult> PostTopic(PublisherType publisherType)
        {
            var postTopicRequest = new PostTopicRequest
            {
                PublisherType = publisherType,
                Text          = "Text" + this.seqNumber.GenerateStronglyOrderedSequenceNumber()
            };

            return(await this.PostTopic(postTopicRequest));
        }
        /// <summary>
        /// Helper routine for posting a generic topic.
        /// </summary>
        /// <param name="client">Client object</param>
        /// <param name="auth">authorization header value</param>
        /// <returns>A post topic response</returns>
        public static async Task <PostTopicResponse> PostGenericTopic(SocialPlusClient client, string auth)
        {
            string   uniqueSuffix = TestUtilities.CreateUniqueDigits();
            string   topicTitle   = "Topic Title" + uniqueSuffix;
            string   topicText    = "Topic text is a long description" + uniqueSuffix;
            BlobType blobType     = BlobType.Image;
            string   blobHandle   = "http://myBlobHandle/" + uniqueSuffix;
            string   language     = "en-US";

            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language);
            var httpResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            if (httpResponse == null || httpResponse.Response == null || !httpResponse.Response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException(string.Format("PostGenericTopic failed for auth {0} with status code {1}", auth, httpResponse.Response.StatusCode));
            }

            return(httpResponse.Body);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <int> > InsertTopic([FromBody] PostTopicRequest model)
        {
            var rs = await _topicService.AddTopic(model.Name, model.Description, model.NameEng, model.DescriptionEng, model.Image, model.StartDate, model.Username);

            return(Ok(rs));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        public async Task BatchTestMultiGetTopics()
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            string           firstName        = "Stan";
            string           lastName         = "TopicMan";
            string           bio              = string.Empty;
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, firstName, lastName, bio);

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

            string   topicTitle1  = "My Favorite Topic";
            string   topicText1   = "It is all about sports!";
            BlobType blobType     = BlobType.Image;
            string   blobHandle   = "http://myBlobHandle/";
            string   language     = "en-US";
            string   deepLink     = "Sports!";
            string   categories   = "sports, ncurrency";
            string   friendlyName = "Game On!";
            string   group        = "mygroup";

            PostTopicRequest postTopicRequest1 = new PostTopicRequest(publisherType: PublisherType.User, text: topicText1, title: topicTitle1, blobType: blobType, blobHandle: blobHandle, categories: categories, language: language, deepLink: deepLink, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse1 = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest1, authorization : auth);

            string           topicTitle2       = "My Favorite Topic #2";
            string           topicText2        = "Maybe it isn't all about sports?";
            PostTopicRequest postTopicRequest2 = new PostTopicRequest(publisherType: PublisherType.User, text: topicText2, title: topicTitle2, blobType: blobType, blobHandle: blobHandle, categories: categories, language: language, deepLink: deepLink, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : auth);

            // extract topic handles from the responses
            var topicHandle1 = postTopicOperationResponse1.Body.TopicHandle;
            var topicHandle2 = postTopicOperationResponse2.Body.TopicHandle;

            // create a new batch operation
            Uri batchURL = new Uri(TestConstants.ServerApiBaseUrl.OriginalString + "batch");
            BatchHttpMessageHandler batchHandler = new BatchHttpMessageHandler(HttpMethod.Post, batchURL);

            // Create a batch client
            DelegatingHandler[] handlers = new DelegatingHandler[1];
            handlers[0] = batchHandler;
            SocialPlusClient batchClient = new SocialPlusClient(TestConstants.ServerApiBaseUrl, handlers);

            // put two calls to GetTopic inside the batch
            Task <HttpOperationResponse <TopicView> > getTopic1 = batchClient.Topics.GetTopicWithHttpMessagesAsync(topicHandle1, auth);
            Task <HttpOperationResponse <TopicView> > getTopic2 = batchClient.Topics.GetTopicWithHttpMessagesAsync(topicHandle2, auth);

            // send the batch to the server
            await batchHandler.IssueBatch();

            // process the individual results from the batch
            var topicResult1 = await getTopic1;
            var topicResult2 = await getTopic2;

            // clean up
            await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle1, auth);

            await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle2, auth);

            await client.Users.DeleteUserWithHttpMessagesAsync(auth);

            // after clean up, check that the get topic operations inside the batch were successful
            Assert.AreEqual(categories, topicResult1.Body.Categories);
            Assert.AreEqual(ContentStatus.Active, topicResult1.Body.ContentStatus);
            Assert.AreEqual(deepLink, topicResult1.Body.DeepLink);
            Assert.AreEqual(friendlyName, topicResult1.Body.FriendlyName);
            Assert.AreEqual(group, topicResult1.Body.Group);
            Assert.AreEqual(language, topicResult1.Body.Language);
            Assert.AreEqual(false, topicResult1.Body.Liked);
            Assert.AreEqual(false, topicResult1.Body.Pinned);
            Assert.AreEqual(PublisherType.User, topicResult1.Body.PublisherType);
            Assert.AreEqual(topicText1, topicResult1.Body.Text);
            Assert.AreEqual(topicTitle1, topicResult1.Body.Title);
            Assert.AreEqual(topicHandle1, topicResult1.Body.TopicHandle);
            Assert.AreEqual(0, topicResult1.Body.TotalComments);
            Assert.AreEqual(0, topicResult1.Body.TotalLikes);
            Assert.AreEqual(firstName, topicResult1.Body.User.FirstName);
            Assert.AreEqual(lastName, topicResult1.Body.User.LastName);
            Assert.AreEqual(postUserResponse.UserHandle, topicResult1.Body.User.UserHandle);

            Assert.AreEqual(categories, topicResult2.Body.Categories);
            Assert.AreEqual(ContentStatus.Active, topicResult2.Body.ContentStatus);
            Assert.AreEqual(deepLink, topicResult2.Body.DeepLink);
            Assert.AreEqual(friendlyName, topicResult2.Body.FriendlyName);
            Assert.AreEqual(group, topicResult2.Body.Group);
            Assert.AreEqual(language, topicResult2.Body.Language);
            Assert.AreEqual(false, topicResult2.Body.Liked);
            Assert.AreEqual(false, topicResult2.Body.Pinned);
            Assert.AreEqual(PublisherType.User, topicResult2.Body.PublisherType);
            Assert.AreEqual(topicText2, topicResult2.Body.Text);
            Assert.AreEqual(topicTitle2, topicResult2.Body.Title);
            Assert.AreEqual(topicHandle2, topicResult2.Body.TopicHandle);
            Assert.AreEqual(0, topicResult2.Body.TotalComments);
            Assert.AreEqual(0, topicResult2.Body.TotalLikes);
            Assert.AreEqual(firstName, topicResult2.Body.User.FirstName);
            Assert.AreEqual(lastName, topicResult2.Body.User.LastName);
            Assert.AreEqual(postUserResponse.UserHandle, topicResult2.Body.User.UserHandle);
        }
Ejemplo n.º 7
0
        public async Task PostGetLikeDeleteCommentTest()
        {
            // create 2 users
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            string           firstName         = "Stan";
            string           lastName          = "TopicMan";
            string           bio               = string.Empty;
            PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client, firstName, lastName, bio);

            string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken);

            string           firstName2        = "NotPopularNelly";
            string           lastName2         = "Von Jerk";
            string           bio2              = "Nelly is not very popular. :(";
            PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client, firstName2, lastName2, bio2);

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

            // create a topic from user 1
            string           topicTitle       = "My Favorite Topic";
            string           topicText        = "It is all about sports!";
            BlobType         blobType         = BlobType.Custom;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = string.Empty;
            string           deepLink         = string.Empty;
            string           categories       = string.Empty;
            string           friendlyName     = string.Empty;
            string           group            = string.Empty;
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, categories: categories, language: language, deepLink: deepLink, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth1);

            string topicHandle = null;

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

            // post comment 1 with an image from user 2
            HttpOperationResponse <PostImageResponse> postImageOperationResponse = await ImageTests.AddImage(new System.Uri("http://research.microsoft.com/a/i/c/ms-logo.png"), ImageType.ContentBlob, client, auth2);

            string             imageHandle         = string.Empty;
            PostCommentRequest postCommentRequest1 = null;
            HttpOperationResponse <PostCommentResponse> postCommentOperationResponse1 = null;

            if (!string.IsNullOrWhiteSpace(topicHandle) && postImageOperationResponse != null && postImageOperationResponse.Response.IsSuccessStatusCode)
            {
                // get the image handle
                imageHandle = postImageOperationResponse.Body.BlobHandle;

                // create a comment from user 2
                postCommentRequest1           = new PostCommentRequest(text: "my comment", blobType: BlobType.Image, blobHandle: imageHandle, language: "gibberish");
                postCommentOperationResponse1 = await client.TopicComments.PostCommentWithHttpMessagesAsync(topicHandle : topicHandle, request : postCommentRequest1, authorization : auth2);
            }

            // post comment 2 from user 1
            PostCommentRequest postCommentRequest2 = null;
            HttpOperationResponse <PostCommentResponse> postCommentOperationResponse2 = null;

            if (!string.IsNullOrWhiteSpace(topicHandle))
            {
                // create a comment from user 1
                postCommentRequest2           = new PostCommentRequest(text: "another comment");
                postCommentOperationResponse2 = await client.TopicComments.PostCommentWithHttpMessagesAsync(topicHandle : topicHandle, request : postCommentRequest2, authorization : auth1);
            }

            // get comment handles
            string commentHandle1 = null;
            string commentHandle2 = null;

            if (postCommentOperationResponse1 != null && postCommentOperationResponse1.Response.IsSuccessStatusCode)
            {
                commentHandle1 = postCommentOperationResponse1.Body.CommentHandle;
            }

            if (postCommentOperationResponse2 != null && postCommentOperationResponse2.Response.IsSuccessStatusCode)
            {
                commentHandle2 = postCommentOperationResponse2.Body.CommentHandle;
            }

            // like comment 2 by user 2
            HttpOperationResponse <object> postLikeOperationResponse = null;

            if (!string.IsNullOrWhiteSpace(commentHandle2))
            {
                postLikeOperationResponse = await client.CommentLikes.PostLikeWithHttpMessagesAsync(commentHandle : commentHandle2, authorization : auth2);
            }

            // get topic & comment feed from the server as user 2
            HttpOperationResponse <TopicView> getTopicOperationResponse = null;
            HttpOperationResponse <FeedResponseCommentView> getCommentsOperationResponse1 = null;

            if (!string.IsNullOrWhiteSpace(commentHandle1) && !string.IsNullOrWhiteSpace(commentHandle2))
            {
                getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1);

                getCommentsOperationResponse1 = await client.TopicComments.GetTopicCommentsWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth2);
            }

            // try to delete comment 1 with wrong bearer token
            HttpOperationResponse <object> deleteCommentOperationResponse1 = null;

            if (postCommentOperationResponse1 != null && postCommentOperationResponse1.Response.IsSuccessStatusCode)
            {
                deleteCommentOperationResponse1 = await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle1, authorization : auth1);
            }

            // delete comment 1 with good bearer token
            HttpOperationResponse <object> deleteCommentOperationResponse2 = null;

            if (postCommentOperationResponse1 != null && postCommentOperationResponse1.Response.IsSuccessStatusCode)
            {
                deleteCommentOperationResponse2 = await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle1, authorization : auth2);
            }

            // get comment feed from the server as user 1
            HttpOperationResponse <FeedResponseCommentView> getCommentsOperationResponse2 = null;

            if (!string.IsNullOrWhiteSpace(commentHandle2))
            {
                getCommentsOperationResponse2 = await client.TopicComments.GetTopicCommentsWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1);
            }

            // delete comment 1 again with good bearer token
            HttpOperationResponse <object> deleteCommentOperationResponse3 = null;

            if (postCommentOperationResponse1 != null && postCommentOperationResponse1.Response.IsSuccessStatusCode)
            {
                deleteCommentOperationResponse3 = await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle1, authorization : auth2);
            }

            // delete comment 2
            HttpOperationResponse <object> deleteCommentOperationResponse4 = null;

            if (postCommentOperationResponse2 != null && postCommentOperationResponse2.Response.IsSuccessStatusCode)
            {
                deleteCommentOperationResponse4 = await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle2, authorization : auth1);
            }

            // no need to delete the image because there is no image delete API

            // delete topic
            HttpOperationResponse <object> deleteTopicOperationResponse = null;

            if (!string.IsNullOrWhiteSpace(topicHandle))
            {
                deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1);
            }

            // delete users
            HttpOperationResponse <object> deleteUserOperationResponse1 = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1);

            HttpOperationResponse <object> deleteUserOperationResponse2 = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2);

            // check failure conditions
            Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postImageOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(postCommentOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postCommentOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(getTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(getCommentsOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(getCommentsOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(postLikeOperationResponse.Response.IsSuccessStatusCode);

            Assert.IsFalse(deleteCommentOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsFalse(deleteCommentOperationResponse3.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentOperationResponse4.Response.IsSuccessStatusCode);

            // check response values
            Assert.IsFalse(string.IsNullOrWhiteSpace(postUserResponse1.SessionToken));
            Assert.IsFalse(string.IsNullOrWhiteSpace(postUserResponse2.SessionToken));
            Assert.IsFalse(string.IsNullOrWhiteSpace(topicHandle));
            Assert.IsFalse(string.IsNullOrWhiteSpace(imageHandle));
            Assert.IsFalse(string.IsNullOrWhiteSpace(commentHandle1));
            Assert.IsFalse(string.IsNullOrWhiteSpace(commentHandle2));
            Assert.AreEqual(getTopicOperationResponse.Body.TotalComments, 2);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data.Count, 2);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data.Count, 1);

            // check comment 1 in comment feed 1 (oldest in the feed)
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].BlobHandle, postCommentRequest1.BlobHandle);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].BlobType, postCommentRequest1.BlobType);
            Assert.IsTrue(getCommentsOperationResponse1.Body.Data[1].BlobUrl.Contains(imageHandle));
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].CommentHandle, commentHandle1);
            Assert.IsTrue(getCommentsOperationResponse1.Body.Data[1].ContentStatus == ContentStatus.Active || getCommentsOperationResponse1.Body.Data[1].ContentStatus == ContentStatus.Clean);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].Language, postCommentRequest1.Language);
            Assert.IsFalse(getCommentsOperationResponse1.Body.Data[1].Liked);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].Text, postCommentRequest1.Text);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].TopicHandle, topicHandle);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].TotalLikes, 0);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].TotalReplies, 0);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[1].User.UserHandle, postUserResponse2.UserHandle);

            // check comment 2 in comment feed 1 (earliest in the feed)
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].BlobHandle, postCommentRequest2.BlobHandle);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].BlobType, BlobType.Unknown);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse1.Body.Data[0].BlobUrl));
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].CommentHandle, commentHandle2);
            Assert.IsTrue(getCommentsOperationResponse1.Body.Data[0].ContentStatus == ContentStatus.Active || getCommentsOperationResponse1.Body.Data[0].ContentStatus == ContentStatus.Clean);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse1.Body.Data[0].Language));
            Assert.IsTrue(getCommentsOperationResponse1.Body.Data[0].Liked);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].Text, postCommentRequest2.Text);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].TotalLikes, 1);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].TotalReplies, 0);
            Assert.AreEqual(getCommentsOperationResponse1.Body.Data[0].User.UserHandle, postUserResponse1.UserHandle);

            // check comment 2 in comment feed 2 (only one in the feed)
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].BlobHandle, postCommentRequest2.BlobHandle);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].BlobType, BlobType.Unknown);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse2.Body.Data[0].BlobUrl));
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].CommentHandle, commentHandle2);
            Assert.IsTrue(getCommentsOperationResponse2.Body.Data[0].ContentStatus == ContentStatus.Active || getCommentsOperationResponse2.Body.Data[0].ContentStatus == ContentStatus.Clean);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse2.Body.Data[0].Language));
            Assert.IsFalse(getCommentsOperationResponse2.Body.Data[0].Liked);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].Text, postCommentRequest2.Text);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TotalLikes, 1);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TotalReplies, 0);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].User.UserHandle, postUserResponse1.UserHandle);
        }
        public async Task AppPublishedCreateVerifyDeleteTopicTest()
        {
            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName);

            if (appHandle == null)
            {
                // fail the test
                Assert.Fail("Failed to lookup appHandle");
            }

            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var user = await TestUtilities.PostGenericUser(client);

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

            string userHandle = user.UserHandle;

            // 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");
            }

            // create a topic
            string           topicTitle       = "My Favorite Topic";
            string           topicText        = "It is all about sports!";
            BlobType         blobType         = BlobType.Image;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = "en-US";
            string           deepLink         = "Sports!";
            string           categories       = "sports, ncurrency";
            string           group            = "mygroup";
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.App, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, categories: categories, language: language, deepLink: deepLink, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // if create topic was a success, grab the topic handle, the topic, and delete the topic and user to cleanup
            string topicHandle = string.Empty;
            HttpOperationResponse <TopicView> getTopicOperationResponse    = null;
            HttpOperationResponse <object>    deleteTopicOperationResponse = null;
            HttpOperationResponse <object>    deleteUserOperationResponse  = null;
            bool?deleteAdminResult = null;

            if (postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
                getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

            // otherwise, delete the admin and the user
            deleteAdminResult           = ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
            deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // check everything went well
            Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(getTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteAdminResult.HasValue);
            Assert.IsTrue(deleteAdminResult.Value);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
            TopicView getTopicResponse = getTopicOperationResponse.Body;

            Assert.AreEqual(getTopicResponse.BlobHandle, blobHandle);
            Assert.AreEqual(getTopicResponse.BlobType, blobType);
            if (getTopicResponse.BlobUrl.Contains("images/" + blobHandle) == false)
            {
                Assert.Fail(blobHandle + "should be contained in this: " + getTopicResponse.BlobUrl);
            }

            Assert.AreEqual(getTopicResponse.Categories, categories);
            Assert.IsTrue(getTopicResponse.ContentStatus == ContentStatus.Active || getTopicResponse.ContentStatus == ContentStatus.Clean);
            Assert.AreEqual(getTopicResponse.DeepLink, deepLink);
            Assert.AreEqual(getTopicResponse.Group, group);
            Assert.AreEqual(getTopicResponse.Language, language);
            Assert.AreEqual(getTopicResponse.Liked, false);
            Assert.AreEqual(getTopicResponse.Pinned, false);
            Assert.AreEqual(getTopicResponse.PublisherType, PublisherType.App);
            Assert.AreEqual(getTopicResponse.Text, topicText);
            Assert.AreEqual(getTopicResponse.Title, topicTitle);
            Assert.AreEqual(getTopicResponse.TopicHandle, topicHandle);
            Assert.AreEqual(getTopicResponse.TotalComments, 0);
            Assert.AreEqual(getTopicResponse.TotalLikes, 0);

            // for app-published topics, the user is null
            Assert.AreEqual(getTopicResponse.User, null);
        }
        public async Task TrendingHashTagsTest()
        {
            // Create users
            SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            string           firstName1        = "Stan";
            string           lastName1         = "TopicMan";
            string           bio1              = string.Empty;
            PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client1, firstName1, lastName1, bio1);

            string bearerToken1 = "Bearer " + postUserResponse1.SessionToken;

            string           firstName2        = "Emily";
            string           lastName2         = "Johnson";
            string           bio2              = string.Empty;
            PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client2, firstName2, lastName2, bio2);

            string bearerToken2 = "Bearer " + postUserResponse2.SessionToken;

            // First Topic by first user
            string           topicTitle1       = "My Favorite Topic";
            string           topicText1        = "It is all about sports! #sports #NFL";
            BlobType         blobType1         = BlobType.Image;
            string           blobHandle1       = "http://myBlobHandle/";
            string           language1         = "en-US";
            string           deepLink1         = "Sports!";
            string           categories1       = "sports, ncurrency";
            string           friendlyName1     = "Game On!";
            string           group1            = "mygroup";
            PostTopicRequest postTopicRequest1 = new PostTopicRequest(
                publisherType: PublisherType.User,
                text: topicText1,
                title: topicTitle1,
                blobType: blobType1,
                blobHandle: blobHandle1,
                language: language1,
                deepLink: deepLink1,
                categories: categories1,
                friendlyName: friendlyName1,
                group: group1);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse1 = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest1, authorization : bearerToken1);

            // If the first post topic operation failed, clean up
            if (!postTopicOperationResponse1.Response.IsSuccessStatusCode)
            {
                await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken1);

                await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken2);

                Assert.Fail("Failed to post first topic");
            }

            // Delay to ensure that the topics are ordered correctly
            await Task.Delay(TestConstants.SearchDelay);

            // Second Topic by first user
            // Create a GUID for the word that we will test autocomplete against.
            // Reduce the size of the guid to fit into the query. Max size is 25.
            string           guidstring        = Guid.NewGuid().ToString().Substring(0, 24);
            string           topicTitle2       = "My Second Favorite Topic";
            string           topicText2        = "It is all about food! #food" + " #" + guidstring + " #" + guidstring + guidstring;
            BlobType         blobType2         = BlobType.Custom;
            string           blobHandle2       = "http://myBlobHandle/";
            string           language2         = "en-US";
            string           deepLink2         = "Food!";
            string           categories2       = guidstring + " " + guidstring;
            string           friendlyName2     = "Eat!";
            string           group2            = "mygroup";
            PostTopicRequest postTopicRequest2 = new PostTopicRequest(
                publisherType: PublisherType.User,
                text: topicText2,
                title: topicTitle2,
                blobType: blobType2,
                blobHandle: blobHandle2,
                language: language2,
                deepLink: deepLink2,
                categories: categories2,
                friendlyName: friendlyName2,
                group: group2);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : bearerToken2);

            // If the second post topic operation failed, clean up
            if (!postTopicOperationResponse2.Response.IsSuccessStatusCode)
            {
                // clean up user 1 and topic 1
                await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse1.Body.TopicHandle, bearerToken1);

                await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken1);

                // clean up user 2
                await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken2);

                Assert.Fail("Failed to post second topic");
            }

            await Task.Delay(TestConstants.SearchDelay);

            // Get the trending hash tags
            HttpOperationResponse <IList <string> > trendingResponse1 = await client2.Hashtags.GetTrendingHashtagsWithHttpMessagesAsync(authorization : bearerToken2);

            // Clean up topics
            await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse1.Body.TopicHandle, bearerToken1);

            await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse2.Body.TopicHandle, bearerToken2);

            // Clean up users
            HttpOperationResponse <object> deleteUser1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken1);

            HttpOperationResponse <object> deleteUser2 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : bearerToken2);

            // Validate the trending part - don't assume order or counts as "dirty" data could affect verification
            Assert.IsTrue(trendingResponse1.Response.IsSuccessStatusCode);
            Assert.IsNotNull(trendingResponse1, "Failed to get trending hashtags");
            Assert.IsNotNull(trendingResponse1.Body, "Failed to get trending hashtags");

            Assert.IsTrue(trendingResponse1.Body.Contains("#" + guidstring), "#" + guidstring + " was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#food"), "#food was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#sports"), "#sports was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#NFL"), "#NFL was not found in the results");
        }
Ejemplo n.º 10
0
        public async Task SearchTopicsTest()
        {
            // generate unique string
            string searchWord = "#" + Guid.NewGuid().ToString().Replace("-", string.Empty);

            // create user
            SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse;
            string           firstName = "FirstUser";
            string           lastName  = "FirstUserLastName";
            string           bio       = string.Empty;

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

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

            // First Topic
            string           topicTitle       = string.Empty;
            string           topicText        = searchWord;
            BlobType         blobType         = BlobType.Unknown;
            string           blobHandle       = string.Empty;
            string           language         = string.Empty;
            string           deepLink         = string.Empty;
            string           categories       = string.Empty;
            string           friendlyName     = string.Empty;
            string           group            = string.Empty;
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // If the first post topic operation failed, clean up
            if (postTopicOperationResponse == null || postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to post first topic");
            }

            // Large delay to increase the difference in freshness between the two topics.
            // Search results are influenced by weight (not used right now), freshness, and relevance.
            // Azure Search's relevance score seems to vary a little bit even though both topics here
            // are exactly the same. By increasing the freshness difference, these small variations in
            // relevance score get washed out, and this test will pass deterministically.
            await Task.Delay(10 *TestConstants.SearchDelay);

            // create a second Topic
            string           topicTitle2       = string.Empty;
            string           topicText2        = searchWord;
            PostTopicRequest postTopicRequest2 = new PostTopicRequest(publisherType: PublisherType.User, text: topicText2, title: topicTitle2, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : auth);

            // If the second post topic operation failed, clean up
            if (postTopicOperationResponse2 == null || postTopicOperationResponse2.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse2.Body.TopicHandle))
            {
                await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse.Body.TopicHandle, auth);

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

                Assert.Fail("Failed to post second topic");
            }

            // Delay a bit to allow data to get into the search
            await Task.Delay(TestConstants.SearchDelay);

            // Only one result
            HttpOperationResponse <FeedResponseTopicView> search1 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : searchWord, cursor : null, limit : 1, authorization : auth);

            // Now get the second one after that cursor
            HttpOperationResponse <FeedResponseTopicView> search2 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : searchWord, cursor : int.Parse(search1.Body.Cursor), limit : 1, authorization : auth);

            // Now get all in one
            HttpOperationResponse <FeedResponseTopicView> search3 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : searchWord, cursor : null, limit : 2, authorization : auth);

            // Delete topics and see if search works
            HttpOperationResponse <object> deleteTopic1 = await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse.Body.TopicHandle, auth);

            HttpOperationResponse <object> deleteTopic2 = await client1.Topics.DeleteTopicWithHttpMessagesAsync(postTopicOperationResponse2.Body.TopicHandle, auth);

            // now search to see if works after deleted
            HttpOperationResponse <FeedResponseTopicView> search4 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : searchWord, cursor : null, limit : 10, authorization : auth);

            // Clean up first user
            HttpOperationResponse <object> deleteUser1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Verify now - verify after all is cleaned up so any failures isn't leaving behind stuff to cause failure next time test is ran
            // Verify Search 1
            Assert.IsTrue(search1.Response.IsSuccessStatusCode);
            Assert.AreEqual(search1.Body.Data.Count, 1);
            Assert.AreEqual(search1.Body.Data[0].TopicHandle, postTopicOperationResponse2.Body.TopicHandle);
            Assert.AreEqual(search1.Body.Data[0].Title, topicTitle2);
            Assert.AreEqual(search1.Body.Data[0].Text, topicText2);
            Assert.AreEqual(search1.Body.Data[0].BlobType, blobType);
            Assert.AreEqual(search1.Body.Data[0].BlobHandle, blobHandle);
            Assert.AreEqual(search1.Body.Data[0].Language, language);
            Assert.AreEqual(search1.Body.Data[0].DeepLink, deepLink);
            Assert.AreEqual(search1.Body.Data[0].Categories, categories);
            Assert.AreEqual(search1.Body.Data[0].FriendlyName, friendlyName);
            Assert.AreEqual(search1.Body.Data[0].Group, group);

            // Verify Search 2
            Assert.IsTrue(search2.Response.IsSuccessStatusCode);
            Assert.AreEqual(search2.Body.Data.Count, 1);
            Assert.AreEqual(search2.Body.Data[0].TopicHandle, postTopicOperationResponse.Body.TopicHandle);
            Assert.AreEqual(search2.Body.Data[0].Title, topicTitle);
            Assert.AreEqual(search2.Body.Data[0].Text, topicText);
            Assert.AreEqual(search2.Body.Data[0].BlobType, blobType);
            Assert.AreEqual(search2.Body.Data[0].BlobHandle, blobHandle);
            Assert.AreEqual(search2.Body.Data[0].Language, language);
            Assert.AreEqual(search2.Body.Data[0].DeepLink, deepLink);
            Assert.AreEqual(search2.Body.Data[0].Categories, categories);
            Assert.AreEqual(search2.Body.Data[0].FriendlyName, friendlyName);
            Assert.AreEqual(search2.Body.Data[0].Group, group);

            // Verify Search 3
            Assert.IsTrue(search3.Response.IsSuccessStatusCode);
            Assert.AreEqual(search3.Body.Data.Count, 2);
            Assert.AreEqual(search3.Body.Data[0].TopicHandle, postTopicOperationResponse2.Body.TopicHandle);
            Assert.AreEqual(search3.Body.Data[0].Title, topicTitle2);
            Assert.AreEqual(search3.Body.Data[0].Text, topicText2);
            Assert.AreEqual(search3.Body.Data[0].BlobType, blobType);
            Assert.AreEqual(search3.Body.Data[0].BlobHandle, blobHandle);
            Assert.AreEqual(search3.Body.Data[0].Language, language);
            Assert.AreEqual(search3.Body.Data[0].DeepLink, deepLink);
            Assert.AreEqual(search3.Body.Data[0].Categories, categories);
            Assert.AreEqual(search3.Body.Data[0].FriendlyName, friendlyName);
            Assert.AreEqual(search3.Body.Data[0].Group, group);

            Assert.AreEqual(search3.Body.Data[1].TopicHandle, postTopicOperationResponse.Body.TopicHandle);
            Assert.AreEqual(search3.Body.Data[1].Title, topicTitle);
            Assert.AreEqual(search3.Body.Data[1].Text, topicText);
            Assert.AreEqual(search3.Body.Data[1].BlobType, blobType);
            Assert.AreEqual(search3.Body.Data[1].BlobHandle, blobHandle);
            Assert.AreEqual(search3.Body.Data[1].Language, language);
            Assert.AreEqual(search3.Body.Data[1].DeepLink, deepLink);
            Assert.AreEqual(search3.Body.Data[1].Categories, categories);
            Assert.AreEqual(search3.Body.Data[1].FriendlyName, friendlyName);
            Assert.AreEqual(search3.Body.Data[1].Group, group);

            // Verify Search 4
            Assert.IsTrue(search4.Response.IsSuccessStatusCode);
            Assert.AreEqual(search4.Body.Data.Count, 0);

            // Verify deletions
            Assert.IsTrue(deleteTopic1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopic2.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUser1.Response.IsSuccessStatusCode);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Create a new topic
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='request'>
 /// Post topic 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 PostTopicResponse PostTopic(this ITopics operations, PostTopicRequest request, string authorization)
 {
     return(Task.Factory.StartNew(s => ((ITopics)s).PostTopicAsync(request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a topic, like it, verify by doing a GetTopic, then delete the like
        /// </summary>
        /// <param name="appPublished">flag to indicate that topic is appPublished</param>
        /// <param name="appHandle">app handle</param>
        /// <returns>Fail if an exception is hit</returns>
        public async Task LikeTopicHelper(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");
                }
            }

            // create a topic
            string   topicTitle   = "Topic for Like Test";
            string   topicText    = "Verify the likes!";
            BlobType blobType     = BlobType.Unknown;
            string   blobHandle   = "http://myBlobHandle/";
            string   language     = "en-US";
            string   deepLink     = "Like It!";
            string   categories   = "#likes";
            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 like on the Topic
            var postLikeOperationResponse = await client.TopicLikes.PostLikeWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (!postLikeOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Like of topic failed.");
            }

            // get the topic and verify by Get Topic
            var getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (!getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.TopicLikes.DeleteLikeWithHttpMessagesAsync(topicHandle : topicHandle, 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.");
            }

            // Delete the like
            var deleteLikeOperationResponse = await client.TopicLikes.DeleteLikeWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (!deleteLikeOperationResponse.Response.IsSuccessStatusCode)
            {
                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 like failed.");
            }

            // Clean up first before verifying
            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;

            // Verify as the last step
            Assert.AreEqual(getTopicResponse.Liked, true);
            Assert.AreEqual(getTopicResponse.Text, topicText);
            Assert.AreEqual(getTopicResponse.Title, topicTitle);
            Assert.AreEqual(getTopicResponse.TopicHandle, topicHandle);
            Assert.AreEqual(getTopicResponse.TotalComments, 0);
            Assert.AreEqual(getTopicResponse.TotalLikes, 1);
        }
Ejemplo n.º 13
0
        public async Task <IHttpActionResult> PostTopic([FromBody] PostTopicRequest request)
        {
            string className  = "TopicsController";
            string methodName = "PostTopic";
            string logEntry   = $"PublisherType = {request?.PublisherType}";

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

            var userProfileEntity = await this.usersManager.ReadUserProfile(this.UserHandle, this.AppHandle);

            if (userProfileEntity == null)
            {
                return(this.Unauthorized(ResponseStrings.UserNotFound));
            }

            UserVisibilityStatus visibility = userProfileEntity.Visibility;

            // app published topics can only be created by an administrator of that application
            if (request.PublisherType == PublisherType.App)
            {
                bool isAdmin = await this.appsManager.IsAdminUser(this.AppHandle, this.UserHandle);

                if (!isAdmin)
                {
                    return(this.Unauthorized(ResponseStrings.UserUnauthorized));
                }
            }

            // Define a locally-scoped userHandle. If App is PublisherType, we will set it to null
            string userHandle = this.UserHandle;

            if (request.PublisherType == PublisherType.App)
            {
                // for app published topics, we don't record the userHandle as the topic owner
                // this is because if the user who created the topic is later deleted, we do not want the topic to disappear
                userHandle = null;

                // app published topics are always public
                visibility = UserVisibilityStatus.Public;
            }

            string topicHandle = this.handleGenerator.GenerateShortHandle();

            await this.topicsManager.CreateTopic(
                ProcessType.Frontend,
                topicHandle,
                request.Title,
                request.Text,
                request.BlobType,
                request.BlobHandle,
                request.Categories,
                request.Language,
                request.Group,
                request.DeepLink,
                request.FriendlyName,
                request.PublisherType,
                userHandle,
                visibility,
                DateTime.UtcNow,
                ReviewStatus.Active,
                this.AppHandle,
                null);

            var response = new PostTopicResponse()
            {
                TopicHandle = topicHandle
            };

            logEntry += $", TopicHandle = {topicHandle}";
            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.Created <PostTopicResponse>(new Uri(this.RequestAbsoluteUri + "/" + topicHandle), response));
        }
        public async Task CreateVerifyDeleteNamedTopicTest()
        {
            HttpOperationResponse <object> deleteUserOperationResponse      = null;
            HttpOperationResponse <object> deleteTopicOperationResponse     = null;
            HttpOperationResponse <object> deleteTopicNameOperationResponse = null;
            DeleteTopicNameRequest         deleteTopicNameReq = new DeleteTopicNameRequest(publisherType: PublisherType.App);
            int endIndex = TestConstants.ConfigFileName.IndexOf(".");

            this.environment = TestConstants.ConfigFileName.Substring(0, endIndex);

            // create a user
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var t = await this.CreateUserForTest(client);

            PostUserResponse postUserResponse = t.Item1;
            string           auth             = t.Item2;
            string           userHandle       = postUserResponse.UserHandle;

            string appHandle = ManageAppsUtils.GetAppHandle(this.environment);

            if (appHandle == null)
            {
                // delete the user and fail the test
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to lookup appHandle");
            }

            // add user as admin
            bool added = ManageAppsUtils.AddAdmin(this.environment, appHandle, userHandle);

            if (!added)
            {
                // delete the user and fail the test
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

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

            // create a topic
            string           topicTitle       = "Test topic for named topics";
            string           topicText        = "This sure is a fine topic.";
            BlobType         blobType         = BlobType.Image;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = "en-US";
            string           group            = "mygroup";
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // if create topic was a success, grab the topic handle
            string topicHandle = string.Empty;

            if (postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }
            else
            {
                // otherwise, delete the admin, the user and fail the test
                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Create topic failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            string topicName = "UnitTestTopicName";

            // create a topic name
            PostTopicNameRequest           postTopicNameReq = new PostTopicNameRequest(publisherType: PublisherType.App, topicName: topicName, topicHandle: topicHandle);
            HttpOperationResponse <object> postTopicNameOperationResponse = await client.Topics.PostTopicNameWithHttpMessagesAsync(request : postTopicNameReq, authorization : auth);

            // if creating the topic name fails, delete the topic, the user, and fail the test
            if (!postTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(authorization : auth, topicHandle : topicHandle);

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Create topic name failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // get the topic name
            HttpOperationResponse <GetTopicByNameResponse> getTopicNameResponse = await client.Topics.GetTopicByNameWithHttpMessagesAsync(topicName : topicName, publisherType : PublisherType.App, authorization : auth);

            if (!getTopicNameResponse.Response.IsSuccessStatusCode)
            {
                // if get topic name fails, cleanup: delete the topic name, the admin, the user, and fail the test
                deleteTopicNameOperationResponse = await client.Topics.DeleteTopicNameWithHttpMessagesAsync(request : deleteTopicNameReq, authorization : auth, topicName : topicName);

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

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("get topic name failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // delete the topic name we just created
            deleteTopicNameOperationResponse = await client.Topics.DeleteTopicNameWithHttpMessagesAsync(request : deleteTopicNameReq, authorization : auth, topicName : topicName);

            // if deleting the topic name fails, delete the topic, the admin, the user, and fail the test
            if (!deleteTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(authorization : auth, topicHandle : topicHandle);

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Delete topic name failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // do standard cleanup : delete the topic, delete the admin, and then delete the user
            deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(authorization : auth, topicHandle : topicHandle);

            ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
            deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // if we reach here, the test was successful.
            return;
        }
        public async Task CreateUpdateDeleteNamedTopicTest()
        {
            var deleteRequest = new DeleteTopicNameRequest()
            {
                PublisherType = PublisherType.App
            };
            int endIndex = TestConstants.ConfigFileName.IndexOf(".");

            this.environment = TestConstants.ConfigFileName.Substring(0, endIndex);

            // create a user
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            var t = await this.CreateUserForTest(client);

            PostUserResponse postUserResponse = t.Item1;
            string           auth             = t.Item2;
            string           userHandle       = postUserResponse.UserHandle;

            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(this.environment);

            if (appHandle == null)
            {
                // delete the user and fail the test
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to lookup appHandle");
            }

            // add user as admin
            bool added = ManageAppsUtils.AddAdmin(this.environment, 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");
            }

            // create a topic
            string           topicTitle       = "Test topic for named topics";
            string           topicText        = "This sure is a fine topic.";
            BlobType         blobType         = BlobType.Image;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = "en-US";
            string           group            = "mygroup";
            string           topicHandle      = null;
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

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

            // create another topic
            string           topicTitle2       = "Test topic #2 for named topics";
            string           topicText2        = "This one also sure is a fine topic.";
            string           language2         = "en-US";
            string           group2            = "mygroup2";
            string           topicHandle2      = null;
            PostTopicRequest postTopicRequest2 = new PostTopicRequest(publisherType: PublisherType.User, text: topicText2, title: topicTitle2, language: language2, group: group2);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : auth);

            if (postTopicOperationResponse2.Response.IsSuccessStatusCode)
            {
                topicHandle2 = postTopicOperationResponse2.Body.TopicHandle;
            }

            if (!(postTopicOperationResponse.Response.IsSuccessStatusCode && postTopicOperationResponse2.Response.IsSuccessStatusCode))
            {
                // if either topic creation fails, cleanup:
                // delete both topics, the admin, the user and fail the test
                await client.Topics.DeleteTopicWithHttpMessagesAsync(authorization : auth, topicHandle : topicHandle);

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

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Create topics failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // create a topic name for topic #1
            string topicName = "SpecialTopicName";
            PostTopicNameRequest           postTopicNameReq = new PostTopicNameRequest(publisherType: PublisherType.App, topicName: topicName, topicHandle: topicHandle);
            HttpOperationResponse <object> postTopicNameOperationResponse = await client.Topics.PostTopicNameWithHttpMessagesAsync(request : postTopicNameReq, authorization : auth);

            if (!postTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                // if creating the topic name fails, cleanup:
                // delete both topics, the admin, the user, and fail the test
                await client.Topics.DeleteTopicWithHttpMessagesAsync(authorization : auth, topicHandle : topicHandle);

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

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Create topic name failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // update the topic name so that it now refers to topic #2
            PutTopicNameRequest            putTopicNameReq = new PutTopicNameRequest(publisherType: PublisherType.App, topicHandle: topicHandle2);
            HttpOperationResponse <object> putTopicNameOperationResponse = await client.Topics.PutTopicNameWithHttpMessagesAsync(topicName : topicName, request : putTopicNameReq, authorization : auth);

            if (!putTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                // if updating the topic name fails, cleanup
                await client.Topics.DeleteTopicNameWithHttpMessagesAsync(topicName : topicName, request : deleteRequest, authorization : auth);

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

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

                ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Put topic name failed, cannot finish the CreateVerifyUpdateDeleteNamedTopicTest");
            }

            // do the standard cleanup
            await client.Topics.DeleteTopicNameWithHttpMessagesAsync(topicName : topicName, request : deleteRequest, authorization : auth);

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

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

            ManageAppsUtils.DeleteAdmin(this.environment, appHandle, userHandle);
            await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);
        }
        /// <summary>
        /// Several types of notication test with Get Put and Count
        /// </summary>
        /// <param name="appPublished">flag to indicate if topics are app published</param>
        /// <param name="appHandle">app handle</param>
        /// <returns>Fail if an exception is hit</returns>
        public async Task GetPutCountNotificationTestHelper(bool appPublished, string appHandle)
        {
            SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client1, "Stan", "TopicMan", string.Empty);

            string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse.SessionToken);

            if (appPublished)
            {
                // add user1 as admin
                bool added = ManageAppsUtils.AddAdmin(TestConstants.EnvironmentName, appHandle, postUserResponse.UserHandle);
                if (!added)
                {
                    // delete the user and fail the test
                    await client1.Users.DeleteUserAsync(auth1);

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

            PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client2, "Emily", "Johnson", string.Empty);

            string           auth2             = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken);
            PostUserResponse postUserResponse3 = await TestUtilities.DoLogin(client3, "Johnny", "OnTheSpot", string.Empty);

            string auth3 = AuthHelper.CreateSocialPlusAuth(postUserResponse3.SessionToken);

            PublisherType     publisherType     = appPublished ? PublisherType.App : PublisherType.User;
            PostTopicRequest  postTopicRequest  = new PostTopicRequest(publisherType: publisherType, text: "Text", title: "Title", blobHandle: "BlobHandle", language: "en-US", deepLink: "link", categories: "categories", friendlyName: "friendlyName", group: "group");
            PostTopicResponse postTopicResponse = await client1.Topics.PostTopicAsync(postTopicRequest, auth1);

            // all three users like the topic that was created
            await client1.TopicLikes.PostLikeAsync(postTopicResponse.TopicHandle, auth1);

            await client2.TopicLikes.PostLikeAsync(postTopicResponse.TopicHandle, auth2);

            await client3.TopicLikes.PostLikeAsync(postTopicResponse.TopicHandle, auth3);

            if (appPublished)
            {
                // for an app published topic, the topic creator (the content owner) does not receive notifications
                // when the topic is liked.
                await Task.Delay(TestConstants.ServiceBusMediumDelay);

                FeedResponseActivityView notifications1 = await client1.MyNotifications.GetNotificationsAsync(auth1);

                notifications1 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);

                CountResponse count1 = await client1.MyNotifications.GetNotificationsCountAsync(auth1);

                // Clean up state from the test
                await client1.Topics.DeleteTopicAsync(postTopicResponse.TopicHandle, auth1);

                ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, postUserResponse.UserHandle);
                await client1.Users.DeleteUserAsync(auth1);

                await client2.Users.DeleteUserAsync(auth2);

                await client3.Users.DeleteUserAsync(auth3);

                // check that no notifications are delivered
                Assert.AreEqual(0, notifications1.Data.Count);
                Assert.AreEqual(0, count1.Count);
            }
            else
            {
                // for a user published topic, user1 (the content owner) should receive two notifications:
                // one when user2 likes the topic, and one when user3 likes the topic
                FeedResponseActivityView notifications1 = null;
                FeedResponseActivityView notifications2 = null;
                FeedResponseActivityView notifications3 = null;
                CountResponse            count1         = null;
                await TestUtilities.AutoRetryServiceBusHelper(
                    async() =>
                {
                    // get the first notification
                    notifications1 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 1);

                    // get the second notification using the first one as the cursor
                    notifications2 = await client1.MyNotifications.GetNotificationsAsync(auth1, notifications1.Cursor, 1);

                    // get up to 10 notifications
                    notifications3 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);

                    // get the count of unread notifications
                    count1 = await client1.MyNotifications.GetNotificationsCountAsync(auth1);
                },
                    () =>
                {
                    // verify
                    Assert.AreEqual(1, notifications1.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications1.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications1.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications1.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications1.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications1.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications1.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(1, notifications2.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications2.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications2.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications2.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications2.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications2.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications2.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(2, notifications3.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications3.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications3.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications3.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications3.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications3.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications3.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(2, count1.Count);
                });

                // Update which is the most recent notification the user has read
                PutNotificationsStatusRequest putNotificationStatusRequest = new PutNotificationsStatusRequest(notifications3.Data.First().ActivityHandle);
                await client1.MyNotifications.PutNotificationsStatusAsync(putNotificationStatusRequest, auth1);

                // Get Notification
                FeedResponseActivityView notifications4 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);

                var count2 = await client1.MyNotifications.GetNotificationsCountAsync(auth1);

                // User3 creates another like on the topic.  Even though this doesn't change
                // the like status because the user has already liked this topic, it does generate
                // another notification.
                await client3.TopicLikes.PostLikeAsync(postTopicResponse.TopicHandle, auth3);

                FeedResponseActivityView notifications5 = null;
                CountResponse            count3         = null;
                await TestUtilities.AutoRetryServiceBusHelper(
                    async() =>
                {
                    // Get new notifications and the count of unread notifications
                    notifications5 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);
                    count3         = await client1.MyNotifications.GetNotificationsCountAsync(auth1);
                }, () =>
                {
                    // verify
                    Assert.AreEqual(2, notifications5.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications5.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications5.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications5.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications5.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications5.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications5.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(1, count3.Count);
                });

                // User2 deletes their like on the topic.  This generates a notification
                await client2.TopicLikes.DeleteLikeAsync(postTopicResponse.TopicHandle, auth2);

                FeedResponseActivityView notifications6 = null;
                CountResponse            count4         = null;
                await TestUtilities.AutoRetryServiceBusHelper(
                    async() =>
                {
                    // Get new notifications and the count of unread notifications
                    notifications6 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);
                    count4         = await client1.MyNotifications.GetNotificationsCountAsync(auth1);
                }, () =>
                {
                    // verify
                    Assert.AreEqual(1, notifications6.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications6.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications6.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications6.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications6.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications6.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications6.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(1, count4.Count);
                });

                // User2 once again likes the topic and generates a notification
                await client2.TopicLikes.PostLikeAsync(postTopicResponse.TopicHandle, auth2);

                FeedResponseActivityView notifications7 = null;
                CountResponse            count5         = null;

                await TestUtilities.AutoRetryServiceBusHelper(
                    async() =>
                {
                    // Get new notifications and the count of unread notifications
                    notifications7 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);
                    count5         = await client1.MyNotifications.GetNotificationsCountAsync(auth1);
                }, () =>
                {
                    // verify
                    Assert.AreEqual(2, notifications7.Data.Count);
                    Assert.AreEqual(ActivityType.Like, notifications7.Data[0].ActivityType);
                    Assert.AreEqual(1, notifications7.Data[0].ActorUsers.Count);
                    Assert.AreEqual(1, notifications7.Data[0].TotalActions);
                    Assert.AreEqual(postTopicResponse.TopicHandle, notifications7.Data[0].ActedOnContent.ContentHandle);
                    Assert.AreEqual(BlobType.Unknown, notifications7.Data[0].ActedOnContent.BlobType);
                    Assert.AreEqual(ContentType.Topic, notifications7.Data[0].ActedOnContent.ContentType);

                    Assert.AreEqual(2, count5.Count);
                });

                // Update the most recent notification read
                putNotificationStatusRequest = new PutNotificationsStatusRequest(notifications7.Data.First().ActivityHandle);
                await client1.MyNotifications.PutNotificationsStatusAsync(putNotificationStatusRequest, auth1);

                // Get new notifications and the count of unread notifications
                var notifications8 = await client1.MyNotifications.GetNotificationsAsync(auth1, null, 10);

                var count6 = await client1.MyNotifications.GetNotificationsCountAsync(auth1);

                // Clean up state from the test
                await client1.Topics.DeleteTopicAsync(postTopicResponse.TopicHandle, auth1);

                await client1.Users.DeleteUserAsync(auth1);

                await client2.Users.DeleteUserAsync(auth2);

                await client3.Users.DeleteUserAsync(auth3);

                // Validate everything
                Assert.AreEqual(1, notifications1.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications1.Data[0].ActivityType);
                Assert.AreEqual(1, notifications1.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications1.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications1.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications1.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications1.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(1, notifications2.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications2.Data[0].ActivityType);
                Assert.AreEqual(1, notifications2.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications2.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications2.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications2.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications2.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, notifications3.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications3.Data[0].ActivityType);
                Assert.AreEqual(1, notifications3.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications3.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications3.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications3.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications3.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, notifications4.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications4.Data[0].ActivityType);
                Assert.AreEqual(1, notifications4.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications4.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications4.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications4.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications4.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, notifications5.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications5.Data[0].ActivityType);
                Assert.AreEqual(1, notifications5.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications5.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications5.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications5.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications5.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(1, notifications6.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications6.Data[0].ActivityType);
                Assert.AreEqual(1, notifications6.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications6.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications6.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications6.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications6.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, notifications7.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications7.Data[0].ActivityType);
                Assert.AreEqual(1, notifications7.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications7.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications7.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications7.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications7.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, notifications8.Data.Count);
                Assert.AreEqual(ActivityType.Like, notifications8.Data[0].ActivityType);
                Assert.AreEqual(1, notifications8.Data[0].ActorUsers.Count);
                Assert.AreEqual(1, notifications8.Data[0].TotalActions);
                Assert.AreEqual(postTopicResponse.TopicHandle, notifications8.Data[0].ActedOnContent.ContentHandle);
                Assert.AreEqual(BlobType.Unknown, notifications8.Data[0].ActedOnContent.BlobType);
                Assert.AreEqual(ContentType.Topic, notifications8.Data[0].ActedOnContent.ContentType);

                Assert.AreEqual(2, count1.Count);
                Assert.AreEqual(0, count2.Count);
                Assert.AreEqual(1, count3.Count);
                Assert.AreEqual(1, count4.Count);
                Assert.AreEqual(2, count5.Count);
                Assert.AreEqual(0, count6.Count);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Publish a new app-published topic with a topic name to Embedded Social
        /// </summary>
        /// <param name="topicName">name of the new topic</param>
        /// <param name="topicTitle">title of the new topic</param>
        /// <param name="topicText">text of the new topic</param>
        /// <param name="topicCategory">category of the new topic</param>
        /// <returns>task that publishes a new topic</returns>
        private async Task CreateTopic(string topicName, string topicTitle, string topicText, string topicCategory)
        {
            // format the input into an Embedded Social topic request
            PostTopicRequest topicRequest = new PostTopicRequest()
            {
                PublisherType = PublisherType.App,
                Text          = topicText,
                Title         = topicTitle,
                BlobType      = BlobType.Unknown,
                BlobHandle    = string.Empty,
                Categories    = topicCategory,
                Language      = TopicLanguage,
                DeepLink      = string.Empty,
                FriendlyName  = topicName,
                Group         = string.Empty
            };

            // publish to Embedded Social
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await this.client.Topics.PostTopicWithHttpMessagesAsync(request : topicRequest, authorization : this.authorization);

            // check response
            if (postTopicOperationResponse == null || postTopicOperationResponse.Response == null)
            {
                throw new Exception("got null response");
            }
            else if (!postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                throw new Exception("request failed with HTTP code: " + postTopicOperationResponse.Response.StatusCode + ", and reason: " + postTopicOperationResponse.Response.ReasonPhrase);
            }
            else if (postTopicOperationResponse.Body == null)
            {
                throw new Exception("got null response body");
            }
            else if (string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                throw new Exception("topicHandle is null or whitespace");
            }

            // publish the name for the topic
            string topicHandle = postTopicOperationResponse.Body.TopicHandle;
            PostTopicNameRequest topicNameRequest = new PostTopicNameRequest()
            {
                PublisherType = PublisherType.App,
                TopicName     = topicName,
                TopicHandle   = topicHandle
            };

            HttpOperationResponse postTopicNameOperationResponse = await this.client.Topics.PostTopicNameWithHttpMessagesAsync(request : topicNameRequest, authorization : this.authorization);

            // check response
            if (postTopicNameOperationResponse == null || postTopicNameOperationResponse.Response == null)
            {
                // attempt to clean up the topic first
                HttpOperationResponse deleteTopicOperationResponse = await this.client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : this.authorization);

                throw new Exception("got null response");
            }
            else if (!postTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                // attempt to clean up the topic first
                HttpOperationResponse deleteTopicOperationResponse = await this.client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : this.authorization);

                throw new Exception("request failed with HTTP code: " + postTopicNameOperationResponse.Response.StatusCode + ", and reason: " + postTopicNameOperationResponse.Response.ReasonPhrase);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Create a new topic
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='request'>
 /// Post topic 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 <PostTopicResponse> PostTopicAsync(this ITopics operations, PostTopicRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostTopicWithHttpMessagesAsync(request, authorization, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Create a topic, and issue 100 likes and unlikes on it from the same user in rapid succession
        /// </summary>
        /// <param name="unlike">if true, will also issue unlikes</param>
        /// <returns>Fail if any of the likes or unlikes result in an HTTP error</returns>
        private async Task RapidLikeTopicHelper(bool unlike)
        {
            int numLikesToIssue     = 100;
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            // create a user
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "Rapid", "Like", "Rapid Like Topic Test");

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

            // create a topic
            PostTopicRequest postTopicRequest = new PostTopicRequest()
            {
                Title         = "Rapid like topic test",
                Text          = "Rapid like topic test",
                BlobType      = BlobType.Unknown,
                BlobHandle    = string.Empty,
                Language      = string.Empty,
                DeepLink      = string.Empty,
                Categories    = string.Empty,
                FriendlyName  = string.Empty,
                Group         = string.Empty,
                PublisherType = PublisherType.User
            };
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            if (!postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);
            }

            Assert.IsTrue(postTopicOperationResponse.Response.IsSuccessStatusCode);
            string topicHandle = postTopicOperationResponse.Body.TopicHandle;

            // issue repeated likes and unlikes
            HttpOperationResponse[] postLikeOperationResponses   = new HttpOperationResponse[numLikesToIssue];
            HttpOperationResponse[] postUnLikeOperationResponses = new HttpOperationResponse[numLikesToIssue];
            for (int i = 0; i < numLikesToIssue; i++)
            {
                postLikeOperationResponses[i] = await client.TopicLikes.PostLikeWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

                if (unlike)
                {
                    postUnLikeOperationResponses[i] = await client.TopicLikes.DeleteLikeWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);
                }
            }

            // clean up
            HttpOperationResponse deleteTopicOperationResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            HttpOperationResponse deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // check for errors
            for (int i = 0; i < numLikesToIssue; i++)
            {
                Assert.IsTrue(postLikeOperationResponses[i].Response.IsSuccessStatusCode);
                if (unlike)
                {
                    Assert.IsTrue(postUnLikeOperationResponses[i].Response.IsSuccessStatusCode);
                }
            }

            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Helper routine that performs the main actions of the test.
        /// Create multiple topics.  Pin them.  Then get the pin feed, and check that all the pinned topics show up.
        /// </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 GetPinFeedTestHelper(bool appPublished, string appHandle)
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            string           firstName        = "J.J.";
            string           lastName         = "Z";
            string           bio              = string.Empty;
            PostUserResponse 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");
                }
            }

            // create topic #1
            string topicTitle = "topic number 1";
            string topicText  = "the jukebox needs to take a leak";
            string language   = "en-US";
            string deepLink   = "http://dummy/";
            string categories = "cat1, cat6";
            string group      = "mygroup";

            // step 1, create a topic and pin it
            string topicHandle      = string.Empty;
            var    postTopicRequest = new PostTopicRequest()
            {
                Text = topicText, Title = topicTitle, Categories = categories, Language = language, DeepLink = deepLink, 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)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }
            else
            {
                // cleanup: delete the user
                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

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

                Assert.Fail("Failed to post topic.");
            }

            var pinRequest = new PostPinRequest()
            {
                TopicHandle = topicHandle
            };
            var postPinOperationResponse = await client.MyPins.PostPinWithHttpMessagesAsync(authorization : auth, request : pinRequest);

            if (!postPinOperationResponse.Response.IsSuccessStatusCode)
            {
                // cleanup: delete topic #1 and delete the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to pin topic #1.");
            }

            // create topic #2 and pin it
            topicTitle = "topic number 2";
            topicText  = "the piano has been drinking";
            language   = "en-US";
            deepLink   = "http://dummy/";
            categories = "cat1, cat6";
            group      = "mygroup";

            string           topicHandle2      = string.Empty;
            PostTopicRequest postTopicRequest2 = new PostTopicRequest()
            {
                Text = topicText, Title = topicTitle, Categories = categories, Language = language, DeepLink = deepLink, Group = group
            };

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

            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse2 = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest2, authorization : auth);

            if (postTopicOperationResponse2.Response.IsSuccessStatusCode)
            {
                topicHandle2 = postTopicOperationResponse2.Body.TopicHandle;
            }
            else
            {
                // cleanup: delete topic #1 and delete the user
                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, 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("Failed to post topic #2.");
            }

            pinRequest = new PostPinRequest()
            {
                TopicHandle = topicHandle2
            };
            postPinOperationResponse = await client.MyPins.PostPinWithHttpMessagesAsync(authorization : auth, request : pinRequest);

            if (!postPinOperationResponse.Response.IsSuccessStatusCode)
            {
                // cleanup: delete topic #1, topic #2, and delete the user
                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle2, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, 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("Failed to pin topic #2.");
            }

            // create topic #3
            topicTitle = "topic number 3";
            topicText  = "the carpet needs a haircut";
            language   = "en-US";
            deepLink   = "http://dummy/";
            categories = "cat1, cat6";
            group      = "mygroup";

            string           topicHandle3      = string.Empty;
            PostTopicRequest postTopicRequest3 = new PostTopicRequest()
            {
                Text = topicText, Title = topicTitle, Categories = categories, Language = language, DeepLink = deepLink, Group = group
            };

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

            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse3 = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest3, authorization : auth);

            if (postTopicOperationResponse3.Response.IsSuccessStatusCode)
            {
                topicHandle3 = postTopicOperationResponse3.Body.TopicHandle;
            }
            else
            {
                // cleanup: delete topic #1, topic #2, and delete the user
                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle2, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, 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("Failed to post topic #3.");
            }

            pinRequest = new PostPinRequest()
            {
                TopicHandle = topicHandle3
            };
            postPinOperationResponse = await client.MyPins.PostPinWithHttpMessagesAsync(authorization : auth, request : pinRequest);

            if (!postPinOperationResponse.Response.IsSuccessStatusCode)
            {
                // cleanup: delete topic #1, topic #2, topic #3 and delete the user
                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle3, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle2, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, 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("Failed to pin topic #3.");
            }

            var pinFeedOperationResponse = await client.MyPins.GetPinsWithHttpMessagesAsync(authorization : auth);

            IList <TopicView> pinFeedResponse = null;

            if (pinFeedOperationResponse.Response.IsSuccessStatusCode)
            {
                pinFeedResponse = pinFeedOperationResponse.Body.Data;
            }
            else
            {
                // cleanup: delete topic #1, topic #2, topic #3 and delete the user
                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle3, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle2, authorization : auth);

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

                await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, 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("Failed to get the pin feed.");
            }

            // after getting the pin feed, clean up
            await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle3, authorization : auth);

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

            await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle2, authorization : auth);

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

            await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

            bool?adminDeleted = null;

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

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

            if (appPublished)
            {
                Assert.IsTrue(adminDeleted.HasValue);
                Assert.IsTrue(adminDeleted.Value);
            }

            // after clean up, check the content of the pin feed
            Assert.AreEqual(pinFeedResponse.Count, 3);
            Assert.AreEqual(pinFeedResponse[0].Title, "topic number 3");
            Assert.AreEqual(pinFeedResponse[1].Title, "topic number 2");
            Assert.AreEqual(pinFeedResponse[2].Title, "topic number 1");
        }
Ejemplo n.º 21
0
        public async Task SearchUpdatedTopicTest()
        {
            string dateString  = DateTime.UtcNow.ToFileTime().ToString();
            string searchWord1 = "OriginalText" + dateString.Substring(dateString.Length - 7);
            string searchWord2 = "UpdatedText" + dateString.Substring(dateString.Length - 7);

            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse;
            string           firstName = "FirstUser";
            string           lastName  = "FirstUserLastName";
            string           bio       = string.Empty;

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

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

            string           topicTitle       = "My Favorite Topic";
            string           originalText     = "Sports. #" + searchWord1;
            BlobType         blobType         = BlobType.Image;
            string           blobHandle       = "http://myBlobHandle/";
            string           language         = "en-US";
            string           deepLink         = "Sports!";
            string           categories       = "sports, ncurrency";
            string           friendlyName     = "Game On!";
            string           group            = "mygroup";
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: originalText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // If the post topic operation failed, clean up
            if (postTopicOperationResponse == null || !postTopicOperationResponse.Response.IsSuccessStatusCode || postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to post topic");
            }

            string topicHandle = postTopicOperationResponse.Body.TopicHandle;

            string                updatedText               = "Movies. #" + searchWord2;
            PutTopicRequest       putTopicRequest           = new PutTopicRequest(text: updatedText, title: topicTitle, categories: categories);
            HttpOperationResponse putTopicOperationResponse = await client.Topics.PutTopicWithHttpMessagesAsync(topicHandle, request : putTopicRequest, authorization : auth);

            // If the put topic operation failed, clean up
            if (putTopicOperationResponse == null || !putTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

                Assert.Fail("Failed to update topic");
            }

            // Delay a bit to allow data to get into the search
            await Task.Delay(TestConstants.SearchDelay);

            // Search on original text
            HttpOperationResponse <FeedResponseTopicView> search1 = await client.Search.GetTopicsWithHttpMessagesAsync(query : searchWord1, cursor : null, authorization : auth);

            // Search on updated text
            HttpOperationResponse <FeedResponseTopicView> search2 = await client.Search.GetTopicsWithHttpMessagesAsync(query : searchWord2, cursor : null, authorization : auth);

            // Clean up topic
            HttpOperationResponse <object> deleteTopic = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            // Clean up user
            HttpOperationResponse <object> deleteUser = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Verify now - verify after cleanup so that failed asserts don't cause data to be left behind and interfere with future tests
            // Verify Search 1
            Assert.IsTrue(search1.Response.IsSuccessStatusCode);
            Assert.AreEqual(search1.Body.Data.Count, 0);

            // Verify Search 2
            Assert.IsTrue(search2.Response.IsSuccessStatusCode);
            Assert.AreEqual(search2.Body.Data.Count, 1);
            Assert.AreEqual(search2.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(search2.Body.Data[0].Title, topicTitle);
            Assert.AreEqual(search2.Body.Data[0].Text, updatedText);
            Assert.AreEqual(search2.Body.Data[0].BlobType, blobType);
            Assert.AreEqual(search2.Body.Data[0].BlobHandle, blobHandle);
            Assert.AreEqual(search2.Body.Data[0].Language, language);
            Assert.AreEqual(search2.Body.Data[0].DeepLink, deepLink);
            Assert.AreEqual(search2.Body.Data[0].Categories, categories);
            Assert.AreEqual(search2.Body.Data[0].FriendlyName, friendlyName);
            Assert.AreEqual(search2.Body.Data[0].Group, group);

            // Verify deletions
            Assert.IsTrue(deleteTopic.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUser.Response.IsSuccessStatusCode);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Helper routine that performs the main actions of the test.
        /// Create a topic.  Get the initial topic pin status, check that it is unpinned.  Pin it.  Check the pin status is true.
        /// Unpin it. Then check pin status is back to false.
        /// </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 PinUnPinDeletePinTestHelper(bool appPublished, string appHandle)
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            string           firstName        = "J.J.";
            string           lastName         = "Z";
            string           bio              = string.Empty;
            PostUserResponse 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   = "Rarest coin";
            string   topicText    = "Egyptian coin";
            BlobType blobType     = BlobType.Image;
            string   blobHandle   = "http://myBlobHandle/";
            string   language     = "en-US";
            string   deepLink     = "coins:abcdef";
            string   categories   = "photo, ncurrency";
            string   friendlyName = "abcde";
            string   group        = "mygroup";
            string   topicHandle  = string.Empty;

            // step 1, create a topic
            var postTopicRequest = new PostTopicRequest()
            {
                Text = topicText, Title = topicTitle, BlobType = blobType, BlobHandle = blobHandle, Categories = categories, Language = language, DeepLink = deepLink, 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)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }
            else
            {
                // cleanup: delete the user
                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

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

                Assert.Fail("Failed to post topic.");
            }

            bool?initialPinValue = null;
            bool?secondPinValue  = null;
            bool?finalPinValue   = null;

            // step 2, get the topic (and its pin status)
            var getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                initialPinValue = getTopicOperationResponse.Body.Pinned;
            }
            else
            {
                // cleanup: delete the topic and the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to get topic.");
            }

            // step 3, pin topic
            PostPinRequest postPinRequest = new PostPinRequest()
            {
                TopicHandle = topicHandle
            };
            var postPinOperationResponse = await client.MyPins.PostPinWithHttpMessagesAsync(request : postPinRequest, authorization : auth);

            if (!postPinOperationResponse.Response.IsSuccessStatusCode)
            {
                // cleanup: delete the topic and the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to pin topic.");
            }

            // step 4, get topic and its pin status again
            getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                secondPinValue = getTopicOperationResponse.Body.Pinned;
            }
            else
            {
                // cleanup: delete the topic and the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to get topic.");
            }

            // step 5, Delete Pin
            var deletePinOperationResponse = await client.MyPins.DeletePinWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (!deletePinOperationResponse.Response.IsSuccessStatusCode)
            {
                // cleanup: delete the topic and the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to delete pin.");
            }

            // step 6, get topic yet again, and check pin status to see that it is now back to false
            getTopicOperationResponse = await client.Topics.GetTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            if (getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                finalPinValue = getTopicOperationResponse.Body.Pinned;
            }
            else
            {
                // cleanup: delete the topic and the user
                await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

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

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

                Assert.Fail("Failed to get pin.");
            }

            // cleanup: delete the topic and the user
            await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth);

            bool?adminDeleted = null;

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

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

            if (appPublished)
            {
                Assert.IsTrue(adminDeleted.HasValue);
                Assert.IsTrue(adminDeleted.Value);
            }

            Assert.IsTrue(initialPinValue.HasValue);
            Assert.IsFalse(initialPinValue.Value);
            Assert.IsTrue(secondPinValue.HasValue);
            Assert.IsTrue(secondPinValue.Value);
            Assert.IsTrue(finalPinValue.HasValue);
            Assert.IsFalse(finalPinValue.Value);
        }
        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
        }
        public async Task AppPublishedTopicSearchTest()
        {
            // create the client
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName);

            if (string.IsNullOrWhiteSpace(appHandle))
            {
                // fail the test
                Assert.Fail("Failed to lookup appHandle");
            }

            // create a user
            var user = await TestUtilities.PostGenericUser(client);

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

            // get the user handle
            string userHandle = user.UserHandle;

            if (string.IsNullOrWhiteSpace(userHandle))
            {
                // fail the test
                Assert.Fail("Failed to get userHandle");
            }

            // elevate the user to 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");
            }

            // create a unique string to search on
            string unique = Guid.NewGuid().ToString().Replace("-", string.Empty);

            // post a topic published by the app
            string           topicTitle       = unique;
            string           topicText        = "Something";
            BlobType         blobType         = BlobType.Unknown;
            string           blobHandle       = string.Empty;
            string           language         = "en-US";
            string           deepLink         = string.Empty;
            string           categories       = string.Empty;
            string           friendlyName     = string.Empty;
            string           group            = string.Empty;
            PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.App, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group);
            HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth);

            // If the post topic operation failed, clean up
            if (postTopicOperationResponse == null || !postTopicOperationResponse.Response.IsSuccessStatusCode ||
                postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

                Assert.Fail("Failed to post topic");
            }

            // Delay a bit to allow data to get into the search
            await Task.Delay(TestConstants.SearchDelay);

            // search for the single result
            HttpOperationResponse <FeedResponseTopicView> search = await client.Search.GetTopicsWithHttpMessagesAsync(query : unique, cursor : null, limit : 5, authorization : auth);

            // Clean up topic
            HttpOperationResponse <object> deleteTopic = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : postTopicOperationResponse.Body.TopicHandle, authorization : auth);

            // Clean up first user
            bool deleteAdminResult = ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
            HttpOperationResponse <object> deleteUser = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Verify search result
            Assert.IsNotNull(search);
            Assert.IsNotNull(search.Body);
            Assert.IsNotNull(search.Body.Data);
            Assert.AreEqual(1, search.Body.Data.Count);
            Assert.AreEqual(postTopicOperationResponse.Body.TopicHandle, search.Body.Data[0].TopicHandle);
            Assert.AreEqual(unique, search.Body.Data[0].Title);

            // Verify deletions
            Assert.IsNotNull(deleteTopic);
            Assert.IsTrue(deleteTopic.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteAdminResult);
            Assert.IsNotNull(deleteUser);
            Assert.IsTrue(deleteUser.Response.IsSuccessStatusCode);
        }