Example #1
0
        public void Validate_GoodUser_ShouldPass()
        {
            // Arrange
            var registerDTO = DummyData.RegisterDTOFaker.Generate();

            // Act
            var result = _sut.TestValidate(registerDTO);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }
        public void ShouldValidateOnRegisterModelIsAllRule()
        {
            var model = new RegisterModel
            {
                Password = "******"
            };

            //we know that password should equal confirmation password
            model.ConfirmPassword = model.Password;
            _registerValidator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Password);
            model.Password = "******";
            //we know that password should equal confirmation password
            model.ConfirmPassword = model.Password;
            _registerValidator.TestValidate(model).ShouldNotHaveValidationErrorFor(x => x.Password);
        }
        public void ShouldHaveErrorWhenFirstnameIsNullOrEmpty()
        {
            var customerSettings = new CustomerSettings
            {
                FirstNameEnabled  = true,
                FirstNameRequired = true
            };

            var validator = new RegisterValidator(GetService <ILocalizationService>(), GetService <IStateProvinceService>(), customerSettings);
            var model     = new RegisterModel
            {
                FirstName = null
            };

            validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.FirstName);
            model.FirstName = string.Empty;
            validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.FirstName);
        }
        public void ShouldNotHaveErrorWhenFirstnameIsSpecified()
        {
            var customerSettings = new CustomerSettings
            {
                FirstNameEnabled = true
            };

            var validator = new RegisterValidator(GetService <ILocalizationService>(), GetService <IStateProvinceService>(), customerSettings);

            var model = new RegisterModel
            {
                FirstName = "John"
            };

            validator.TestValidate(model).ShouldNotHaveValidationErrorFor(x => x.FirstName);
        }
        public void ShouldHaveErrorWhenEmailIsNullOrEmpty()
        {
            var model = new RegisterModel
            {
                Email = null
            };

            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
            model.Email = string.Empty;
            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
        }