public void Login_WhenCalledWithCorrectUserNameAndPassword_ShouldReturnOk() { var request = TestDataRepository.BuildAuthenticateRequest(); request.GoogleToken = null; var user = TestDataRepository.BuildUser(); _usersRepository.Setup(x => x.FilterBy(It.IsAny <Expression <Func <User, bool> > >())) .Returns(new List <User> { user }); var result = (OkObjectResult)_loginController.Login(request); Assert.IsNotNull(result); var res = result.Value as AuthenticateResponse; Assert.IsNotNull(res); Assert.AreEqual(request.UserName, res.Username); Assert.AreEqual(user.FirstName, res.FirstName); Assert.AreEqual(user.LastName, res.LastName); Assert.AreEqual(user.UserName, res.Username); }
public void InitTests() { _repository = new Mock <IMongoRepository <Recipe> >(); _httpContextAccessor = new Mock <IHttpContextAccessor>(); _user = TestDataRepository.BuildUser(); _httpContextAccessor.Setup(x => x.HttpContext.Items["User"]).Returns(_user); _recipeService = new RecipeService(_repository.Object, _httpContextAccessor.Object); _recipesController = new RecipesController(_recipeService); }
public void Login_WhenCalledWithPasswordMissing_ShouldReturnValidationError() { var request = TestDataRepository.BuildAuthenticateRequest(); request.GoogleToken = null; request.Password = null; var user = TestDataRepository.BuildUser(); _usersRepository.Setup(x => x.FilterBy(It.IsAny <Expression <Func <User, bool> > >())) .Returns(new List <User> { user }); var result = (OkObjectResult)_loginController.Login(request); Assert.Fail("Expected validationexception to occur"); }
public void Login_WhenCalledWithIncorrectPassword_ShouldReturnNotAuthorized() { var request = TestDataRepository.BuildAuthenticateRequest(); request.GoogleToken = null; var user = TestDataRepository.BuildUser(); user.Password = "******".Hash(); _usersRepository.Setup(x => x.FilterBy(x => x.UserName.Equals(request.UserName) && x.AccountType == AccountType.Internal) ).Returns(new List <User> { user }); var result = (BadRequestObjectResult)_loginController.Login(request); Assert.IsNotNull(result); }