public void NegatedValidatorReturnsSuccessForNullReference() { Validator validator = new NotNullValidator(true); ValidationResults validationResults = validator.Validate(null); Assert.IsTrue(validationResults.IsValid); }
public void Should_validate_property_value_without_instance() { var validator = new NotNullValidator(); var parentContext = new ValidationContext(null); var rule = new PropertyRule(null, x => null, null, null, typeof(string), null) { PropertyName = "Surname" }; var context = new PropertyValidatorContext(parentContext, rule, null); var result = validator.Validate(context); result.Single().ShouldNotBeNull(); }
public void ValidateSuccess() { try { NotNullValidator.Validate <SourceEntity>(null, c => c.Name, "test"); } catch (ApplicationException ex) { Assert.Contains("Name", ex.Message); } }
public void NonNegatedValidatorReturnsFailureForNullReference() { Validator validator = new NotNullValidator(); ValidationResults validationResults = validator.Validate(null); Assert.IsFalse(validationResults.IsValid); IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults); Assert.AreEqual(1, resultsList.Count); Assert.AreEqual(Resources.NonNullNonNegatedValidatorDefaultMessageTemplate, resultsList[0].Message); }
public void Should_validate_property_value_without_instance() { var validator = new NotNullValidator(); var parentContext = new ValidationContext <string>(null); var rule = new PropertyRule(null, x => null, null, null, typeof(string), null) { PropertyName = "Surname" }; var context = new PropertyValidatorContext(parentContext, rule, null); var result = validator.Validate(context); result.Single().ShouldNotBeNull(); }
public void ReturnsFailureWithOverriddenMessageForNullReference() { string message = "overriden message"; Validator validator = new NotNullValidator(message); ValidationResults validationResults = validator.Validate(null); Assert.IsFalse(validationResults.IsValid); IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults); Assert.AreEqual(1, resultsList.Count); Assert.AreEqual(message, resultsList[0].Message); }
public async Task <IndicatorGetListRp> Create(int customerId, string product, string source, string feature) { var createdBy = this._identityGateway.GetIdentity(); var productEntity = await this._dbContext.Products.Where(c => c.CustomerId == customerId && c.Name == product).SingleAsync(); var sourceEntity = NotNullValidator.Validate(await this._dbContext.GetSource(productEntity.Id.Value, source), c => c.Name, source); var featureEntity = await this._dbContext.Features.Where(c => c.ProductId == productEntity.Id && c.Name == feature).SingleAsync(); var sli = await this._dbContext.Indicators.Where(c => c.FeatureId == featureEntity.Id && c.SourceId == sourceEntity.Id).SingleOrDefaultAsync(); if (sli == null) { sli = IndicatorEntity.Factory.Create(featureEntity, sourceEntity, this._datetimeGateway.GetCurrentDateTime(), createdBy); this._dbContext.Indicators.Add(sli); await this._dbContext.SaveChangesAsync(); } return(this._mapper.Map <IndicatorGetListRp>(sli)); }
public void When_the_validator_fails_the_error_message_should_be_set() { var validator = new NotNullValidator(); var result = validator.Validate(new PropertyValidatorContext("name", null, x => null)); result.Single().ErrorMessage.ShouldEqual("'name' must not be empty."); }
public void Not_null_validator_should_work_ok_with_non_nullable_value_type() { var validator = new NotNullValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => 3)); result.Count().ShouldEqual(0); }
public void NotNullValidator_should_pass_if_value_has_value() { var validator = new NotNullValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => "Jeremy")); result.Count().ShouldEqual(0); }
public void NotNullValidator_should_fail_if_value_is_null() { var validator = new NotNullValidator(); var result = validator.Validate(new PropertyValidatorContext("name", new object(), x => null)); result.Single(); }
public void Should_validate_property_value_without_instance() { var validator = new NotNullValidator(); var context = new PropertyValidatorContext("Surname", null, null as object, null); validator.Validate(context).Single().ShouldNotBeNull(); }