Ejemplo n.º 1
0
        public ActionResult Register(UserRegisterViewModel user)
        {
            if (ModelState.IsValid)
            {
                userService.Create(user.ConvertToDomain());
                return View("Success");
            }

            return View();
        }
        public void ConvertToDomain()
        {
            var viewModel = new UserRegisterViewModel()
            {
                Login = "******",
                Email = "*****@*****.**",
                Password = "******",
                PasswordRepeated = "1234"
            };

            var user = viewModel.ConvertToDomain();

            user.Login.Should().Be(viewModel.Login);
            user.Email.Should().Be(viewModel.Email);
            user.Password.Should().Be("81DC9BDB52D04DC20036DBD8313ED055");
        }
        public void TestingWithAllFieldsEmpty()
        {
            var viewModel = new UserRegisterViewModel();
            var userService = new Mock<IUserService>();
            userService.Setup(x => x.FindByLogin(It.IsAny<string>())).Returns<User>(null);
            userService.Setup(x => x.FindByEmail(It.IsAny<string>())).Returns<User>(null);

            var validator = new UserRegisterViewModelValidator(userService.Object);
            var results = validator.Validate(viewModel);

            results.Errors.Count.Should().Be(4);
            results.Errors[0].ErrorMessage.Should().Be("'Login' deve ser preenchido.");
            results.Errors[1].ErrorMessage.Should().Be("'Email' deve ser preenchido.");
            results.Errors[2].ErrorMessage.Should().Be("'Senha' deve ser preenchido.");
            results.Errors[3].ErrorMessage.Should().Be("'Repetir Senha' deve ser preenchido.");
        }
Ejemplo n.º 4
0
        public void TryToRegisterWithInvalidData()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var userService = new Mock<IUserService>();
                var authProvider = new Mock<IAuthProvider>();
                var target = new UserController(userService.Object, authProvider.Object);

                target.ModelState.AddModelError("error", "error");

                var user = new UserRegisterViewModel();

                target.Register(user);

                userService.Verify(x => x.Create(It.IsAny<User>()), Times.Never());
            }
        }
        public void TestingWithInvalidEmail()
        {
            var viewModel = new UserRegisterViewModel()
            {
                Login = "******",
                Email = "abcd",
                Password = "******",
                PasswordRepeated = "1234"
            };

            var userService = new Mock<IUserService>();
            userService.Setup(x => x.FindByLogin(It.IsAny<string>())).Returns<User>(null);
            userService.Setup(x => x.FindByEmail(It.IsAny<string>())).Returns<User>(null);

            var validator = new UserRegisterViewModelValidator(userService.Object);
            var results = validator.Validate(viewModel);

            results.Errors.Count.Should().Be(1);
            results.Errors[0].ErrorMessage.Should().Be("'Email' deve ser um endereço de email válido.");
        }
Ejemplo n.º 6
0
        public void TryToRegisterWithValidData()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var userService = new Mock<IUserService>();
                var authProvider = new Mock<IAuthProvider>();
                var target = new UserController(userService.Object, authProvider.Object);

                var user = new UserRegisterViewModel()
                {
                    Login = "******",
                    Email = "*****@*****.**",
                    Password = "******",
                    PasswordRepeated = "1234"
                };

                target.Register(user);

                userService.Verify(x => x.Create(It.IsAny<User>()), Times.Once());
            }
        }
        public void TestingWithDifferentsPasswords()
        {
            var viewModel = new UserRegisterViewModel()
            {
                Login = "******",
                Email = "*****@*****.**",
                Password = "******",
                PasswordRepeated = "12345"
            };

            var userService = new Mock<IUserService>();
            userService.Setup(x => x.FindByLogin(It.IsAny<string>())).Returns<User>(null);
            userService.Setup(x => x.FindByEmail(It.IsAny<string>())).Returns<User>(null);
            
            var validator = new UserRegisterViewModelValidator(userService.Object);
            var results = validator.Validate(viewModel);

            results.Errors.Count.Should().Be(2);
            results.Errors[0].ErrorMessage.Should().Be("As senhas informadas devem ser iguais.");
            results.Errors[1].ErrorMessage.Should().Be("As senhas informadas devem ser iguais.");
        }
        public void TestingWithValidData()
        {
            var viewModel = new UserRegisterViewModel()
            {
                Login = "******",
                Email = "*****@*****.**",
                Password = "******",
                PasswordRepeated = "1234"
            };

            var userService = new Mock<IUserService>();
            userService.Setup(x => x.FindByLogin(It.IsAny<string>())).Returns<User>(null);
            userService.Setup(x => x.FindByEmail(It.IsAny<string>())).Returns<User>(null);

            var validator = new UserRegisterViewModelValidator(userService.Object);
            var results = validator.Validate(viewModel);

            results.Errors.Count.Should().Be(0);
        }
        public void TestingWithInvalidEmailAndLogin()
        {
            var viewModel = new UserRegisterViewModel()
            {
                Login = "******",
                Email = "*****@*****.**",
                Password = "******",
                PasswordRepeated = "1234"
            };

            var userService = new Mock<IUserService>();
            userService.Setup(x => x.FindByLogin(It.IsAny<string>())).Returns(
                new User{ Login = "******"}
            );
            userService.Setup(x => x.FindByEmail(It.IsAny<string>())).Returns(
                new User{ Login = "******"}
            );

            var validator = new UserRegisterViewModelValidator(userService.Object);
            var results = validator.Validate(viewModel);

            results.Errors.Count.Should().Be(2);
            results.Errors[0].ErrorMessage.Should().Be("'Login' já existente.");
            results.Errors[1].ErrorMessage.Should().Be("'Email' já existente.");
        }