public void SavePasswordNoLetters()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel {
                Email = "*****@*****.**", Password = "******", PasswordConfirm = "12345678"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Password must contains 1 letter at least.", exception.Message);
        }
        public void SaveEmailInvalid()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel {
                Email = "test"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("The e-mail is invalid", exception.Message);
        }
        public void SavePasswordLengthLowerThan8()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                PasswordConfirm = "123456"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Password must contains more than 8 characters.", exception.Message);
        }
        public void SavePasswordDoesntMatch()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                PasswordConfirm = "123456"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Password doesn't match", exception.Message);
        }
        public void SavePasswordEmpty()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel
            {
                Email           = "*****@*****.**",
                Password        = "",
                PasswordConfirm = ""
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Password and Confirm Password are required fields", exception.Message);
        }
        public void SaveWithoutDefaultProfile()
        {
            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                PasswordConfirm = "ABCDEFGH123!"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Your account can't be registered because there is no default profile.", exception.Message);
        }
        public IActionResult Post(UserRequestCreateAccountViewModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                return(Ok(service.Post(user, Request.Host.Value)));
            }
            catch (Exception)
            {
                throw;
            }
        }
        //[TestMethod] - Commented because Mock for AutoMapper is not working.
        public void SaveWithDefaultProfile()
        {
            profileRepository.Setup(x => x.GetDefault()).Returns(new Domain.Entities.Profile
            {
                Id   = 1,
                Name = "Default"
            });

            mapper.Setup(m => m.Map <UserRequestCreateAccountViewModel, User>(It.IsAny <UserRequestCreateAccountViewModel>()))
            .Returns(new User());

            UserRequestCreateAccountViewModel userRequest = new UserRequestCreateAccountViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                PasswordConfirm = "ABCDEFGH123!"
            };
            ApiException exception = Assert.ThrowsException <ApiException>(() => userService.Post(userRequest, ""));

            Assert.AreEqual("Your account can't be registered because there is no default profile.", exception.Message);
        }
Exemplo n.º 9
0
        public bool Post(UserRequestCreateAccountViewModel user, string host)
        {
            ValidationService.ValidEmail(user.Email);
            ValidationService.ValidPassword(user.Password, user.PasswordConfirm);

            if (repository.GetByEmail(user.Email) != null)
            {
                throw new ApiException("Email not found", HttpStatusCode.Conflict);
            }

            Profile _profile = profileRepository.GetDefault();

            if (_profile == null)
            {
                throw new ApiException("Your account can't be registered because there is no default profile.", HttpStatusCode.Unused);
            }

            try
            {
                User _user = mapper.Map <User>(user);
                _user.ProfileId = _profile.Id;
                _user.Code      = UtilsService.GenerateCode(8);

                repository.Create(_user);

                string _generateUrlEmail = UtilsService.GenerateURL(_user.Code, _user.Email, host);

                emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Account Created - Template", "ACCOUNT-CREATED"), new string[] { _user.Name, _generateUrlEmail });

                return(true);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex.Message, HttpStatusCode.BadRequest);
            }
        }