public void CpfValidation_Validate_ShouldCheckIfCpfIsValid(string validCpf, string invalidCpf) { // Act var validResult = CpfValidation.Validate(validCpf); var invalidResult = CpfValidation.Validate(invalidCpf); // Assert Assert.True(validResult); Assert.False(invalidResult); }
public EmployeeValidation() { RuleFor(e => e.FirstName) .NotEmpty().WithMessage("The field {PropertyName} must be provided") .Length(2, 50).WithMessage("The field {PropertyName} need to have between {MinLength} and {MaxLength} characteres"); RuleFor(e => e.LastName) .NotEmpty().WithMessage("The field {PropertyName} must be provided") .Length(2, 50).WithMessage("The field {PropertyName} need to have between {MinLength} and {MaxLength} characteres"); RuleFor(e => e.Document.Length).Equal(CpfValidation.CpfLength) .WithMessage("O campo Documento precisa ter {ComparisonValue} caracteres e foi fornecido {PropertyValue}"); RuleFor(f => CpfValidation.Validate(f.Document)).Equal(false) .WithMessage("O documento fornecido é inválido."); }
public ProviderValidation() { RuleFor(p => p.Name) .NotEmpty().WithMessage("O campo Nome não pode ser vazio") .Length(3, 100).WithMessage("O campo Nome precisa ter de {MinLength} a {MaxLength} caracteres"); When(p => p.ProviderType == ProviderType.LegalPerson, () => { RuleFor(p => p.DocumentNumber.Length).Equal(CnpjValidation.TamanhoCnpj).WithMessage("O campo Cnpj precisa ter {ComparisonValue} caracteres"); RuleFor(p => CnpjValidation.Validate(p.DocumentNumber)).Equal(true).WithMessage("O Cnpj fornecido é inválido"); }); When(p => p.ProviderType == ProviderType.PhysicalPerson, () => { RuleFor(p => p.DocumentNumber.Length).Equal(CpfValidation.TamanhoCpf).WithMessage("O campo Cpf precisa ter {ComparisonValue} caracteres"); RuleFor(p => CpfValidation.Validate(p.DocumentNumber)).Equal(true).WithMessage("O Cpf fornecido é inválido"); }); }
public SupplierValidation() { RuleFor(x => x.Name) .NotEmpty().WithMessage("The field {PropertyName} is required.") .Length(2, 100).WithMessage("The field {PropertyName} must have between {MinLenght} and {MaxLength} characters."); When(x => x.SupplierType == SupplierType.PF, () => { RuleFor(x => x.Document.Length).Equal(CpfValidation.CpfSize).WithMessage("The document field must have {ComparisonValue} characters."); RuleFor(x => CpfValidation.Validate(x.Document)).Equal(true).WithMessage("The document provided is invalid."); }); When(f => f.SupplierType == SupplierType.PJ, () => { RuleFor(f => f.Document.Length).Equal(CnpjValidation.CnpjSize).WithMessage("The Document field must have {ComparisonValue} characters."); RuleFor(f => CnpjValidation.Validate(f.Document)).Equal(true).WithMessage("The document provided is invalid."); }); }
public SupplierValidation() { RuleFor(s => s.Name) .NotEmpty() .WithMessage("O campo {PropertyName} é obrigatório") .Length(2, 100) .WithMessage("O campo {PropertyName} precisa ter entre {MinLength} e {MaxLength} caracteres"); When(s => s.SupplierType == SupplierType.IndividualRegistration, () => { RuleFor(s => s.Document.Length).Equal(CpfValidation.CPF_LENGTH) .WithMessage("O campo Documento precisa ter {ComparisonValue} caracteres e foi fornecido {PropertyValue}"); RuleFor(s => CpfValidation.Validate(s.Document)).Equal(true) .WithMessage("O CPF está em formato inválido"); }); When(s => s.SupplierType == SupplierType.LegalEntityRegistration, () => { RuleFor(s => s.Document.Length).Equal(CnpjValidation.CNPJ_LENGTH) .WithMessage("O campo Documento precisa ter {ComparisonValue} caracteres e foi fornecido {PropertyValue}"); RuleFor(s => CnpjValidation.Validate(s.Document)).Equal(true) .WithMessage("O CNPJ está em formato inválido"); }); }
public SupplierValidation() { RuleFor(s => s.Name) .NotEmpty().WithMessage("{PropertyName} field must be provided") .Length(2, 100).WithMessage("{PropertyName field must be between {MinLength} and {MaxLength} characters}"); When(s => s.SupplierType == SupplierType.NaturalPerson, () => { RuleFor(s => s.Document.Length).Equal(CpfValidation.CpfSize) .WithMessage("Document field must be {ComparisonValue} characters long and has been provided {PropertyValue}."); RuleFor(s => CpfValidation.Validate(s.Document)).Equal(true) .WithMessage("The document provided is invalid"); }); When(s => s.SupplierType == SupplierType.LegalEntity, () => { RuleFor(s => s.Document.Length).Equal(CnpjValidation.CnpjSize) .WithMessage("Document field must be {ComparisonValue} characters long and has been provived {PropertyValue}"); RuleFor(s => CnpjValidation.Validate(s.Document)).Equal(true) .WithMessage("The document provided is invalid"); }); }
public ProviderValidation() { RuleFor(p => p.Name) .NotEmpty().WithMessage("O Campo {PropertyName} precisa ser informado.") .Length(min: 2, max: 100).WithMessage("O Campo {PropertyName} precisa ter entre {MinLength} e {MaxLength} caracteres"); When(f => f.ProviderType == ProviderType.PhysicalPerson, () => { RuleFor(f => f.Document.Length) .Equal(CpfValidation.CpfLength) .WithMessage("O Campo Documento precisa ter {ComparisonValue} caracteres e foi fornecido {PropertyValue}"); RuleFor(f => CpfValidation.Validate(f.Document)).Equal(true) .WithMessage("O Documento fornecido é inválido"); }); When(f => f.ProviderType == ProviderType.LegalPerson, () => { RuleFor(f => f.Document.Length) .Equal(CnpjValidation.CpfLength) .WithMessage("O Campo Documento precisa ter {ComparisonValue} caracteres e foi fornecido {PropertyValue}"); RuleFor(f => CnpjValidation.Validate(f.Document)).Equal(true) .WithMessage("O Documento fornecido é inválido"); }); }