public void UsingWrongCardTypeFails()
        {
            var errors = ModelValidator.ValidateObject(new ExampleModel2()).Errors;

            Assert.That(errors.Count, Is.EqualTo(1));

            Assert.That(errors[0].ErrorCode, Is.EqualTo(CreditCardErrorCodes.CreditCardTypeIsInvalid.ToString()));
            Assert.That(errors[0].FieldName, Is.EqualTo("WrongCardTypeForCardNumber"));
        }
Exemplo n.º 2
0
        public void Validate(ICollection <ValidationError> errors)
        {
            ModelValidator.ValidateObject(this, errors, nameof(TriggerViewModel.Trigger), nameof(TriggerPropertiesViewModel.Daily));

            if (RepeatForever == false && RepeatCount == null)
            {
                errors.Add(ValidationError.EmptyField("trigger[daily.repeatCount]"));
            }
        }
        public void NullAndEmptyStringFailsRequiredTextValidationTest()
        {
            var errorFieldNames = new[] { "EmptyString", "NullString" }.ToList();
            var errors = ModelValidator.ValidateObject(new ExampleModel1()).Errors;
            Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));

            Assert.That(errors.ToList().All(x => x.ErrorCode == ValidationErrorCodes.Required.ToString()));
            Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
        }
        public void Concrete_Validate_Ok()
        {
            var person = new Person {
                Name = "Helen"
            };

            person.Invoking(p => ModelValidator.ValidateObject(person))
            .ShouldNotThrow();
        }
		public void OnlyNullReferencesFailNotNullValidationTest()
		{
			var result = ModelValidator.ValidateObject(new ExampleModel1());
			Assert.That(result.Errors.Count, Is.EqualTo(1));

			var error = result.Errors[0];
			Assert.That(error.ErrorCode, Is.EqualTo(ValidationErrorCodes.Required.ToString()));
			Assert.That(error.FieldName, Is.EqualTo("NullString"));
		}
        public void ValidEmailValidationTest()
        {
            var errorFieldNames = new[] { "EmailWithoutTld", "EmptyString", "SimpleText", "EmailWithPlusChar" }.ToList();
            var errors = ModelValidator.ValidateObject(new ExampleModel1()).Errors;

            Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));

            Assert.That(errors.ToList().All(x => x.ErrorCode == ErrorCodes.EmailAddressIsNotValid.ToString()));
            Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
        }
        public void CardWithExpiredDateFails()
        {
            var errorFieldNames = new[] { "ExpiredByOneYear", "ExpiredByOneMonth" }.ToList();
            var errors = ModelValidator.ValidateObject(new ExampleModel4()).Errors;

            Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));

            Assert.That(errors.ToList().All(x => x.ErrorCode == CreditCardErrorCodes.CreditCardHasExpired.ToString()));
            Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
        }
        public void Concrete_Validate_Fail()
        {
            var person = new Person {
                Name = null
            };

            person.Invoking(p => ModelValidator.ValidateObject(person))
            .ShouldThrow <ValidationException>()
            .Which.Message.Should().Contain("The Name field is required");
        }
        public void UsingWrongCardHoldersNameFails()
        {
            var errorFieldNames = new[] { "NoCardHoldersName" }.ToList();
            var errors = ModelValidator.ValidateObject(new ExampleModel6()).Errors;

            Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));

            Assert.That(errors.ToList().All(x => x.ErrorCode == CreditCardErrorCodes.CreditCardHolderNameIsInvalid.ToString()));
            Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
        }
Exemplo n.º 10
0
        public void OnlyPublicPropertiesAreValidatedTest()
        {
            var result = ModelValidator.ValidateObject(new ExampleModel2());

            Assert.That(result.Errors.Count, Is.EqualTo(1));

            var error = result.Errors[0];

            Assert.That(error.ErrorCode, Is.EqualTo(ValidationErrorCodes.Required.ToString()));
            Assert.That(error.FieldName, Is.EqualTo("PublicProperty"));
        }
Exemplo n.º 11
0
        public void SingleNotNullValidationTest()
        {
            var result = ModelValidator.ValidateObject(new ExampleModel1());

            Assert.That(result.Errors.Count, Is.EqualTo(1));

            var error = result.Errors[0];

            Assert.That(error.ErrorCode, Is.EqualTo(ValidationErrorCodes.Required.ToString()));
            Assert.That(error.FieldName, Is.EqualTo("EmptyText"));
        }
        public void UsingInvalidCardNumbersFails()
        {
            var errorFieldNames = new[] {
                "CardNumberTooShort", "CardNumberTooLong", "CardNumberWithLetters"
            }.ToList();
            var errors = ModelValidator.ValidateObject(new ExampleModel3()).Errors;

            Assert.That(errors.Count, Is.EqualTo(errorFieldNames.Count));

            Assert.That(errors.ToList().All(x => x.ErrorCode == CreditCardErrorCodes.CreditCardNumberIsInvalid.ToString()));
            Assert.That(errors.ToList().All(x => errorFieldNames.Contains(x.FieldName)));
        }
Exemplo n.º 13
0
        public void Validate(ICollection <ValidationError> errors)
        {
            ModelValidator.ValidateObject(this, errors, camelCase: false);

            if (knownCalendars.TryGetValue(Type, out var o))
            {
                o.Validator(this, errors);
            }
            else
            {
                errors.Add(new ValidationError {
                    Field = nameof(Type), Reason = "Invalid value."
                });
            }
        }
        public void TwoInterfaces_Validate_Fail()
        {
            var person = new HumanPerson {
                Name = "Clumsy Cyclops", EyeCount = 1, FootCount = 1
            };

            person.Invoking(p => ModelValidator.ValidateObject(person))
            .ShouldThrow <ValidationException>()
            .Which.Message.Should().Match(m => m.Contains("EyeCount") || m.Contains("FootCount"));

            person.EyeCount = 2;
            person.Invoking(p => ModelValidator.ValidateObject(person))
            .ShouldThrow <ValidationException>()
            .WithMessage("*FootCount*");

            person.Name = null;
            person.Invoking(p => ModelValidator.ValidateObject(person))
            .ShouldThrow <ValidationException>()
            .WithMessage("*Name*required*");
        }
Exemplo n.º 15
0
 public void Validate(ICollection <ValidationError> errors)
 {
     ModelValidator.ValidateObject(this, errors, nameof(TriggerViewModel.Trigger), nameof(TriggerPropertiesViewModel.Cron));
 }
Exemplo n.º 16
0
 public void Validate(ICollection <ValidationError> errors) => ModelValidator.ValidateObject(this, errors);
 public void Update(TEntity item)
 {
     ModelValidator.ValidateObject(item);
     _inner.Update(item);
 }
 public void Add(TEntity item)
 {
     ModelValidator.ValidateObject(item);
     _inner.Add(item);
 }
Exemplo n.º 19
0
 public virtual ValidationResult Validate()
 {
     return(ModelValidator.ValidateObject(this));
 }
Exemplo n.º 20
0
 public void Validate(ICollection <ValidationError> errors) => ModelValidator.ValidateObject(this, errors, nameof(JobViewModel.Job));
        public void ValidCardInfoPasses()
        {
            var errors = ModelValidator.ValidateObject(new ExampleModel1()).Errors;

            Assert.That(errors.Count, Is.EqualTo(0));
        }