public async Task SocialFollowUnfollowTest() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user1 creates topic1 and topic2 var postTopic1 = await TestUtilities.PostGenericTopic(client, auth1); var postTopic2 = await TestUtilities.PostGenericTopic(client, auth1); // user2 follows user1 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse1.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth2); // when one user follows another, import of existing topics into the following topics feed // is done by a worker FeedResponseTopicView followingTopics1 = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // user2 gets the combined following topics feed followingTopics1 = await client.MyFollowing.GetTopicsAsync(auth2, null, 10); }, () => { // wait until two topics are returned or the auto-retry helper times out Assert.AreEqual(2, followingTopics1.Data.Count); }); // user2 unfollows user1 await client.MyFollowing.DeleteFollowingUserAsync(postUserResponse1.UserHandle, auth2); // user2 gets the combined following topics feed after user2 unfollows user1 var followingTopics2 = await client.MyFollowing.GetTopicsAsync(auth2, null, 10); // clean up: delete topics and users await TestUtilities.DeleteTopic(client, postTopic1.TopicHandle, auth1); await TestUtilities.DeleteTopic(client, postTopic2.TopicHandle, auth1); await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: check that followingTopics1 contains both topics and followingTopics2 is empty Assert.AreEqual(2, followingTopics1.Data.Count); Assert.AreEqual(0, followingTopics2.Data.Count); Assert.AreEqual(postTopic2.TopicHandle, followingTopics1.Data[0].TopicHandle); Assert.AreEqual(FollowerStatus.Follow, followingTopics1.Data[0].User.FollowerStatus); Assert.AreEqual(postTopic1.TopicHandle, followingTopics1.Data[1].TopicHandle); Assert.AreEqual(FollowerStatus.Follow, followingTopics1.Data[1].User.FollowerStatus); }
public async Task FollowingActivityTest() { // Setup three users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var user3 = await TestUtilities.PostGenericUser(client3); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); var auth3 = AuthHelper.CreateSocialPlusAuth(user3.SessionToken); // user1 requests to follow user2 PostFollowingUserRequest followingUserReq1 = new PostFollowingUserRequest() { UserHandle = user2.UserHandle }; HttpOperationResponse postFollowingResponse1 = await client1.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq1, authorization : auth1); // user2 requests to follow user3 PostFollowingUserRequest followingUserReq2 = new PostFollowingUserRequest() { UserHandle = user3.UserHandle }; HttpOperationResponse postFollowingResponse2 = await client2.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq2, authorization : auth2); HttpOperationResponse <FeedResponseActivityView> activitiesResponse = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // because user1 follows user2, user1 should receive an activity indicating that user2 follows user3 activitiesResponse = await client1.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth1); }, () => { // verify that user1 sees 1 activity, whose type is Following Assert.AreEqual(1, activitiesResponse.Body.Data.Count); Assert.AreEqual(ActivityType.Following, activitiesResponse.Body.Data[0].ActivityType); }); // clean up the three users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); HttpOperationResponse deleteUserOperationResponse3 = await client3.Users.DeleteUserWithHttpMessagesAsync(authorization : auth3); IList <ActivityView> activityList = activitiesResponse.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Following, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user2.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(user3.UserHandle, activityList[0].ActedOnUser.UserHandle); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); }
public async Task SocialDeleteFollowTest() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1, user2, and user3 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); var postUserResponse3 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); string auth3 = AuthHelper.CreateSocialPlusAuth(postUserResponse3.SessionToken); // user2 follows user1 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse1.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth2); // user3 follows user1 await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth3); // user1 gets the feed of his followers var followersUsers1 = await client.MyFollowers.GetFollowersAsync(auth1, null, 10); // user2 unfollows user1 await client.MyFollowing.DeleteFollowingUserAsync(postUserResponse1.UserHandle, auth2); // user1 gets the updated list of his followers var followersUsers2 = await client.MyFollowers.GetFollowersAsync(auth1, null, 10); // user1 removes user3 as a follower await client.MyFollowers.DeleteFollowerAsync(postUserResponse3.UserHandle, auth1); // user1 gets the updated list of his followers var followersUsers3 = await client.MyFollowers.GetFollowersAsync(auth1, null, 10); // clean up: delete all three users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); await TestUtilities.DeleteUser(client, auth3); // - validate: // check that user1's list of followers includes user2 and user3 the first time. // check that user1's list of followers includes user3 the second time. // check that user1's list of following users is empty the third time. Assert.AreEqual(2, followersUsers1.Data.Count); Assert.AreEqual(1, followersUsers2.Data.Count); Assert.AreEqual(0, followersUsers3.Data.Count); Assert.AreEqual(postUserResponse3.UserHandle, followersUsers1.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers1.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse2.UserHandle, followersUsers1.Data[1].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers1.Data[1].FollowerStatus); Assert.AreEqual(postUserResponse3.UserHandle, followersUsers2.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers2.Data[0].FollowerStatus); }
public async Task <IHttpActionResult> PostFollowingUser([FromBody] PostFollowingUserRequest request) { string className = "MyFollowingController"; string methodName = "PostFollowingUser"; string logEntry = $"FollowingUserHandle = {request?.UserHandle}"; this.LogControllerStart(this.log, className, methodName, logEntry); // Call the RelationshipControllerBase's method for updating the relationship. This method of the base class takes care of tracing also. return(await this.UpdateRelationshipToUser(className, methodName, RelationshipOperation.FollowUser, request.UserHandle)); }
public async Task BlockAfterFollow() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user1 follows user2 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth1); // user2 posts topic1 var postTopicResponse1 = await TestUtilities.PostGenericTopic(client, auth2); // user1 gets topic1 TopicView topicView1 = await client.Topics.GetTopicAsync(postTopicResponse1.TopicHandle, auth1); // user2 blocks user1 PostBlockedUserRequest postBlockedUserRequest = new PostBlockedUserRequest(postUserResponse1.UserHandle); await client.MyBlockedUsers.PostBlockedUserAsync(postBlockedUserRequest, auth2); // user2 posts topic2 var postTopicResponse2 = await TestUtilities.PostGenericTopic(client, auth2); // user1 gets topic1 TopicView topicView2 = await client.Topics.GetTopicAsync(postTopicResponse1.TopicHandle, auth1); // user1 fetches topic2 TopicView topicView3 = await client.Topics.GetTopicAsync(postTopicResponse2.TopicHandle, auth1); // cleanup: delete both users and both topics await client.Topics.DeleteTopicAsync(postTopicResponse1.TopicHandle, auth2); await client.Topics.DeleteTopicAsync(postTopicResponse2.TopicHandle, auth2); await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that getting topic1 worked the first time // check that getting topic1 worked the second time // check that getting topic2 did not work Assert.AreEqual(postTopicResponse1.TopicHandle, topicView1.TopicHandle); Assert.AreEqual(postTopicResponse1.TopicHandle, topicView2.TopicHandle); Assert.AreEqual(null, topicView3.TopicHandle); }
/// <summary> /// Create synthetic following relationships by having each user follow the given number of other users /// chosen randomly without replacement /// </summary> /// <param name="client">a valid SocialPlusClient</param> /// <param name="users">a list of UserInfo objects representing the pool of users in which to create following relationships</param> /// <param name="numUsersToFollow">the number of users each user should follow</param> /// <returns>a task</returns> private static async Task FollowUsers(SocialPlusClient client, List <UserInfo> users, int numUsersToFollow) { for (int userIndex = 0; userIndex < users.Count; userIndex++) { List <UserInfo> shuffledUsers = GetShuffledList(users); shuffledUsers.Remove(users[userIndex]); for (int i = 0; i < numUsersToFollow; i++) { PostFollowingUserRequest request = new PostFollowingUserRequest(shuffledUsers[i].UserHandle); await client.MyFollowing.PostFollowingUserWithHttpMessagesAsync(request, users[userIndex].BearerToken); } } }
public async Task SocialFollowingUserTest() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user2 gets the feed of users that he is following FeedResponseUserCompactView following1 = await client.MyFollowing.GetFollowingUsersAsync(auth2, null, 10); // user2 follows user1 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse1.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth2); // user2 gets the feed of users that he is following var following2 = await client.UserFollowing.GetFollowingAsync(postUserResponse2.UserHandle, auth2, null, 10); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile1 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile2 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // clean up: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: check that following1 is empty, following2 contains user1, and both user profiles have the correct state Assert.AreEqual(0, following1.Data.Count); Assert.AreEqual(1, following2.Data.Count); Assert.AreEqual(postUserResponse1.UserHandle, following2.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.Follow, following2.Data[0].FollowerStatus); Assert.AreEqual(FollowerStatus.None, userProfile1.FollowerStatus); Assert.AreEqual(FollowingStatus.Follow, userProfile1.FollowingStatus); Assert.AreEqual(0, userProfile1.TotalFollowers); Assert.AreEqual(1, userProfile1.TotalFollowing); Assert.AreEqual(FollowerStatus.Follow, userProfile2.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile2.FollowingStatus); Assert.AreEqual(1, userProfile2.TotalFollowers); Assert.AreEqual(0, userProfile2.TotalFollowing); }
public async Task CommentActivityTest() { // Setup two users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); // user1 requests to follow user2 PostFollowingUserRequest followingUserReq1 = new PostFollowingUserRequest() { UserHandle = user2.UserHandle }; HttpOperationResponse postFollowingResponse = await client1.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq1, authorization : auth1); // user1 creates a topic var postTopicResponse = await TestUtilities.PostGenericTopic(client1, auth1); string topicHandle = postTopicResponse.TopicHandle; // user2 posts a comment on the topic -- this causes a Comment activity to be sent to users following user2 var postCommentResponse = await TestUtilities.PostGenericComment(client2, auth2, topicHandle); string commentHandle = postCommentResponse.CommentHandle; HttpOperationResponse <FeedResponseActivityView> activitiesResponse = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // because user1 follows user2, user1 should receive an activity indicating that user2 commented on a topic activitiesResponse = await client1.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth1); }, () => { // verify that user1 sees 1 activity, whose type is Comment Assert.AreEqual(1, activitiesResponse.Body.Data.Count); Assert.AreEqual(ActivityType.Comment, activitiesResponse.Body.Data[0].ActivityType); }); // clean up the comment and the topic HttpOperationResponse deleteComment = await client2.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth2); HttpOperationResponse deleteTopic = await client1.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1); // clean up the two users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); IList <ActivityView> activityList = activitiesResponse.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Comment, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user2.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(user1.UserHandle, activityList[0].ActedOnUser.UserHandle); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); }
public async Task SocialFollowPrivateUserRejectTest() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile1 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile2 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // make user2 a private user PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth2); // user1 requests to follow user2 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth1); CountResponse getPendingUserCount1 = null; FeedResponseUserCompactView getPendingUsers1 = null; // user2 gets the count of his pending users // user2 gets his feed of pending users getPendingUserCount1 = await client.MyPendingUsers.GetPendingUsersCountAsync(auth2); getPendingUsers1 = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile3 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile4 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // user2 rejects user1's follow request await client.MyPendingUsers.DeletePendingUserAsync(postUserResponse1.UserHandle, auth2); // user2 gets the count of his pending users // user2 gets his feed of pending users CountResponse getPendingUserCount2 = await client.MyPendingUsers.GetPendingUsersCountAsync(auth2); var getPendingUsers2 = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user1 gets the profile of user2 // user2 gets the profile of user1 var userProfile5 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile6 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // clean up: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that user2's list of pending users includes user1 // check that user2's list of pending users is empty after the reject // check the user profiles to see that follower status and following status are updated correctly Assert.AreEqual(1, getPendingUserCount1.Count); Assert.AreEqual(0, getPendingUserCount2.Count); Assert.AreEqual(postUserResponse1.UserHandle, getPendingUsers1.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, getPendingUsers1.Data[0].FollowerStatus); Assert.AreEqual(Visibility.Public, getPendingUsers1.Data[0].Visibility); // Validate User Profiles Assert.AreEqual(FollowerStatus.None, userProfile1.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile1.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile1.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile2.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile2.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile2.Visibility); Assert.AreEqual(FollowerStatus.Pending, userProfile3.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile3.FollowingStatus); Assert.AreEqual(Visibility.Private, userProfile3.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile4.FollowerStatus); Assert.AreEqual(FollowingStatus.Pending, userProfile4.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile4.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile5.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile5.FollowingStatus); Assert.AreEqual(Visibility.Private, userProfile5.Visibility); Assert.AreEqual(FollowerStatus.None, userProfile6.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile6.FollowingStatus); Assert.AreEqual(Visibility.Public, userProfile6.Visibility); }
public async Task SocialFollowPrivateUserTest() { // create the client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // make user2 a private user PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth2); // user2 gets the feed of his followers var followersUsers1 = await client.MyFollowers.GetFollowersAsync(auth2, null, 10); // user1 requests to follow user2 PostFollowingUserRequest postFollowingRequest1 = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest1, auth1); // user2 gets his feed of pending users var pendingUsers = await client.MyPendingUsers.GetPendingUsersAsync(auth2, null, 10); // user2 accepts user1's follow request PostFollowerRequest postFollowerRequest2 = new PostFollowerRequest(postUserResponse1.UserHandle); await client.MyFollowers.PostFollowerAsync(postFollowerRequest2, auth2); // user2 gets the feed of his followers with GET /users/{userhandle}/followers var followersUsers2 = await client.UserFollowers.GetFollowersAsync(postUserResponse2.UserHandle, auth2, null, 10); // user2 gets the feed of his followers with GET /users/me/followers - result is same, just using a different API var followersUsers3 = await client.MyFollowers.GetFollowersAsync(auth2, null, 10); // user1 gets the feed of his following users var followingUsers = await client.MyFollowing.GetFollowingUsersAsync(auth1, null, 10); // clean up: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that user2's list of pending users includes user1 // check that user2's followers feed includes user1 // check that user1's list of following users includes user2 Assert.AreEqual(0, followersUsers1.Data.Count); Assert.AreEqual(1, followersUsers2.Data.Count); Assert.AreEqual(1, followersUsers3.Data.Count); Assert.AreEqual(1, pendingUsers.Data.Count); Assert.AreEqual(1, followingUsers.Data.Count); Assert.AreEqual(postUserResponse1.UserHandle, followersUsers2.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers2.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse1.UserHandle, followersUsers3.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, followersUsers3.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse1.UserHandle, pendingUsers.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, pendingUsers.Data[0].FollowerStatus); Assert.AreEqual(postUserResponse2.UserHandle, followingUsers.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.Follow, followingUsers.Data[0].FollowerStatus); }
/// <summary> /// Follow a user /// </summary> /// When I follow a user, that user will appear on my following feed. That /// feed is /// visible to all users, unless my profile is set to private, in /// which case only those /// users that request to follow me and I approve will see that /// feed. If I try to follow a /// user with a private profile, then that private user controls /// whether I am allowed to /// follow them or not. /// That user's topics will appear in my following topics feed and /// actions /// performed by that user will also appear in my following /// activities feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post following user request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PostFollowingUserAsync(this IMyFollowing operations, PostFollowingUserRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostFollowingUserWithHttpMessagesAsync(request, authorization, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Follow a user /// </summary> /// When I follow a user, that user will appear on my following feed. That /// feed is /// visible to all users, unless my profile is set to private, in /// which case only those /// users that request to follow me and I approve will see that /// feed. If I try to follow a /// user with a private profile, then that private user controls /// whether I am allowed to /// follow them or not. /// That user's topics will appear in my following topics feed and /// actions /// performed by that user will also appear in my following /// activities feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post following user request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> public static object PostFollowingUser(this IMyFollowing operations, PostFollowingUserRequest request, string authorization) { return(Task.Factory.StartNew(s => ((IMyFollowing)s).PostFollowingUserAsync(request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public async Task PopularUsersTest() { // This test is susceptable to data left over from previous tests. Run CleanServerState before running all the tests and this will work fine. // Create Users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserResponse postUserResponse1 = await TestUtilities.DoLogin(client1, "Stan", "TopicMan", string.Empty); PostUserResponse postUserResponse2 = await TestUtilities.DoLogin(client2, "Bill", "Top Man", string.Empty); PostUserResponse postUserResponse3 = await TestUtilities.DoLogin(client3, "Jill", "TopicWoman", "Third man in"); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); string auth3 = AuthHelper.CreateSocialPlusAuth(postUserResponse3.SessionToken); // Get Followings PostFollowingUserRequest postFollowingRequest1 = new PostFollowingUserRequest(postUserResponse1.UserHandle); PostFollowingUserRequest postFollowingRequest2 = new PostFollowingUserRequest(postUserResponse1.UserHandle); PostFollowingUserRequest postFollowingRequest3 = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client2.MyFollowing.PostFollowingUserAsync(postFollowingRequest1, auth2); await client3.MyFollowing.PostFollowingUserAsync(postFollowingRequest2, auth3); await client3.MyFollowing.PostFollowingUserAsync(postFollowingRequest3, auth3); // Use the first one as the gating factor. If that works then others will be ready too FeedResponseUserProfileView popularUsers1 = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // Various Popular Users stuff popularUsers1 = await client3.Users.GetPopularUsersAsync(auth3, null, 10); }, () => { // verify Assert.AreEqual("Stan", popularUsers1.Data[0].FirstName); Assert.AreEqual("TopicMan", popularUsers1.Data[0].LastName); }); // Various Popular Users stuff - check the others and use cursor FeedResponseUserProfileView popularUsers2 = await client1.Users.GetPopularUsersAsync(auth1, null, 1); FeedResponseUserProfileView popularUsers3 = await client1.Users.GetPopularUsersAsync(auth1, int.Parse(popularUsers2.Cursor), 1); await client2.MyFollowing.DeleteFollowingUserAsync(postUserResponse1.UserHandle, auth2); await client3.MyFollowing.DeleteFollowingUserAsync(postUserResponse1.UserHandle, auth3); // Since following stuff deleted need to wait for service bus FeedResponseUserProfileView popularUsers4 = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // Various Popular Users stuff popularUsers4 = await client1.Users.GetPopularUsersAsync(auth1, null, 10); }, () => { // verify Assert.AreEqual("Bill", popularUsers4.Data[0].FirstName); Assert.AreEqual("Top Man", popularUsers4.Data[0].LastName); }); await client3.Users.DeleteUserAsync(auth3); var popularUsers5 = await client1.Users.GetPopularUsersAsync(auth1, null, 10); await client2.Users.DeleteUserAsync(auth2); var popularUsers6 = await client1.Users.GetPopularUsersAsync(auth1, null, 10); await client1.Users.DeleteUserAsync(auth1); var popularUsers7 = await client1.Users.GetPopularUsersAsync(auth1, null, 10); // Verify Assert.AreEqual(2, popularUsers1.Data.Count); Assert.AreEqual("Stan", popularUsers1.Data[0].FirstName); Assert.AreEqual("TopicMan", popularUsers1.Data[0].LastName); Assert.AreEqual(postUserResponse1.UserHandle, popularUsers1.Data[0].UserHandle); Assert.AreEqual("Bill", popularUsers1.Data[1].FirstName); Assert.AreEqual("Top Man", popularUsers1.Data[1].LastName); Assert.AreEqual(postUserResponse2.UserHandle, popularUsers1.Data[1].UserHandle); Assert.AreEqual(1, popularUsers2.Data.Count); Assert.AreEqual("Stan", popularUsers2.Data[0].FirstName); Assert.AreEqual("TopicMan", popularUsers2.Data[0].LastName); Assert.AreEqual(1, popularUsers3.Data.Count); Assert.AreEqual("Bill", popularUsers3.Data[0].FirstName); Assert.AreEqual("Top Man", popularUsers3.Data[0].LastName); Assert.AreEqual(2, popularUsers4.Data.Count); Assert.AreEqual("Bill", popularUsers4.Data[0].FirstName); Assert.AreEqual("Top Man", popularUsers4.Data[0].LastName); Assert.AreEqual(postUserResponse2.UserHandle, popularUsers4.Data[0].UserHandle); Assert.AreEqual("Stan", popularUsers4.Data[1].FirstName); Assert.AreEqual("TopicMan", popularUsers4.Data[1].LastName); Assert.AreEqual(postUserResponse1.UserHandle, popularUsers4.Data[1].UserHandle); Assert.AreEqual(2, popularUsers5.Data.Count); Assert.AreEqual("Bill", popularUsers5.Data[0].FirstName); Assert.AreEqual("Top Man", popularUsers5.Data[0].LastName); Assert.AreEqual(postUserResponse2.UserHandle, popularUsers5.Data[0].UserHandle); Assert.AreEqual("Stan", popularUsers5.Data[1].FirstName); Assert.AreEqual("TopicMan", popularUsers5.Data[1].LastName); Assert.AreEqual(postUserResponse1.UserHandle, popularUsers5.Data[1].UserHandle); Assert.AreEqual(1, popularUsers6.Data.Count); Assert.AreEqual("Stan", popularUsers6.Data[0].FirstName); Assert.AreEqual("TopicMan", popularUsers6.Data[0].LastName); Assert.AreEqual(postUserResponse1.UserHandle, popularUsers6.Data[0].UserHandle); Assert.AreEqual(0, popularUsers7.Data.Count); }
public async Task FollowingTopicActivityTest() { // Setup three users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var user3 = await TestUtilities.PostGenericUser(client3); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); var auth3 = AuthHelper.CreateSocialPlusAuth(user3.SessionToken); // user2 requests to follow user1 PostFollowingUserRequest followingUserReq = new PostFollowingUserRequest() { UserHandle = user1.UserHandle }; HttpOperationResponse postFollowingResponse = await client2.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq, authorization : auth2); // user3 requests to follow user1 PostFollowingUserRequest followingUserReq2 = new PostFollowingUserRequest() { UserHandle = user1.UserHandle }; HttpOperationResponse postFollowingResponse2 = await client3.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq2, authorization : auth3); // user2 creates a topic var postTopicResponse = await TestUtilities.PostGenericTopic(client2, auth2); string topicHandle = postTopicResponse.TopicHandle; // user1 follows the topic created by user2 PostFollowingTopicRequest followingTopicReq = new PostFollowingTopicRequest() { TopicHandle = topicHandle }; HttpOperationResponse postFollowingResponse3 = await client1.MyFollowing.PostFollowingTopicWithHttpMessagesAsync(followingTopicReq, authorization : auth1); // fetch user1's combined following topics feed HttpOperationResponse <FeedResponseTopicView> combinedFollowingTopics = await client1.MyFollowing.GetTopicsWithHttpMessagesAsync(authorization : auth1); // check that both user2 and user3 receive the activity generated when user1 follows the topic HttpOperationResponse <FeedResponseActivityView> activitiesResponse1 = null; HttpOperationResponse <FeedResponseActivityView> activitiesResponse2 = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { activitiesResponse1 = await client2.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth2); activitiesResponse2 = await client3.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth3); }, () => { // verify that user2 and user3 both see 1 activity, whose type is Following Assert.AreEqual(1, activitiesResponse1.Body.Data.Count); Assert.AreEqual(ActivityType.Following, activitiesResponse1.Body.Data[0].ActivityType); Assert.AreEqual(1, activitiesResponse2.Body.Data.Count); Assert.AreEqual(ActivityType.Following, activitiesResponse2.Body.Data[0].ActivityType); }); // clean up the topic HttpOperationResponse deleteTopic = await client2.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth2); // clean up the three users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); HttpOperationResponse deleteUserOperationResponse3 = await client3.Users.DeleteUserWithHttpMessagesAsync(authorization : auth3); // check the result of the combined following topics feed Assert.AreEqual(1, combinedFollowingTopics.Body.Data.Count); Assert.AreEqual(topicHandle, combinedFollowingTopics.Body.Data[0].TopicHandle); // check the activity results IList <ActivityView> activityList = activitiesResponse1.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Following, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user1.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(null, activityList[0].ActedOnUser); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); activityList = activitiesResponse2.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Following, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user1.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(null, activityList[0].ActedOnUser); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); }