Example #1
0
        public async Task LargePostOnFirstRequest()
        {
            // Set up initial login with one client
            SocialPlusClient client1          = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            string           firstName        = "Image";
            string           lastName         = "Consumer";
            string           bio              = "I like to download images";
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client1, firstName, lastName, bio);

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

            // add image to server using another client
            Uri imageUri             = new Uri("https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Bryan_Cranston_by_Gage_Skidmore_2.jpg/1024px-Bryan_Cranston_by_Gage_Skidmore_2.jpg");
            SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            HttpOperationResponse <PostImageResponse> postImageResponse = await AddImage(imageUri, ImageType.ContentBlob, client2, auth);

            // there is no delete image API call, so cannot cleanup the image from the server

            // delete the user
            HttpOperationResponse <object> deleteUserOperationResponse = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // test responses
            Assert.IsNotNull(postImageResponse);
            Assert.IsTrue(postImageResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
Example #2
0
        public async Task GetUserTest()
        {
            // Set up initial stuff
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "Fred", "Flintstone", "Rocking bedrock ...");

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

            // Call Get User
            UserProfileView getUserProfile = await client.Users.GetMyProfileAsync(auth);

            // Clean up first before verifying
            await client.Users.DeleteUserAsync(auth);

            Assert.AreEqual("Rocking bedrock ...", getUserProfile.Bio);
            Assert.AreEqual("Fred", getUserProfile.FirstName);
            Assert.AreEqual("Flintstone", getUserProfile.LastName);
            Assert.AreEqual(FollowerStatus.None, getUserProfile.FollowerStatus);
            Assert.AreEqual(FollowingStatus.None, getUserProfile.FollowingStatus);
            Assert.AreEqual(null, getUserProfile.PhotoHandle);
            Assert.AreEqual(null, getUserProfile.PhotoUrl);
            Assert.AreEqual(ProfileStatus.Active, getUserProfile.ProfileStatus);
            Assert.AreEqual(0, getUserProfile.TotalFollowers);
            Assert.AreEqual(0, getUserProfile.TotalFollowing);
            Assert.AreEqual(0, getUserProfile.TotalTopics);
            Assert.AreEqual(postUserResponse.UserHandle, getUserProfile.UserHandle);
            Assert.AreEqual(Visibility.Public, getUserProfile.Visibility);
        }
Example #3
0
        public async Task PutUserTest()
        {
            // Set up initial stuff
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "ü", "§", "╚");

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

            PutUserInfoRequest putUserInfoRequest = new PutUserInfoRequest(firstName: "Wilman", lastName: "Flinstone", bio: "Changed it up!");
            await client.Users.PutUserInfoAsync(putUserInfoRequest, auth);

            // Call Get User
            UserProfileView getUserProfile = await client.Users.GetUserAsync(postUserResponse.UserHandle, auth);

            // Clean up first before verifying
            await client.Users.DeleteUserAsync(auth);

            // Verify changes ... also verify rest to make sure nothing else wiped out
            Assert.AreEqual("Changed it up!", getUserProfile.Bio);
            Assert.AreEqual("Wilman", getUserProfile.FirstName);
            Assert.AreEqual("Flinstone", getUserProfile.LastName);
            Assert.AreEqual(FollowerStatus.None, getUserProfile.FollowerStatus);
            Assert.AreEqual(FollowingStatus.None, getUserProfile.FollowingStatus);
            Assert.AreEqual(null, getUserProfile.PhotoHandle);
            Assert.AreEqual(null, getUserProfile.PhotoUrl);
            Assert.AreEqual(ProfileStatus.Active, getUserProfile.ProfileStatus);
            Assert.AreEqual(0, getUserProfile.TotalFollowers);
            Assert.AreEqual(0, getUserProfile.TotalFollowing);
            Assert.AreEqual(0, getUserProfile.TotalTopics);
            Assert.AreEqual(postUserResponse.UserHandle, getUserProfile.UserHandle);
            Assert.AreEqual(Visibility.Public, getUserProfile.Visibility);
        }
Example #4
0
        public async Task UnfollowNotFollowedTopicTest()
        {
            // Create two users
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse user1  = await TestUtilities.PostGenericUser(client);

            string auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken);
            string auth2;

            try
            {
                PostUserResponse user2 = await TestUtilities.PostGenericUser(client);

                auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken);
            }
            catch (Exception e)
            {
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1);

                throw e;
            }

            // User 1 creates a topic
            string topicHandle;

            try
            {
                PostTopicResponse postTopicResponse = await TestUtilities.PostGenericTopic(client, auth1);

                topicHandle = postTopicResponse.TopicHandle;
            }
            catch (Exception e)
            {
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1);

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

                throw e;
            }

            // User 2 who is not following that topic, tries to unfollow the topic
            HttpOperationResponse deleteFollowingTopicResponse = await client.MyFollowing.DeleteFollowingTopicWithHttpMessagesAsync(topicHandle, auth2);

            // cleanup
            HttpOperationResponse deleteTopicResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1);

            HttpOperationResponse deleteUserOperationResponse1 = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1);

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

            // check results
            Assert.IsFalse(deleteFollowingTopicResponse.Response.IsSuccessStatusCode);
            Assert.AreEqual(deleteFollowingTopicResponse.Response.StatusCode, System.Net.HttpStatusCode.NotFound);
            Assert.IsTrue(deleteTopicResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
        }
        public async Task CommentReport()
        {
            // create two users
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

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

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

            // create a topic from user 1
            var postTopicOperationResponse = await TestUtilities.PostGenericTopic(client, auth1);

            var topicHandle = postTopicOperationResponse.TopicHandle;

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

            var commentHandle = postCommentOperationResponse.CommentHandle;

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

            // issue another report from user 2
            PostReportRequest postReportRequest2 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postCommentReportOperationResponse2 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postReportRequest2, authorization : auth2);

            // delete comment
            var deleteCommentOperationResponse = await TestUtilities.DeleteComment(client, commentHandle, auth1);

            // delete topic
            var deleteTopicOperationResponse = await TestUtilities.DeleteTopic(client, topicHandle, auth1);

            // issue another report from user 2 that should fail
            PostReportRequest postReportRequest3 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postCommentReportOperationResponse3 = await client.CommentReports.PostReportWithHttpMessagesAsync(commentHandle : commentHandle, postReportRequest : postReportRequest3, authorization : auth2);

            // delete users
            var deleteUserOperationResponse1 = await TestUtilities.DeleteUser(client, auth1);

            var deleteUserOperationResponse2 = await TestUtilities.DeleteUser(client, auth2);

            // check failure conditions
            Assert.IsTrue(postCommentReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postCommentReportOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteCommentOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsFalse(postCommentReportOperationResponse3.Response.IsSuccessStatusCode);
            Assert.AreEqual(postCommentReportOperationResponse3.Response.StatusCode, System.Net.HttpStatusCode.NotFound);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
        }
Example #6
0
        /// <summary>
        /// Check that result of post user is Created (201), and that the user handle returned is matches
        /// the one passed found in the UserPrincipal.
        /// </summary>
        /// <param name="actionResultPostUser">result of create user operation</param>
        public void CheckPostUserResult201(IHttpActionResult actionResultPostUser)
        {
            // Check that create user worked
            Assert.IsInstanceOfType(actionResultPostUser, typeof(CreatedNegotiatedContentResult <PostUserResponse>));
            PostUserResponse postUserResponse = (actionResultPostUser as CreatedNegotiatedContentResult <PostUserResponse>).Content;

            if (this.UserPrincipal.UserHandle != null)
            {
                Assert.AreEqual(this.UserPrincipal.UserHandle, postUserResponse.UserHandle);
            }
        }
        /// <summary>
        /// helper routine to create a user for named topics tests
        /// </summary>
        /// <param name="client">social plus client</param>
        /// <returns>a post user response and an authorization header value</returns>
        private async Task <Tuple <PostUserResponse, string> > CreateUserForTest(SocialPlusClient client)
        {
            string           firstName        = "Joe";
            string           lastName         = "Blow";
            string           bio              = "Joe Joe Joe";
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, firstName, lastName, bio);

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

            return(new Tuple <PostUserResponse, string>(postUserResponse, auth));
        }
Example #8
0
        public async Task GetUserTestUsingHandle()
        {
            // Set up initial stuff
            SocialPlusClient client1           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            SocialPlusClient client2           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client1, "Fred", "Flintstone", "Rocking bedrock ...");

            PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client2, "Barney", "Rubble", "Being Fred's sidekick");

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

            // Call Get User for first one
            UserProfileView getUserProfile1 = await client1.Users.GetUserAsync(postUserResponse1.UserHandle, auth1);

            // Call Get User for Second one
            UserProfileView getUserProfile2 = await client1.Users.GetUserAsync(postUserResponse2.UserHandle, auth1);

            // Clean up first before verifying
            await client1.Users.DeleteUserAsync(auth1);

            await client2.Users.DeleteUserAsync(auth2);

            // Verify first one
            Assert.AreEqual("Rocking bedrock ...", getUserProfile1.Bio);
            Assert.AreEqual("Fred", getUserProfile1.FirstName);
            Assert.AreEqual("None", getUserProfile1.FollowerStatus.ToString());
            Assert.AreEqual("None", getUserProfile1.FollowingStatus.ToString());
            Assert.AreEqual("Flintstone", getUserProfile1.LastName);
            Assert.AreEqual(null, getUserProfile1.PhotoHandle);
            Assert.AreEqual(null, getUserProfile1.PhotoUrl);
            Assert.AreEqual(ProfileStatus.Active, getUserProfile1.ProfileStatus);
            Assert.AreEqual(0, getUserProfile1.TotalFollowers);
            Assert.AreEqual(0, getUserProfile1.TotalFollowing);
            Assert.AreEqual(0, getUserProfile1.TotalTopics);
            Assert.AreEqual(postUserResponse1.UserHandle, getUserProfile1.UserHandle);
            Assert.AreEqual(Visibility.Public, getUserProfile1.Visibility);

            // Verify second one
            Assert.AreEqual("Being Fred's sidekick", getUserProfile2.Bio);
            Assert.AreEqual("Barney", getUserProfile2.FirstName);
            Assert.AreEqual(FollowerStatus.None, getUserProfile2.FollowerStatus);
            Assert.AreEqual(FollowingStatus.None, getUserProfile2.FollowingStatus);
            Assert.AreEqual("Rubble", getUserProfile2.LastName);
            Assert.AreEqual(null, getUserProfile2.PhotoHandle);
            Assert.AreEqual(null, getUserProfile1.PhotoUrl);
            Assert.AreEqual(ProfileStatus.Active, getUserProfile2.ProfileStatus);
            Assert.AreEqual(0, getUserProfile2.TotalFollowers);
            Assert.AreEqual(0, getUserProfile2.TotalFollowing);
            Assert.AreEqual(0, getUserProfile2.TotalTopics);
            Assert.AreEqual(postUserResponse2.UserHandle, getUserProfile2.UserHandle);
            Assert.AreEqual(Visibility.Public, getUserProfile2.Visibility);
        }
Example #9
0
        public async Task CreateDeleteUserTest()
        {
            // Set up initial stuff
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "Joseph", "Johnson", "Some Bio");

            string auth = AuthHelper.CreateSocialPlusAuth(postUserResponse.SessionToken);
            await client.Users.DeleteUserAsync(auth);

            // Test that PostUser returns a non-null and non-empty user handle and session token
            Assert.IsFalse(string.IsNullOrEmpty(postUserResponse.UserHandle));
            Assert.IsFalse(string.IsNullOrEmpty(postUserResponse.SessionToken));
        }
Example #10
0
        public async Task CreateDeleteSessionTest()
        {
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "Barack", "Obama", "president");

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

            // Delete session (corresponding to log off)
            await client.Sessions.DeleteSessionAsync(authorization : auth);

            // Create session (corresponding to log on)
            PostSessionRequest postSessionRequest = new PostSessionRequest("E2Etests", postUserResponse.UserHandle);
            var postSessionResponse = await client.Sessions.PostSessionWithHttpMessagesAsync(postSessionRequest, auth);

            // Delete user
            string newAuth = AuthHelper.CreateSocialPlusAuth(postSessionResponse.Body.SessionToken);
            await client.Users.DeleteUserAsync(authorization : newAuth);
        }
        public async Task UserReport()
        {
            // create two users
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserResponse postUserResponse1 = await TestUtilities.PostGenericUser(client);

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

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

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

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

            // issue another report from user 1 that should fail
            PostReportRequest postReportRequest3 = new PostReportRequest(Reason.Other);
            HttpOperationResponse <object> postUserReportOperationResponse3 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest3, authorization : auth1);

            // delete user 1
            var deleteUserOperationResponse1 = await TestUtilities.DeleteUser(client, auth1);

            // issue another report from user 2 that should fail
            PostReportRequest postReportRequest4 = new PostReportRequest(Reason.OffensiveContent);
            HttpOperationResponse <object> postUserReportOperationResponse4 = await client.UserReports.PostReportWithHttpMessagesAsync(userHandle : postUserResponse1.UserHandle, postReportRequest : postReportRequest4, authorization : auth2);

            // delete user 2
            var deleteUserOperationResponse2 = await TestUtilities.DeleteUser(client, auth2);

            // check failure conditions
            Assert.IsTrue(postUserReportOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(postUserReportOperationResponse2.Response.IsSuccessStatusCode);
            Assert.IsFalse(postUserReportOperationResponse3.Response.IsSuccessStatusCode);
            Assert.AreEqual(postUserReportOperationResponse3.Response.StatusCode, System.Net.HttpStatusCode.Unauthorized);
            Assert.IsFalse(postUserReportOperationResponse4.Response.IsSuccessStatusCode);
            Assert.AreEqual(postUserReportOperationResponse4.Response.StatusCode, System.Net.HttpStatusCode.NotFound);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode);
        }
Example #12
0
        public async Task GetNullUserTest()
        {
            // create a client
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

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

            // call get user with null user handle argument
            var getUserResponse = await client.Users.GetUserWithHttpMessagesAsync(null, auth);

            // clean up: delete the user
            await TestUtilities.DeleteUser(client, auth);

            // check that get user returns not found
            Assert.AreEqual(HttpStatusCode.NotFound, getUserResponse.Response.StatusCode);
        }
Example #13
0
        public async Task LoadCreateDeleteUserTest()
        {
            // number of users
            int numUsers = 100;

            TimeSpan threeMinutes = new TimeSpan(0, 3, 0);

            SocialPlusClient[]        clients   = new SocialPlusClient[numUsers];
            Task <PostUserResponse>[] t         = new Task <PostUserResponse> [numUsers];
            PostUserResponse[]        responses = new PostUserResponse[numUsers];

            for (int i = 0; i < numUsers; i += 1)
            {
                clients[i] = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

                // Add another three minutes to the timeout defaults of these clients. We don't want them to timeout early.
                ////api[i].IncrementHttpTimeout(threeMinutes);
            }

            for (int i = 0; i < numUsers; i += 1)
            {
                t[i] = TestUtilities.PostGenericUser(clients[i]);
            }

            for (int i = 0; i < numUsers; i += 1)
            {
                t[i].Wait();
                responses[i] = (PostUserResponse)t[i].Result;

                // Write to the console the user handle and the last 10 chars of the session token (no need to write the whole session token)
                string sessionTokenSuffix = responses[i].SessionToken.Substring(responses[i].SessionToken.Length - 10);
                Console.WriteLine("{0}: UserHandle: {1}; SessionToken: ...{2} created.", i, responses[i].UserHandle, sessionTokenSuffix);
            }

            // Cleanup
            for (int i = 0; i < numUsers; i += 1)
            {
                // final clean up
                var   auth = AuthHelper.CreateSocialPlusAuth(responses[i].SessionToken);
                await clients[i].Users.DeleteUserAsync(auth);
            }
        }
Example #14
0
        public async Task PostUserAsync_ShouldSucceed()
        {
            PostUserResponse postResponse = await _userClient.PostUserAsync(
                new PostUserBody()
            {
                User   = _fixture.UsernameToCreate,
                Passwd = "password",
                Extra  = new Dictionary <string, object>()
                {
                    ["somedata"] = "here"
                }
            });

            Assert.False(postResponse.Error);
            Assert.Equal(HttpStatusCode.Created, postResponse.Code);
            Assert.Equal(_fixture.UsernameToCreate, postResponse.User);
            Assert.True(postResponse.Active);
            Assert.True(postResponse.Extra.ContainsKey("somedata"));
            Assert.Equal("here", postResponse.Extra["somedata"].ToString());
        }
Example #15
0
        /// <summary>
        /// Create synthetic users
        /// </summary>
        /// <param name="client">a valid SocialPlusClient</param>
        /// <param name="numUsers">the number of users to create</param>
        /// <returns>a list of UserInfo objects corresponding to the created users</returns>
        private static async Task <List <UserInfo> > CreateUsers(SocialPlusClient client, int numUsers)
        {
            List <UserInfo> users = new List <UserInfo>();

            for (int userIndex = 0; userIndex < numUsers; userIndex++)
            {
                string           firstName = "UserFirst" + userIndex;
                string           lastName  = "UserLast" + userIndex;
                string           bio       = string.Empty;
                PostUserResponse response  = await TestUtilities.DoLogin(client, firstName, lastName, bio);

                UserInfo userInfo = default(UserInfo);
                userInfo.UserHandle  = response.UserHandle;
                userInfo.BearerToken = "Bearer " + response.SessionToken;
                userInfo.UserIndex   = userIndex;
                users.Add(userInfo);
            }

            return(users);
        }
Example #16
0
        public async Task <ActionResult <PostUserResponse> > CreateUser([FromBody] PostUserRequest postUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new PostUserResponse()));
            }

            try
            {
                var oktaUser = await _oktaClient.Users.GetUserAsync(postUser.Email);

                if (oktaUser == null)
                {
                    var response = new PostUserResponse();
                    response.AddError(nameof(PostUserRequest.Email), "Okta User doesn't exist for email");
                    return(BadRequest(response));
                }

                var userToCreate = new MeUser
                {
                    OktaId    = oktaUser.Id,
                    FirstName = oktaUser.Profile.FirstName,
                    LastName  = oktaUser.Profile.LastName,
                    Email     = oktaUser.Profile.Email,
                };

                var currentUser = await CurrentUser();

                var createdUser = await _userCreationService.Handle(new CreateUserQuery(userToCreate, currentUser));

                return(Ok(Mapper.Map <PostUserResponse>(createdUser)));
            }
            catch (DocumentClientException)
            {
                return(NotFound(new PostUserResponse()));
            }
            catch (ArgumentException)
            {
                return(NotFound(new PostUserResponse()));
            }
        }
Example #17
0
        public async Task AnonGetUserTest()
        {
            // create a client
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

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

            // fetch the profile of the user we just created using anonymous auth
            string anonAuth        = TestUtilities.GetAnonAuth();
            var    getUserResponse = await client.Users.GetUserWithHttpMessagesAsync(createdUser, anonAuth);

            // clean up: delete the user
            await TestUtilities.DeleteUser(client, auth);

            // check that user handle returned by post user matched that returned by get user
            Assert.AreEqual(getUserResponse.Response.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(getUserResponse.Body.UserHandle, createdUser);
        }
Example #18
0
        public async Task UpdateUserPhotoTest()
        {
            // Set up initial stuff
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, "ü", "§", "╚");

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

            // Call Put User
            string photoURL = "myPics.org//Selfie.jpg";
            PutUserPhotoRequest putUserPhotoRequest = new PutUserPhotoRequest(photoURL);
            await client.Users.PutUserPhotoAsync(putUserPhotoRequest, auth);

            // Call Get User
            UserProfileView getUserProfile = await client.Users.GetUserAsync(postUserResponse.UserHandle, auth);

            // Clean up first before verifying
            await client.Users.DeleteUserAsync(auth);

            // Verify changes ... also verify rest to make sure nothing else wiped out
            Assert.AreEqual("╚", getUserProfile.Bio);
            Assert.AreEqual("ü", getUserProfile.FirstName);
            Assert.AreEqual("§", getUserProfile.LastName);
            Assert.AreEqual(FollowerStatus.None, getUserProfile.FollowerStatus);
            Assert.AreEqual(FollowingStatus.None, getUserProfile.FollowingStatus);
            Assert.AreEqual(photoURL, getUserProfile.PhotoHandle);
            if (getUserProfile.PhotoUrl.Contains("images/" + photoURL) == false)
            {
                Assert.Fail("'images'" + photoURL + " should be contained in this: " + getUserProfile.PhotoUrl);
            }

            Assert.AreEqual(ProfileStatus.Active, getUserProfile.ProfileStatus);
            Assert.AreEqual(0, getUserProfile.TotalFollowers);
            Assert.AreEqual(0, getUserProfile.TotalFollowing);
            Assert.AreEqual(0, getUserProfile.TotalTopics);
            Assert.AreEqual(postUserResponse.UserHandle, getUserProfile.UserHandle);
            Assert.AreEqual(Visibility.Public, getUserProfile.Visibility);
        }
        public async Task ManualReportTesting()
        {
            // WARNING: do not run this test unless you are doing a test where you can tolerate 1-3 days of latency
            // and can manually verify the result by inspecting Azure Tables
            Assert.IsTrue(false);

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

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

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

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

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

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

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

            string topicHandle = null;

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

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

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

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

            var commentHandle = postCommentOperationResponse.CommentHandle;

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

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

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

            string replyHandle = null;

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

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

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

            // do NOT clean up the users after the test ends
        }
Example #20
0
        public async Task PostGetLikeDeleteCommentTest()
        {
            // create 2 users
            SocialPlusClient client            = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            string           firstName         = "Stan";
            string           lastName          = "TopicMan";
            string           bio               = string.Empty;
            PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client, firstName, lastName, bio);

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

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

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

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

            string topicHandle = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // check comment 2 in comment feed 2 (only one in the feed)
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].BlobHandle, postCommentRequest2.BlobHandle);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].BlobType, BlobType.Unknown);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse2.Body.Data[0].BlobUrl));
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].CommentHandle, commentHandle2);
            Assert.IsTrue(getCommentsOperationResponse2.Body.Data[0].ContentStatus == ContentStatus.Active || getCommentsOperationResponse2.Body.Data[0].ContentStatus == ContentStatus.Clean);
            Assert.IsTrue(string.IsNullOrEmpty(getCommentsOperationResponse2.Body.Data[0].Language));
            Assert.IsFalse(getCommentsOperationResponse2.Body.Data[0].Liked);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].Text, postCommentRequest2.Text);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TopicHandle, topicHandle);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TotalLikes, 1);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].TotalReplies, 0);
            Assert.AreEqual(getCommentsOperationResponse2.Body.Data[0].User.UserHandle, postUserResponse1.UserHandle);
        }
Example #21
0
        public async Task BatchTestMultiGetTopics()
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

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

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

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

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

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

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

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

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

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

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

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

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

            await client.Users.DeleteUserWithHttpMessagesAsync(auth);

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

            Assert.AreEqual(categories, topicResult2.Body.Categories);
            Assert.AreEqual(ContentStatus.Active, topicResult2.Body.ContentStatus);
            Assert.AreEqual(deepLink, topicResult2.Body.DeepLink);
            Assert.AreEqual(friendlyName, topicResult2.Body.FriendlyName);
            Assert.AreEqual(group, topicResult2.Body.Group);
            Assert.AreEqual(language, topicResult2.Body.Language);
            Assert.AreEqual(false, topicResult2.Body.Liked);
            Assert.AreEqual(false, topicResult2.Body.Pinned);
            Assert.AreEqual(PublisherType.User, topicResult2.Body.PublisherType);
            Assert.AreEqual(topicText2, topicResult2.Body.Text);
            Assert.AreEqual(topicTitle2, topicResult2.Body.Title);
            Assert.AreEqual(topicHandle2, topicResult2.Body.TopicHandle);
            Assert.AreEqual(0, topicResult2.Body.TotalComments);
            Assert.AreEqual(0, topicResult2.Body.TotalLikes);
            Assert.AreEqual(firstName, topicResult2.Body.User.FirstName);
            Assert.AreEqual(lastName, topicResult2.Body.User.LastName);
            Assert.AreEqual(postUserResponse.UserHandle, topicResult2.Body.User.UserHandle);
        }
Example #22
0
        /// <summary>
        /// Helper routine that performs the main actions of the test.
        /// Create a topic.  Get the initial topic pin status, check that it is unpinned.  Pin it.  Check the pin status is true.
        /// Unpin it. Then check pin status is back to false.
        /// </summary>
        /// <param name="appPublished">flag to indicate if topic is app published</param>
        /// <param name="appHandle">app handle</param>
        /// <returns>Fail if an exception is hit</returns>
        public async Task PinUnPinDeletePinTestHelper(bool appPublished, string appHandle)
        {
            // Set up initial login etc
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

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

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

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

            string   topicTitle   = "Rarest coin";
            string   topicText    = "Egyptian coin";
            BlobType blobType     = BlobType.Image;
            string   blobHandle   = "http://myBlobHandle/";
            string   language     = "en-US";
            string   deepLink     = "coins:abcdef";
            string   categories   = "photo, ncurrency";
            string   friendlyName = "abcde";
            string   group        = "mygroup";
            string   topicHandle  = string.Empty;

            // step 1, create a topic
            var postTopicRequest = new PostTopicRequest()
            {
                Text = topicText, Title = topicTitle, BlobType = blobType, BlobHandle = blobHandle, Categories = categories, Language = language, DeepLink = deepLink, FriendlyName = friendlyName, Group = group
            };

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

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

            if (postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                topicHandle = postTopicOperationResponse.Body.TopicHandle;
            }
            else
            {
                // cleanup: delete the user
                if (appPublished)
                {
                    ManageAppsUtils.DeleteAdmin(TestConstants.EnvironmentName, appHandle, userHandle);
                }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            bool?adminDeleted = null;

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

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

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

            Assert.IsTrue(initialPinValue.HasValue);
            Assert.IsFalse(initialPinValue.Value);
            Assert.IsTrue(secondPinValue.HasValue);
            Assert.IsTrue(secondPinValue.Value);
            Assert.IsTrue(finalPinValue.HasValue);
            Assert.IsFalse(finalPinValue.Value);
        }
        public async Task TrendingHashTagsTest()
        {
            // Create users
            SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

            string bearerToken1 = "Bearer " + postUserResponse1.SessionToken;

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

            string bearerToken2 = "Bearer " + postUserResponse2.SessionToken;

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

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

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

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

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

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

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

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

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

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

            await Task.Delay(TestConstants.SearchDelay);

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

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

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

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

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

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

            Assert.IsTrue(trendingResponse1.Body.Contains("#" + guidstring), "#" + guidstring + " was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#food"), "#food was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#sports"), "#sports was not found in the results");
            Assert.IsTrue(trendingResponse1.Body.Contains("#NFL"), "#NFL was not found in the results");
        }
Example #24
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 #25
0
        /// <summary>
        /// Create a topic, and issue 100 likes and unlikes on it from the same user in rapid succession
        /// </summary>
        /// <param name="unlike">if true, will also issue unlikes</param>
        /// <returns>Fail if any of the likes or unlikes result in an HTTP error</returns>
        private async Task RapidLikeTopicHelper(bool unlike)
        {
            int numLikesToIssue     = 100;
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

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

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

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

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

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

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

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

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

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

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

            Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);
        }
Example #26
0
        public async Task <IHttpActionResult> PostUser([FromBody] PostUserRequest request)
        {
            string className  = "UsersController";
            string methodName = "PostUser";

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

            // 1. Construct the user principal for the new user. An incoming request always has a user principal. However the user
            // principal might or might not have an empty user handle. For example, Beihai requests have non-empty user handles.
            UserPrincipal userPrincipal = this.UserPrincipal;

            if (userPrincipal.UserHandle == null)
            {
                // Use the identity provider and account id from the user principal except if the identity provider type is AADS2S.
                // In that case, the userhandle also acts as the account id
                string userHandle = this.handleGenerator.GenerateShortHandle();
                if (this.UserPrincipal.IdentityProvider == IdentityProviderType.AADS2S)
                {
                    userPrincipal = new UserPrincipal(this.log, userHandle, IdentityProviderType.AADS2S, userHandle);
                }
                else
                {
                    userPrincipal = new UserPrincipal(this.log, userHandle, this.UserPrincipal.IdentityProvider, this.UserPrincipal.IdentityProviderAccountId);
                }
            }

            // 2. Check whether a user profile for the application calling us exists. If so, return a conflict error message
            var userProfileEntity = await this.usersManager.ReadUserProfile(userPrincipal.UserHandle, this.AppHandle);

            if (userProfileEntity != null)
            {
                this.log.LogError(string.Format("Conflict on PostUser: user profile for this app already exists.  UserHandle={0}, AppHandle={1}", userPrincipal.UserHandle, this.AppHandle));
                return(this.Conflict(ResponseStrings.UserExists));
            }

            // 3. Check whether this user has profiles registered with any applications other than the one calling us.
            //    In that case, we shouldn't need to create the user (we just need to create a user profile).
            //    Othwerwise, create the user (which also creates the user profile).
            var linkedAccountEntities = await this.usersManager.ReadLinkedAccounts(userPrincipal.UserHandle);

            if (linkedAccountEntities.Count == 0)
            {
                // Create the user using SocialPlus identity provider space
                await this.usersManager.CreateUserAndUserProfile(
                    ProcessType.Frontend,
                    userPrincipal.UserHandle,
                    IdentityProviderType.SocialPlus,
                    userPrincipal.UserHandle,
                    this.AppHandle,
                    request.FirstName,
                    request.LastName,
                    request.Bio,
                    request.PhotoHandle,
                    DateTime.UtcNow,
                    null);

                // Also create a linked account in the third-party identity provider space
                await this.usersManager.CreateLinkedAccount(ProcessType.Frontend, userPrincipal);
            }
            else
            {
                await this.usersManager.CreateUserProfile(
                    ProcessType.Frontend,
                    userPrincipal.UserHandle,
                    this.AppHandle,
                    request.FirstName,
                    request.LastName,
                    request.Bio,
                    request.PhotoHandle,
                    DateTime.UtcNow,
                    null);
            }

            // 4. Generate session token
            string sessionToken = await this.tokenManager.CreateToken(this.AppPrincipal, userPrincipal, this.sessionTokenDuration);

            PostUserResponse response = new PostUserResponse()
            {
                UserHandle   = userPrincipal.UserHandle,
                SessionToken = sessionToken
            };

            // Log added user to app metrics
            this.applicationMetrics.AddUser();

            string logEntry = $"UserHandle = {response.UserHandle}";

            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.Created <PostUserResponse>(userPrincipal.UserHandle, response));
        }
        public async Task BlobTest_PostAndGet()
        {
            // Set up initial login
            SocialPlusClient client           = new SocialPlusClient(TestConstants.ServerApiBaseUrl);
            string           firstName        = "Image";
            string           lastName         = "Consumer";
            string           bio              = "I like to download images";
            PostUserResponse postUserResponse = await TestUtilities.DoLogin(client, firstName, lastName, bio);

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

            try
            {
                var blobUri = new Uri("https://upload.wikimedia.org/wikipedia/commons/5/51/Just_major_triad_on_C.mid");

                // fetch the blob
                using (var httpClient = new HttpClient())
                {
                    using (var responseMessage = await httpClient.GetAsync(blobUri))
                    {
                        HttpOperationResponse <PostBlobResponse> postBlobResponse;
                        long originalBlobSize = 0;
                        long newBlobSize      = 0;

                        if (!responseMessage.IsSuccessStatusCode)
                        {
                            // test fails if we cannot download the blob
                            Assert.Fail("Cannot download blob");
                        }

                        using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync())
                        {
                            MemoryStream memoryStream1 = responseStream as MemoryStream;
                            originalBlobSize = memoryStream1.Length;

                            // submit the POST request
                            postBlobResponse = await client.Blobs.PostBlobWithHttpMessagesAsync(authorization : auth, blob : responseStream);
                        }

                        Assert.IsNotNull(postBlobResponse);
                        Assert.IsTrue(postBlobResponse.Response.IsSuccessStatusCode);
                        Assert.IsNotNull(postBlobResponse.Body);
                        Assert.IsFalse(string.IsNullOrWhiteSpace(postBlobResponse.Body.BlobHandle));

                        // if the post is successful, then download the blob
                        var blobHandle      = postBlobResponse.Body.BlobHandle;
                        var getBlobResponse = await client.Blobs.GetBlobWithHttpMessagesAsync(authorization : auth, blobHandle : blobHandle);

                        Assert.IsNotNull(getBlobResponse);
                        Assert.IsTrue(getBlobResponse.Response.IsSuccessStatusCode);

                        using (var memoryStream2 = new MemoryStream())
                        {
                            getBlobResponse.Body.CopyTo(memoryStream2);
                            newBlobSize = memoryStream2.Length;
                        }

                        // check that size of blob downloaded from Social Plus matches the size
                        Assert.AreEqual(originalBlobSize, newBlobSize);
                    }
                }
            }
            finally
            {
                // delete the user
                HttpOperationResponse <object> deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);
            }
        }
        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);
        }
        public async Task ApiSequenceTest()
        {
            this.ControllersContext = await ControllersContext.ConstructControllersContext();

            this.ControllersContextWithNullUserHandle = await ControllersContext.ConstructControllersContextWithNullUserHandle();

            //// Sequence #1: PostUser, PostLinkedAccount, PostLinkedAccount, DeleteUser

            var result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            PostUserResponse postUserResponse = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;

            this.SessionToken = postUserResponse.SessionToken;

            var seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.PostLinkedAccount204, this.PostLinkedAccount409, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #2: PostUser, PostLinkedAccount, DeleteLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.PostLinkedAccount204, this.DeleteLinkedAccount204, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #3: PostUser, PostLinkedAccount, GetLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.PostLinkedAccount204, this.GetLinkedAccounts200, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #4: PostUser, PostLinkedAccount, DeleteUser, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.PostLinkedAccount204, this.DeleteUser204, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #5: PostUser, DeleteLinkedAccount, PostLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteLinkedAccount404, this.PostLinkedAccount204, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #6: PostUser, DeleteLinkedAccount, DeleteLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteLinkedAccount404, this.DeleteLinkedAccount404, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #7: PostUser, DeleteLinkedAccount, GetLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteLinkedAccount404, this.GetLinkedAccounts200, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #8: PostUser, DeleteLinkedAccount, DeleteUser, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteLinkedAccount404, this.DeleteUser204, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #9: PostUser, GetLinkedAccount, PostLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.GetLinkedAccounts200, this.PostLinkedAccount204, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #10: PostUser, GetLinkedAccount, DeleteLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.GetLinkedAccounts200, this.DeleteLinkedAccount404, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #11: PostUser, GetLinkedAccount, GetLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.GetLinkedAccounts200, this.GetLinkedAccounts200, this.DeleteUser204
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #12: PostUser, GetLinkedAccount, DeleteUser, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.GetLinkedAccounts200, this.DeleteUser204, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #13: PostUser, DeleteUser, PostLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteUser204, this.PostLinkedAccount204, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #14: PostUser, DeleteUser, DeleteLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteUser204, this.DeleteLinkedAccount404, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #15: PostUser, DeleteUser, GetLinkedAccount, DeleteUser

            result = await ApiSequenceTestingFramework.Execute(this.PostUser201);

            postUserResponse  = (result as CreatedNegotiatedContentResult <PostUserResponse>).Content;
            this.SessionToken = postUserResponse.SessionToken;

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.DeleteUser204, this.GetLinkedAccounts200, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);

            //// Sequence #16: PostUser, DeleteUser, DeleteUser, DeleteUser

            seq = new List <Tuple <Func <Task <IHttpActionResult> >, Action <IHttpActionResult> > > {
                this.PostUser201, this.DeleteUser204, this.DeleteUser404, this.DeleteUser404
            };
            await ApiSequenceTestingFramework.Execute(seq);
        }
        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;
        }