This is my function of a controller class, I want to test this but I didn't have any idea to know why checking the OkObject is null. I need some advice and a way to solve this:
[HttpGet]
public async Task<IActionResult> LoginAsync(string phoneNumber, string pass)
{
User login = new User();
login.Phone = phoneNumber;
login.Password = pass;
IActionResult response = Unauthorized();
var user = await _loginService.AuthenticateUserAsync(login);
if(user != null)
{
var tokenStr = _loginService.GenerateJWT(user);
response = Ok(new { token = tokenStr });
}
return response;
}
My test function is :
[Fact]
public async Task LoginAsync_ReturnOk()
{
var mock = new Mock<ILoginService>();
var controller = new LoginController(mock.Object);
var phone = "0123456789";
var pass = "abc123";
var okResult = await controller.LoginAsync(phone, pass);
Assert.IsType<OkObjectResult>(okResult as OkObjectResult);
}
I really need help from you guys.