示例#1
0
        public async Task GetUser_InvalidUser_ReturnsNotFoundResult()
        {
            // Arrange
            _repo.GetByNameAsync(Arg.Any <string>()).Returns(Task.FromResult <User>(null));

            // Act
            var notFoundResult = await _controller.GetUser("invalid_user");

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
        public async Task <ActionResult <User> > GetUser(string userName)
        {
            var user = await _repo.GetByNameAsync(userName);

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

            return(user);
        }