public async Task <IActionResult> GetFavoriteGroupsForUser(int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } return(Ok(await _groupsService.GetFavoriteGroupsForUser(userId))); }
public async Task GetFavoriteGroupsForUser_ShouldBeDoneSuccessfully() { // Arrange var groups = new List <Membership>() { new Membership() { UserId = 1, } }; var groupsToReturn = new List <GroupToReturnDto>() { new GroupToReturnDto() { Id = 1, Favorite = true } }; _unitOfWork.Setup(x => x.Groups.GetFavoriteGroupsForUser(It.IsAny <int>())) .ReturnsAsync(groups); _mapperMock.Setup(x => x.Map <ICollection <GroupToReturnDto> >(groups)) .Returns(groupsToReturn); // Act var result = await _sut.GetFavoriteGroupsForUser(It.IsAny <int>()); // Assert var group = result.FirstOrDefault(); Assert.NotNull(group); Assert.NotNull(result); Assert.NotEmpty(result); Assert.True(group.Favorite); Assert.Equal(1, group.Id); }