Ejemplo n.º 1
0
        public async Task Authenticate_InvalidUser_ReturnsNotFoundResult()
        {
            // Arrange
            var invalidUser = new UserDto()
            {
                UserName = "******",
                Password = "******"
            };

            _repo.FirstOrDefaultAsync(Arg.Any <Expression <Func <User, bool> > >()).Returns(Task.FromResult <User>(null));

            // Act
            var notFoundResult = await _controller.PostAsync(invalidUser);

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
        public async Task <ActionResult <User> > PostAsync(UserDto newUser)
        {
            var user = await _repo.FirstOrDefaultAsync(u => u.UserName == newUser.UserName && u.Password == newUser.Password);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }