public async Task <IHttpActionResult> PostBlockedUser([FromBody] PostBlockedUserRequest request) { string className = "MyBlockedUsersController"; string methodName = "PostBlockedUser"; string logEntry = $"BlockedUserHandle = {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.BlockUser, 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> /// Block a user /// </summary> /// After I block a user, that user will no longer be able to see topics /// authored by me. /// However, that user will continue to see comments and replies /// that I create on /// topics authored by other users or by the app. That user will /// also be able to observe /// that activities have been performed by users on my topics. /// I will no longer appear in that user's following feed, and /// that user will no longer /// appear in my followers feed. /// If I am following that user, that relationship will survive /// and I will continue to see /// topics and activities by that user and I will appear in that /// user's follower feed and /// that user will appear in my following feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post blocked 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> PostBlockedUserAsync(this IMyBlockedUsers operations, PostBlockedUserRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostBlockedUserWithHttpMessagesAsync(request, authorization, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Block a user /// </summary> /// After I block a user, that user will no longer be able to see topics /// authored by me. /// However, that user will continue to see comments and replies /// that I create on /// topics authored by other users or by the app. That user will /// also be able to observe /// that activities have been performed by users on my topics. /// I will no longer appear in that user's following feed, and /// that user will no longer /// appear in my followers feed. /// If I am following that user, that relationship will survive /// and I will continue to see /// topics and activities by that user and I will appear in that /// user's follower feed and /// that user will appear in my following feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post blocked 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 PostBlockedUser(this IMyBlockedUsers operations, PostBlockedUserRequest request, string authorization) { return(Task.Factory.StartNew(s => ((IMyBlockedUsers)s).PostBlockedUserAsync(request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public async Task SocialBlockUnblockUserTest() { // 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 user2's profile // user2 gets user1's profile var userProfile1 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile2 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // user2 blocks user1 PostBlockedUserRequest postBlockedUserRequest = new PostBlockedUserRequest(postUserResponse1.UserHandle); await client.MyBlockedUsers.PostBlockedUserAsync(postBlockedUserRequest, auth2); // user2 gets his list of blocked users var getBlockedUsers1 = await client.MyBlockedUsers.GetBlockedUsersAsync(auth2, null, 10); // user1 gets user2's profile // user2 gets user1's profile var userProfile3 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile4 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // user2 unblocks user1 await client.MyBlockedUsers.DeleteBlockedUserAsync(postUserResponse1.UserHandle, auth2); // user1 gets user2's profile // user2 gets user1's profile var userProfile5 = await client.Users.GetUserAsync(postUserResponse2.UserHandle, auth1); var userProfile6 = await client.Users.GetUserAsync(postUserResponse1.UserHandle, auth2); // user2 gets his updated list of blocked users var getBlockedUsers2 = await client.MyBlockedUsers.GetBlockedUsersAsync(auth2, null, 10); // cleanup: delete both users await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that user1 appears as blocked in the profile followerstatus and followingstatus // check that users2's list of blocked users has user1 the first time // check that users2's list of blocked users is empty the second time Assert.AreEqual(FollowerStatus.None, userProfile1.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile1.FollowingStatus); Assert.AreEqual(FollowerStatus.None, userProfile2.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile2.FollowingStatus); Assert.AreEqual(FollowerStatus.Blocked, userProfile3.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile3.FollowingStatus); Assert.AreEqual(FollowerStatus.None, userProfile4.FollowerStatus); Assert.AreEqual(FollowingStatus.Blocked, userProfile4.FollowingStatus); Assert.AreEqual(FollowerStatus.None, userProfile5.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile5.FollowingStatus); Assert.AreEqual(FollowerStatus.None, userProfile6.FollowerStatus); Assert.AreEqual(FollowingStatus.None, userProfile6.FollowingStatus); Assert.AreEqual(1, getBlockedUsers1.Data.Count); Assert.AreEqual(postUserResponse1.UserHandle, getBlockedUsers1.Data[0].UserHandle); Assert.AreEqual(FollowerStatus.None, getBlockedUsers1.Data[0].FollowerStatus); Assert.AreEqual(0, getBlockedUsers2.Data.Count); }
/// <summary> /// Block a user /// </summary> /// After I block a user, that user will no longer be able to see topics /// authored by me. /// However, that user will continue to see comments and replies /// that I create on /// topics authored by other users or by the app. That user will /// also be able to observe /// that activities have been performed by users on my topics. /// I will no longer appear in that user's following feed, and /// that user will no longer /// appear in my followers feed. /// If I am following that user, that relationship will survive /// and I will continue to see /// topics and activities by that user and I will appear in that /// user's follower feed and /// that user will appear in my following feed. /// <param name='request'> /// Post blocked 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='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse <object> > PostBlockedUserWithHttpMessagesAsync(PostBlockedUserRequest request, string authorization, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (request == null) { throw new ValidationException(ValidationRules.CannotBeNull, "request"); } if (request != null) { request.Validate(); } if (authorization == null) { throw new ValidationException(ValidationRules.CannotBeNull, "authorization"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("request", request); tracingParameters.Add("authorization", authorization); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "PostBlockedUser", tracingParameters); } // Construct URL var _baseUrl = this.Client.BaseUri.AbsoluteUri; var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v0.7/users/me/blocked_users").ToString(); // Create HTTP transport objects HttpRequestMessage _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new Uri(_url); // Set Headers if (authorization != null) { if (_httpRequest.Headers.Contains("Authorization")) { _httpRequest.Headers.Remove("Authorization"); } _httpRequest.Headers.TryAddWithoutValidation("Authorization", authorization); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (request != null) { _requestContent = SafeJsonConvert.SerializeObject(request, this.Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8); _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 204 && (int)_statusCode != 400 && (int)_statusCode != 401 && (int)_statusCode != 404 && (int)_statusCode != 409 && (int)_statusCode != 500) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <object>(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 204) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = SafeJsonConvert.DeserializeObject <object>(_responseContent, this.Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }