Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void Login_WhenCalledWithInvalidGoogleToken_ShouldReturnBadResult()
        {
            var request = TestDataRepository.BuildAuthenticateRequest();

            var result = (BadRequestObjectResult)_loginController.Login(request);

            Assert.IsNotNull(result);
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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);
        }