Ejemplo n.º 1
0
        public void AddUser()
        {
            //-- arrange
            var countBeforeAdd = _repository.GetUsers(_resourceParameters).Count;

            var user = new User
            {
                FirstName    = "fname",
                LastName     = "lname",
                EmailAddress = "email@users",
                Password     = "******"
            };

            //-- act
            _repository.AddUser(user);
            _repository.Save();

            var actual = _repository.GetUsers(_resourceParameters).Count;

            //-- assert
            Assert.AreEqual(countBeforeAdd + 1, actual);

            //-- clean up
            _repository.DeleteUser(user);
            _repository.Save();
        }
Ejemplo n.º 2
0
        public IActionResult DeleteUser(int userId,
                                        [FromBody] UserCredentialsDto credentials)
        {
            var emailAddress = credentials.EmailAddress;
            var password     = credentials.Password;

            if (!_weblogDataRepository.Authorized(userId, emailAddress, password))
            {
                return(Unauthorized());
            }

            var userFromRepo = _weblogDataRepository.GetUser(userId);

            if (userFromRepo is null)
            {
                return(NotFound());
            }

            _weblogDataRepository.DeleteUser(userFromRepo);
            _weblogDataRepository.Save();

            return(NoContent());
        }