public async void GetFriends_ForProperUserGuid_ShouldReturnUsersFriends() { var service = new FriendService(_dataContext); var userId = Guid.Parse("44889f11-b43e-476f-8cba-e9bbbf5d2b86"); var friends = await service.GetFriends(userId); friends.Count.Should().Be(1); friends.First().Id.Should().Be(Guid.Parse("475d30dc-6e0f-4369-bf15-37f4f8873215")); }
public async Task <IActionResult> GetFriends() { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _friendService.GetFriends(userId); if (!response.Success) { return(BadRequest(response.Message)); } var userFriendsDto = _mapper.Map <UserFriends, UserFriendsDto>(response.Resource); return(Ok(userFriendsDto)); }
public async Task <List <UserFriendModel> > GetFriends(string userId, string authenticationToken) { try { FriendService friendService = new FriendService(); var userFriends = new List <UserFriendModel>(); var response = await friendService.GetFriends(userId, authenticationToken); if (response.IsSuccessStatusCode) { var json = JObject.Parse(await response.Content.ReadAsStringAsync()); if (json.HasValues) { var ids = json.SelectToken("$.friends.ids").ToObject <JArray>(); var names = json.SelectToken("$.friends.names").ToObject <JArray>(); var profilePictures = json.SelectToken("$.friends.profilePictures").ToObject <JArray>(); for (int i = 0; i < ids.Count; i++) { userFriends.Add(new UserFriendModel(ids[i].ToString(), names[i].ToString(), profilePictures[i].ToString())); } } return(userFriends); } else { if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new Exception("Unauthorized"); } else { throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
public FriendViewModel() { _friendsList = new ObservableCollection <Friends>(); friendService = new FriendService(); _friendsList = Task.Run(async() => await friendService.GetFriends()).Result; }