public void UsernameOnlyAcceptsAlphaNumericCharacters(string test, bool result)
        {
            Mock<IUserService> sessionMock = new Mock<IUserService>();
            sessionMock.Setup(x => x.DoesUserExistWithUsername(test)).Returns(false);
            UserRegisterViewModelValidator validator = new UserRegisterViewModelValidator(sessionMock.Object);
            var results = validator.Validate(new ViewModels.UserRegisterViewModel()
            {
                Username = test,
                Password = "******",
                StayLoggedIn = true
            });

            Assert.AreEqual(result, results.IsValid);
        }
        public void WhenUserExistsValidationFails()
        {
            Mock<IUserService> sessionMock = new Mock<IUserService>();
            sessionMock.Setup(x => x.DoesUserExistWithUsername("tester")).Returns(true);
            UserRegisterViewModelValidator validator = new UserRegisterViewModelValidator(sessionMock.Object);
            var results = validator.Validate(new ViewModels.UserRegisterViewModel()
            {
                 Username = "******",
                 Password = "******",
                 StayLoggedIn = true
            });

            Assert.False(results.IsValid);
        }
Exemplo n.º 3
0
        public void WhenUserDoesNotExistValidationSucceeds()
        {
            Mock <IUserService> sessionMock = new Mock <IUserService>();

            sessionMock.Setup(x => x.DoesUserExistWithUsername("tester")).Returns(false);
            UserRegisterViewModelValidator validator = new UserRegisterViewModelValidator(sessionMock.Object);
            var results = validator.Validate(new ViewModels.UserRegisterViewModel()
            {
                Username     = "******",
                Password     = "******",
                StayLoggedIn = true
            });

            Assert.True(results.IsValid);
        }
Exemplo n.º 4
0
        public void UsernameOnlyAcceptsAlphaNumericCharacters(string test, bool result)
        {
            Mock <IUserService> sessionMock = new Mock <IUserService>();

            sessionMock.Setup(x => x.DoesUserExistWithUsername(test)).Returns(false);
            UserRegisterViewModelValidator validator = new UserRegisterViewModelValidator(sessionMock.Object);
            var results = validator.Validate(new ViewModels.UserRegisterViewModel()
            {
                Username     = test,
                Password     = "******",
                StayLoggedIn = true
            });

            Assert.AreEqual(result, results.IsValid);
        }
        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.");
        }
        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.");
        }
        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.");
        }