public async Task IssueManyBatches() { // instantiate the handlers DelegatingHandler[] handlers = new DelegatingHandler[2]; Uri batchURL = new Uri(TestConstants.ServerApiBaseUrl.OriginalString + "batch"); BatchHttpMessageHandler batchHandler = new BatchHttpMessageHandler(HttpMethod.Post, batchURL); InstrumentedHttpMessageHandler testHandler = new InstrumentedHttpMessageHandler(); handlers[0] = batchHandler; // this will be the inner handler handlers[1] = testHandler; // this will be the outer handler // instantiate the client, passing in the handler SocialPlusClient myClient = new SocialPlusClient(TestConstants.ServerApiBaseUrl, handlers); // request server build info many times int numRequests = 50; List <Task <HttpOperationResponse <GetBuildInfoResponse> > > getBuildsTasks = new List <Task <HttpOperationResponse <GetBuildInfoResponse> > >(); for (int i = 0; i < numRequests; i++) { getBuildsTasks.Add(myClient.Config.GetBuildInfoWithHttpMessagesAsync()); } // issue the batch await batchHandler.IssueBatch(); // verify server build info responses for (int i = 0; i < numRequests; i++) { HttpOperationResponse <GetBuildInfoResponse> buildsResponse = await getBuildsTasks[i]; VerifyBuildsResponse(buildsResponse); } }
public async Task IssueNonBatch() { // instantiate the handler DelegatingHandler[] handlers = new DelegatingHandler[1]; InstrumentedHttpMessageHandler testHandler = new InstrumentedHttpMessageHandler(); handlers[0] = testHandler; // instantiate the client SocialPlusClient myClient = new SocialPlusClient(TestConstants.ServerApiBaseUrl, handlers); // request server build info HttpOperationResponse <GetBuildInfoResponse> buildsResponse = await myClient.Config.GetBuildInfoWithHttpMessagesAsync(); VerifyBuildsResponse(buildsResponse); // login PostUserRequest postUserRequest = new PostUserRequest(InstanceId, "Bob", "Smith", "mybio", null); string userHandle = HandleGenerator.GenerateShortHandle(); string auth = await TestUtilities.GetAADAuth(userHandle); HttpOperationResponse <PostUserResponse> postUserResponse = await myClient.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth); VerifyPostUserResponse(postUserResponse); // delete login auth = AuthHelper.CreateSocialPlusAuth(postUserResponse.Body.SessionToken); HttpOperationResponse <object> deleteUserResponse = await myClient.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); Assert.IsTrue(deleteUserResponse.Response.IsSuccessStatusCode); }
public async Task CreateDeleteUserWithValidAADTokenValidSPClient() { // Get the access token for a valid AAD application CertificateHelper certHelper = new CertificateHelper(ValidSPClient.CertThumbprint, ValidSPClient.ClientId, StoreLocation.CurrentUser); string accessToken = await certHelper.GetAccessToken(ValidSPClient.Authority, ValidSPClient.AppUri); string userHandle = HandleGenerator.GenerateShortHandle(); string auth = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle); // Set up initial stuff SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserRequest postUserRequest = new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio"); HttpOperationResponse <PostUserResponse> postUserOperationResponse = await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth); HttpOperationResponse <object> deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); // Assert correct HTTP error codes Assert.IsTrue(postUserOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode); // PostUser also returns a non-empty session token and the user handle Assert.IsFalse(string.IsNullOrEmpty(postUserOperationResponse.Body.SessionToken)); Assert.AreEqual(userHandle, postUserOperationResponse.Body.UserHandle); }
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); }
public async Task CreateDeleteUserWithValidAADTokenInvalidAudience() { // Get the access token for SocialPlus AAD application. While this is a valid AAD token, // the service checks that the token's audience is "https://embeddedsocial.microsoft.com/testclient1". // In this case, it is not. Instead, the audience is "https://embeddedsocial.microsoft.com/testclient2" CertificateHelper certHelper = new CertificateHelper(InvalidSPClient.CertThumbprint, InvalidSPClient.ClientId, StoreLocation.CurrentUser); string accessToken = await certHelper.GetAccessToken(InvalidSPClient.Authority, InvalidSPClient.AppUri); string userHandle = HandleGenerator.GenerateShortHandle(); string auth = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle); // Set up initial stuff SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserRequest postUserRequest = new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio"); HttpOperationResponse <PostUserResponse> postUserOperationResponse = await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : accessToken); // the above post user operation should fail. but in case it doesn't, we clean up the user we created HttpOperationResponse <object> deleteUserOperationResponse = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : accessToken); // both the create and delete operations should fail Assert.AreEqual(HttpStatusCode.Unauthorized, postUserOperationResponse.Response.StatusCode); Assert.AreEqual(HttpStatusCode.Unauthorized, deleteUserOperationResponse.Response.StatusCode); }
public async Task CreateUserTwiceDeleteUserTwice() { // Get the access token for the Embedded Social Test Client 1 AAD application CertificateHelper certHelper = new CertificateHelper(ValidSPClient.CertThumbprint, ValidSPClient.ClientId, StoreLocation.CurrentUser); string accessToken = await certHelper.GetAccessToken(ValidSPClient.Authority, ValidSPClient.AppUri); string userHandle = HandleGenerator.GenerateShortHandle(); string auth = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle); // Set up initial stuff SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserRequest postUserRequest = new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio"); HttpOperationResponse <PostUserResponse> postUserOperationResponse1 = await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth); HttpOperationResponse <PostUserResponse> postUserOperationResponse2; postUserOperationResponse2 = await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth); HttpOperationResponse <object> deleteUserOperationResponse1 = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); HttpOperationResponse <object> deleteUserOperationResponse2 = await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); // Assert correct HTTP error codes Assert.IsTrue(postUserOperationResponse1.Response.IsSuccessStatusCode); Assert.AreEqual(HttpStatusCode.Conflict, postUserOperationResponse2.Response.StatusCode); Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode); }
public async Task UpdateUserVisibilityTest() { SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user = await TestUtilities.PostGenericUser(client); var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken); // Call Put User PutUserVisibilityRequest putUserVisibilityRequest = new PutUserVisibilityRequest(Visibility.Private); await client.Users.PutUserVisibilityAsync(putUserVisibilityRequest, auth); // Call Get User UserProfileView getUserProfile = await client.Users.GetUserAsync(user.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(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(user.UserHandle, getUserProfile.UserHandle); Assert.AreEqual(Visibility.Private, getUserProfile.Visibility); }
public async Task GetTopicsForUserUsingHandleTest() { SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user = await TestUtilities.PostGenericUser(client); var auth = AuthHelper.CreateSocialPlusAuth(user.SessionToken); var httpResponse1 = await TestUtilities.PostGenericTopic(client, auth); string topicHandle1 = httpResponse1.TopicHandle; var httpResponse2 = await TestUtilities.PostGenericTopic(client, auth); string topicHandle2 = httpResponse2.TopicHandle; // get the topics for this user FeedResponseTopicView topicListResponse = await client.UserTopics.GetTopicsAsync(user.UserHandle, auth, cursor : null, limit : 2); // Delete Topics await client.Topics.DeleteTopicAsync(topicHandle1, auth); await client.Topics.DeleteTopicAsync(topicHandle2, auth); // Delete user await TestUtilities.DeleteUser(client, auth); Assert.AreEqual(2, topicListResponse.Data.Count); }
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 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); }
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 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); }
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 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); }
/// <summary> /// Helper routine for posting a generic user /// </summary> /// <param name="client">Client object</param> /// <returns>Post user response</returns> public static async Task <PostUserResponse> PostGenericUser(SocialPlusClient client) { string uniqueSuffix = TestUtilities.CreateUniqueDigits(); string firstName = "Barack" + uniqueSuffix; string lastName = "Obama" + uniqueSuffix; string bio = "44th President" + uniqueSuffix; return(await TestUtilities.DoLogin(client, firstName, lastName, bio)); }
public async Task SearchTopicsTestUsingEmptyString() { // *********************************************** // ** NOTE ** - Verification might change if design is set to not return anything vs return everything // *********************************************** SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); PostUserResponse postUserResponse; string firstName = "FirstUser"; string lastName = "FirstUserLastName"; string bio = string.Empty; postUserResponse = await TestUtilities.DoLogin(client1, firstName, lastName, bio); string auth = AuthHelper.CreateSocialPlusAuth(postUserResponse.SessionToken); // First Topic string topicTitle = "My Favorite Topic"; string topicText = "Sports. "; BlobType blobType = BlobType.Image; string blobHandle = "http://myBlobHandle/"; string language = "en-US"; string deepLink = "Sports!"; string categories = "sports, ncurrency"; string friendlyName = "Game On!"; string group = "mygroup"; PostTopicRequest postTopicRequest = new PostTopicRequest(publisherType: PublisherType.User, text: topicText, title: topicTitle, blobType: blobType, blobHandle: blobHandle, language: language, deepLink: deepLink, categories: categories, friendlyName: friendlyName, group: group); HttpOperationResponse <PostTopicResponse> postTopicOperationResponse = await client1.Topics.PostTopicWithHttpMessagesAsync(request : postTopicRequest, authorization : auth); // If the post topic operation failed, clean up if (postTopicOperationResponse == null || postTopicOperationResponse.Body == null || string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle)) { await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); Assert.Fail("Failed to post topic"); } // Delay a bit to allow data to get into the search await Task.Delay(TestConstants.SearchDelay); // Only one result HttpOperationResponse <FeedResponseTopicView> search1 = await client1.Search.GetTopicsWithHttpMessagesAsync(query : string.Empty, cursor : null, limit : 5, authorization : auth); // Clean up topic HttpOperationResponse <object> deleteTopic1 = await client1.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : postTopicOperationResponse.Body.TopicHandle, authorization : auth); // Clean up first user HttpOperationResponse <object> deleteUser1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth); // Verify now - get info Assert.AreEqual(search1.Response.StatusCode, HttpStatusCode.BadRequest); // Verify deletions Assert.IsTrue(deleteTopic1.Response.IsSuccessStatusCode); Assert.IsTrue(deleteUser1.Response.IsSuccessStatusCode); }
public async Task ServiceInfoTest() { SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var configServiceInfoResponse = await client.Config.GetServiceInfoAsync(); Console.WriteLine("Current Service Information:"); Console.WriteLine($" Service API Version: {configServiceInfoResponse.ServiceApiVersion}"); Console.WriteLine($" Service API All Versions: {configServiceInfoResponse.ServiceApiAllVersions}"); }
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); }
/// <summary> /// Create synthetic reply likes by having each of the supplied users like the given number of replies /// chosen randomly without replacement /// </summary> /// <param name="client">a valid SocialPlusClient</param> /// <param name="users">a list of UserInfo objects representing the users who will like replies</param> /// <param name="replyHandles">a list of reply handles corresponding to the replies to like</param> /// <param name="numReplyLikesPerUser">the number of replies each user should like</param> /// <returns>a task</returns> private static async Task AddReplyLikes(SocialPlusClient client, List <UserInfo> users, List <string> replyHandles, int numReplyLikesPerUser) { for (int userIndex = 0; userIndex < users.Count; userIndex++) { List <string> shuffledReplyHandles = GetShuffledList(replyHandles); for (int i = 0; i < numReplyLikesPerUser; i++) { await client.ReplyLikes.PostLikeWithHttpMessagesAsync(shuffledReplyHandles[i], users[userIndex].BearerToken); } } }
/// <summary> /// Create synthetic topic likes by having each of the supplied users like the given number of topics /// chosen randomly without replacement /// </summary> /// <param name="client">a valid SocialPlusClient</param> /// <param name="users">a list of UserInfo objects representing the users who will like topics</param> /// <param name="topics">a list of TopicInfo objects representing the topics to like</param> /// <param name="numTopicLikesPerUser">the number of topics each user should like</param> /// <returns>a task</returns> private static async Task AddTopicLikes(SocialPlusClient client, List <UserInfo> users, List <TopicInfo> topics, int numTopicLikesPerUser) { for (int userIndex = 0; userIndex < users.Count; userIndex++) { List <TopicInfo> shuffledTopics = GetShuffledList(topics); for (int i = 0; i < numTopicLikesPerUser; i++) { await client.TopicLikes.PostLikeWithHttpMessagesAsync(shuffledTopics[i].TopicHandle, users[userIndex].BearerToken); } } }
/// <summary> /// Helper routine to clean up a reply using the SocialPlusClient api. /// This version takes a replyResponse, for when a handle hasn't been extracted. /// </summary> /// <param name="client">Client object</param> /// <param name="postReplyResponse">The reply response, can be null.</param> /// <param name="authorization">authorization header value</param> /// <returns>An <see cref="HttpOperationResponse"/> for the deletion.</returns> public static async Task <HttpOperationResponse <object> > DeleteReply(SocialPlusClient client, HttpOperationResponse <PostReplyResponse> postReplyResponse, string authorization) { HttpOperationResponse <object> deleteReplyResponse = null; if (postReplyResponse != null && postReplyResponse.Response.IsSuccessStatusCode && !string.IsNullOrWhiteSpace(postReplyResponse.Body.ReplyHandle)) { deleteReplyResponse = await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : postReplyResponse.Body.ReplyHandle, authorization : authorization); } return(deleteReplyResponse); }
/// <summary> /// Helper routine to clean up a reply using the SocialPlusClient api. /// This version takes a replyHandle. /// </summary> /// <param name="client">Client object</param> /// <param name="replyHandle">The handle for the reply, can be null.</param> /// <param name="authorization">authorization header value</param> /// <returns>An <see cref="HttpOperationResponse"/> for the deletion.</returns> public static async Task <HttpOperationResponse <object> > DeleteReply(SocialPlusClient client, string replyHandle, string authorization) { HttpOperationResponse <object> deleteReplyResponse = null; if (!string.IsNullOrWhiteSpace(replyHandle)) { deleteReplyResponse = await client.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : authorization); } return(deleteReplyResponse); }
/// <summary> /// Helper routine to clean up a comment using the SocialPlusClient api. /// </summary> /// <param name="client">Client object</param> /// <param name="commentHandle">The handle for the comment, can be null.</param> /// <param name="authorization">authorization header value</param> /// <returns>An <see cref="HttpOperationResponse"/> for the deletion.</returns> public static async Task <HttpOperationResponse <object> > DeleteComment(SocialPlusClient client, string commentHandle, string authorization) { HttpOperationResponse <object> deleteCommentResponse = null; if (!string.IsNullOrWhiteSpace(commentHandle)) { deleteCommentResponse = await client.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : authorization); } return(deleteCommentResponse); }
/// <summary> /// Helper routine to clean up a topic using the SocialPlusClient api. /// </summary> /// <param name="client">Client object</param> /// <param name="topicHandle">The handle for the topic, can be null.</param> /// <param name="authorization">authorization header value</param> /// <returns>An <see cref="HttpOperationResponse"/> for the deletion.</returns> public static async Task <HttpOperationResponse <object> > DeleteTopic(SocialPlusClient client, string topicHandle, string authorization) { HttpOperationResponse <object> deleteTopicResponse = null; if (!string.IsNullOrWhiteSpace(topicHandle)) { deleteTopicResponse = await client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : authorization); } return(deleteTopicResponse); }
public async Task CommentNotification() { // 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); // create a topic by user 1 var postTopicResponse = await TestUtilities.PostGenericTopic(client1, auth1); // get the notification feed HttpOperationResponse <FeedResponseActivityView> getNotificationsOperationResponse1 = await client1.MyNotifications.GetNotificationsWithHttpMessagesAsync(authorization : auth1); // create a comment by user 2 var postCommentOperationResponse = await TestUtilities.PostGenericComment(client2, auth2, postTopicResponse.TopicHandle); // wait for notifications to fan out await Task.Delay(TestConstants.ServiceBusLongDelay); // get the notification feed HttpOperationResponse <FeedResponseActivityView> getNotificationsOperationResponse2 = await client1.MyNotifications.GetNotificationsWithHttpMessagesAsync(authorization : auth1); // clean up HttpOperationResponse <object> deleteCommentOperationResponse = await client2.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : postCommentOperationResponse.CommentHandle, authorization : auth2); HttpOperationResponse <object> deleteTopicOperationResponse = await client1.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : postTopicResponse.TopicHandle, authorization : auth1); HttpOperationResponse <object> deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse <object> deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); // check everything went well Assert.IsTrue(getNotificationsOperationResponse1.Response.IsSuccessStatusCode); Assert.IsTrue(getNotificationsOperationResponse2.Response.IsSuccessStatusCode); Assert.IsTrue(deleteCommentOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(deleteTopicOperationResponse.Response.IsSuccessStatusCode); Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode); Assert.IsTrue(deleteUserOperationResponse2.Response.IsSuccessStatusCode); // check the notification feed contents Assert.AreEqual(getNotificationsOperationResponse1.Body.Data.Count, 0); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data.Count, 1); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data[0].ActivityType, ActivityType.Comment); Assert.IsTrue(getNotificationsOperationResponse2.Body.Data[0].Unread); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data[0].ActedOnContent.ContentHandle, postTopicResponse.TopicHandle); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data[0].ActorUsers.Count, 1); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data[0].ActorUsers[0].UserHandle, user2.UserHandle); Assert.AreEqual(getNotificationsOperationResponse2.Body.Data[0].TotalActions, 1); }
/// <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)); }
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); }
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); }
public async Task CreateVerifyDeleteClientNameAndConfigTest() { // retrieve the developerId using ManageApps string developerId = ManageAppsUtils.GetDeveloperId(TestConstants.EnvironmentName); // create a client name and config using ManageApps string uniqueSuffix = TestUtilities.CreateUniqueDigits(); string clientName = $"{TestConstants.EnvironmentName}-ClientNameTest{uniqueSuffix}"; string clientSideAppKey = Guid.NewGuid().ToString(); string clientConfigJson = "{}"; string serverSideAppKey = ManageAppsUtils.CreateClientNameAndConfig(clientName, clientSideAppKey, clientConfigJson); // create a test client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 var postUserResponse1 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); if (serverSideAppKey == null) { // delete the user and fail the test await TestUtilities.DeleteUser(client, auth1); Assert.Fail("Failed to create client name and config"); } // retrieve the client configuration var clientConfig = await client.Config.GetClientConfigWithHttpMessagesAsync(developerId, clientName); // delete client name and configuration bool deleted = ManageAppsUtils.DeleteClientNameAndConfig(clientName); if (!deleted) { // delete the user and fail the test await TestUtilities.DeleteUser(client, auth1); Assert.Fail("Failed to delete client name and config"); } // delete the user await TestUtilities.DeleteUser(client, auth1); // Check the retrieved configuration is correct Assert.AreEqual(serverSideAppKey, clientConfig.Body.ServerSideAppKey); Assert.AreEqual(clientConfigJson, clientConfig.Body.ClientConfigJson); // if we reach here, the test was successful. return; }
public async Task 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)); }