public async Task CreateVerifyDeleteClientNameAndConfigTest()
        {
            // retrieve the developerId using ManageApps
            string developerId = ManageAppsUtils.GetDeveloperId(TestConstants.EnvironmentName);

            // create a client name and config using ManageApps
            string uniqueSuffix     = TestUtilities.CreateUniqueDigits();
            string clientName       = $"{TestConstants.EnvironmentName}-ClientNameTest{uniqueSuffix}";
            string clientSideAppKey = Guid.NewGuid().ToString();
            string clientConfigJson = "{}";
            string serverSideAppKey = ManageAppsUtils.CreateClientNameAndConfig(clientName, clientSideAppKey, clientConfigJson);

            // create a test client
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            // create user1
            var postUserResponse1 = await TestUtilities.PostGenericUser(client);

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

            if (serverSideAppKey == null)
            {
                // delete the user and fail the test
                await TestUtilities.DeleteUser(client, auth1);

                Assert.Fail("Failed to create client name and config");
            }

            // retrieve the client configuration
            var clientConfig = await client.Config.GetClientConfigWithHttpMessagesAsync(developerId, clientName);

            // delete client name and configuration
            bool deleted = ManageAppsUtils.DeleteClientNameAndConfig(clientName);

            if (!deleted)
            {
                // delete the user and fail the test
                await TestUtilities.DeleteUser(client, auth1);

                Assert.Fail("Failed to delete client name and config");
            }

            // delete the user
            await TestUtilities.DeleteUser(client, auth1);

            // Check the retrieved configuration is correct
            Assert.AreEqual(serverSideAppKey, clientConfig.Body.ServerSideAppKey);
            Assert.AreEqual(clientConfigJson, clientConfig.Body.ClientConfigJson);

            // if we reach here, the test was successful.
            return;
        }
        public async Task AppPublishedGetPutCountNotificationTest()
        {
            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName);

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

            var nt = new NotificationsTests();
            await nt.GetPutCountNotificationTestHelper(true, appHandle);
        }
        public async Task AppPublishedLikeCommentReplyDeleteTest()
        {
            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName);

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

            var lt = new LikeTests();
            await lt.LikeCommentReplyDeleteTestHelper(true, appHandle);
        }
        public async Task AppPublishedPinUnpinTest()
        {
            // get the app handle
            string appHandle = ManageAppsUtils.GetAppHandle(TestConstants.EnvironmentName);

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

            var pt = new PinTests();
            await pt.PinUnPinDeletePinTestHelper(true, appHandle);
        }
Example #5
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);
        }
Example #6
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");
        }
Example #7
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);
        }
Example #8
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);
        }
        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);
            }
        }
        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 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);
        }