public async Task UserFriends_Followers_With_User(KnownChains apiName) { var user = Users[apiName]; var offset = string.Empty; var someResponsesAreHasFollowTrue = false; for (var i = 0; i < 10; i++) { var request = new UserFriendsModel(user.Login, FriendsType.Followers) { Login = user.Login, Offset = offset }; var response = await Api[apiName].GetUserFriends(request, CancellationToken.None); AssertResult(response); Assert.IsTrue(response.Result.Results != null); someResponsesAreHasFollowTrue = response.Result.Results.Any(x => x.HasFollowed == true); if (someResponsesAreHasFollowTrue) { break; } offset = response.Result.Results.Last().Author; } Assert.IsTrue(someResponsesAreHasFollowTrue); }
public async Task GetUserFriendsTest(KnownChains apiName) { var user = Users[apiName]; var request = new UserFriendsModel(user.Login, FriendsType.Following); var result = await Gateway[apiName].GetUserFriends(request, CancellationToken.None); Assert.IsTrue(result.IsSuccess, result.Error?.Message); }
private void FollowTest(StringBuilder sb, int num) { sb.Append($"{num}) FollowTest : "); StepFinished?.Invoke(sb.ToString()); // Load last created post var getPosts = new PostsModel(PostType.New) { Login = _user.Login }; var postsResp = _api.GetPosts(getPosts, CancellationToken.None) .Result; if (!postsResp.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {postsResp.Error.Message}"); return; } if (postsResp.Result.Results.Count == 0) { sb.AppendLine("fail. Reason:{Environment.NewLine} There are no Posts to Follow!"); return; } var testPost = postsResp.Result.Results.First(); var votereq = new FollowModel(_user, FollowType.Follow, testPost.Author); var rez = _api.Follow(votereq, CancellationToken.None) .Result; if (!rez.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {rez.Error.Message}"); return; } Task.Delay(10000); var userFriendsReq = new UserFriendsModel(_user.Login, FriendsType.Followers) { Login = _user.Login, Offset = testPost.Author, Limit = 1 }; var verifyResp = _api.GetUserFriends(userFriendsReq, CancellationToken.None).Result; if (!verifyResp.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {verifyResp.Error.Message}"); return; } if (verifyResp.Result.Results.Count != 1) { sb.AppendLine($"fail. Reason:{Environment.NewLine} user ({testPost.Author}) not found!"); return; } sb.AppendLine("pass."); }
public async Task UserFriends_Followers_Invalid_Username(KnownChains apiName) { // Arrange var user = Users[apiName]; var request = new UserFriendsModel(user.Login + "x", FriendsType.Followers); // Act var response = await Api[apiName].GetUserFriends(request, CancellationToken.None); // Assert Assert.IsTrue(response.Error.Message.Equals("Account does not exist")); }
private void GetUserFriendsTest(StringBuilder sb, int num) { sb.Append($"{num}) GetUserFriendsTest : "); StepFinished?.Invoke(sb.ToString()); var limit = 3; var request = new UserFriendsModel(_user.Login, FriendsType.Followers) { Limit = limit }; var response = _api.GetUserFriends(request, CancellationToken.None).Result; if (IsError1(sb, limit, response, response.Result.Results.Count)) { return; } request.Offset = response.Result.Results.Last().Author; response = _api.GetUserFriends(request, CancellationToken.None).Result; if (IsError2(sb, limit, response, request.Offset)) { return; } //--- request = new UserFriendsModel(_user.Login, FriendsType.Following) { Limit = limit }; response = _api.GetUserFriends(request, CancellationToken.None).Result; if (IsError1(sb, limit, response, response.Result.Results.Count)) { return; } request.Offset = response.Result.Results.Last().Author; response = _api.GetUserFriends(request, CancellationToken.None).Result; if (IsError2(sb, limit, response, request.Offset)) { return; } sb.AppendLine("pass."); }
public async Task UserFriends_Followers_Offset_Limit(KnownChains apiName, string offset) { // Arrange var user = Users[apiName]; var request = new UserFriendsModel(user.Login, FriendsType.Followers); request.Offset = offset; request.Limit = 1; // Act var response = await Api[apiName].GetUserFriends(request, CancellationToken.None); // Assert AssertResult(response); Assert.That(response.Result.Results, Is.Not.Empty); Assert.That(response.Result.Results.First().Author, Is.EqualTo(offset)); Assert.That(response.Result.Results.Count == 1); }
public async Task UserFriends_Followers(KnownChains apiName) { // Arrange var user = Users[apiName]; var request = new UserFriendsModel(user.Login, FriendsType.Followers); // Act var response = await Api[apiName].GetUserFriends(request, CancellationToken.None); // Assert AssertResult(response); Assert.That(response.Result.Results, Is.Not.Empty); Assert.That(response.Result.Results.First().Author, Is.Not.Null); Assert.That(response.Result.Results.First().Avatar, Is.Not.Null); Assert.That(response.Result.Results.First().Reputation, Is.Not.Null); Assert.That(response.Result.Results.First().HasFollowed, Is.False); var noHasFollowTrueWithoutUser = response.Result.Results.Any(x => x.HasFollowed == true); Assert.That(noHasFollowTrueWithoutUser, Is.False); }
private async Task <ErrorBase> LoadNextUserFriends(string username, CancellationToken ct) { if (!FollowType.HasValue) { return(null); } var request = new UserFriendsModel(username, FollowType.Value) { Login = AppSettings.User.Login, Offset = OffsetUrl, Limit = ItemsLimit }; var response = await Api.GetUserFriends(request, ct); if (response.IsSuccess) { var result = response.Result.Results; if (result.Count > 0) { lock (Items) { Items.AddRange(Items.Count == 0 ? result : result.Skip(1)); CashPresenterManager.Add(Items.Count == 0 ? result : result.Skip(1)); } OffsetUrl = result.Last().Author; } if (result.Count < Math.Min(ServerMaxCount, ItemsLimit)) { IsLastReaded = true; } NotifySourceChanged(nameof(TryLoadNextUserFriends), true); } return(response.Error); }
public async Task <OperationResult <ListResponse <UserFriend> > > GetUserFriends(UserFriendsModel model, CancellationToken token) { if (!EnableRead) { return(null); } var results = Validate(model); if (results.Any()) { return(new OperationResult <ListResponse <UserFriend> >(new ValidationError(string.Join(Environment.NewLine, results.Select(i => i.ErrorMessage))))); } var parameters = new Dictionary <string, object>(); AddOffsetLimitParameters(parameters, model.Offset, model.Limit); AddLoginParameter(parameters, model.Login); var endpoint = $"user/{model.Username}/{model.Type.ToString().ToLowerInvariant()}"; return(await Gateway.Get <ListResponse <UserFriend> >(GatewayVersion.V1P1, endpoint, parameters, token)); }
public async Task <OperationResult <ListResponse <UserFriend> > > GetUserFriends(UserFriendsModel model, CancellationToken token) { if (!EnableRead) { return(null); } var results = Validate(model); if (results != null) { return(new OperationResult <ListResponse <UserFriend> >(results)); } var parameters = new Dictionary <string, object>(); AddOffsetLimitParameters(parameters, model.Offset, model.Limit); AddLoginParameter(parameters, model.Login); var endpoint = $"{BaseUrl}/{GatewayVersion.V1P1}/user/{model.Username}/{model.Type.ToString().ToLowerInvariant()}"; return(await HttpClient.Get <ListResponse <UserFriend> >(endpoint, parameters, token)); }