Ejemplo n.º 1
0
        public async Task FollowUser_ResponseStatus_400(FollowUserRequest request)
        {
            // Arrange
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, Utils.GenerateUserIdString(1)),
            }, "mock"));

            var mockUserManagementService = new Mock <IUserManagementService>();

            mockUserManagementService.Setup(x => x.FollowUserAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(true));

            var userController = new UserController(Mapper, null, mockUserManagementService.Object, null);

            userController.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };
            MockModelState(request, userController);

            // Act
            var response = await userController.FollowUser(request);

            // Assert
            var badObjectResult = Assert.IsType <BadRequestObjectResult>(response);

            mockUserManagementService.Verify(x => x.FollowUserAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> FollowUser(FollowUserRequest request)
        {
            var response = await mediator.Send(request);

            logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} followed user #{request.RecipientId}", response.Error);

            return(response.IsSucceeded ? (IActionResult)Ok(response) : BadRequest(response));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> FollowUser(FollowUserRequest request)
        {
            var response = await mediator.Send(request);

            Log.Information($"User #{HttpContext.GetCurrentUserId()} {(response.IsFollowed ? "followed" : "unfollowed")} user #{request.UserId}");

            return(this.CreateResponse(response));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> FollowUser(FollowUserRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var currentUser = User.Identity.Name;
                await _userManagementService.FollowUserAsync(currentUser, request.UserToFollow);

                return(NoContent());
            }
            catch (EntityNotFoundException)
            {
                return(BadRequest("User not found"));
            }
        }