public async Task GivenAValidUser_WhenILoginANewUserWithWrongpassword_ThenItReturnsUnauthorized() { getAuthHelper authHelper = new getAuthHelper(); _mockAuthRepository = new Mock <IAuthRepository>(); _mockAuthMapper = new Mock <IMapper>(); _mockConfig = new Mock <IConfiguration>(); _mockAuthRepository.Setup(repo => repo.Login(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(authHelper.userExits("john", "nopassword")); _authController = new AuthController(_mockAuthRepository.Object, _mockConfig.Object, _mockAuthMapper.Object); var token = await _authController.Login(new UserForLoginDto { AUsername = "******", Password = "******", }); Assert.IsInstanceOf <UnauthorizedResult>(token); }
public async Task GivenAValidUser_WhenILoginANewUserWithTheRightPassword_ThenItReturnsokResponse() { getAuthHelper authHelper = new getAuthHelper(); _mockAuthRepository = new Mock <IAuthRepository>(); _mockAuthMapper = new Mock <IMapper>(); _mockConfig = new Mock <IConfiguration>(); _mockAuthRepository.Setup(repo => repo.Login(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(authHelper.userExits("john", "password")); _mockConfig.Setup(config => config.GetSection(It.IsAny <string>()).Value).Returns("super secret key"); _authController = new AuthController(_mockAuthRepository.Object, _mockConfig.Object, _mockAuthMapper.Object); var token = await _authController.Login(new UserForLoginDto { AUsername = "******", Password = "******", }); Assert.IsInstanceOf <OkObjectResult>(token); }