Esempio n. 1
0
        public async Task <IActionResult> GetGroupsForUser(int userId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            return(Ok(await _groupsService.GetGroupsForUser(userId)));
        }
        public async Task GetGroupsForUser_ShouldBeDoneSuccessfully()
        {
            // Arrange
            var memberships = new List <Membership>()
            {
                new Membership()
                {
                    UserId = 1,
                }
            };

            var groupsToReturn = new List <GroupToReturnDto>()
            {
                new GroupToReturnDto()
                {
                    Id = 1,
                }
            };

            _unitOfWork.Setup(x => x.Groups.GetGroupsForUser(It.IsAny <int>()))
            .ReturnsAsync(memberships);

            _mapperMock.Setup(x => x.Map <ICollection <GroupToReturnDto> >(memberships))
            .Returns(groupsToReturn);

            // Act
            var result = await _sut.GetGroupsForUser(It.IsAny <int>());

            // Assert
            var group = result.FirstOrDefault();

            Assert.NotNull(result);
            Assert.NotNull(group);
            Assert.NotEmpty(result);
            Assert.Equal(1, group.Id);
        }