public void Validate_Should_ReturnError()
        {
            var validator = new RequiredGuidValidator();
            var product   = new Product();

            var selector = ValidatorOptions.ValidatorSelectors.DefaultValidatorSelectorFactory();
            var context  = new PropertyValidatorContext(
                new ValidationContext(product, new PropertyChain(), selector)
                , PropertyRule.Create <Product, Guid>(p => p.Id)
                , nameof(product.Id)
                , product.Id);

            var result = validator.Validate(context);

            result.Should().HaveCount(1);
            result.First().ErrorMessage.Should().Contain("required");
        }
Beispiel #2
0
        public void Validate_Should_ReturnNoErrors()
        {
            var validator = new RequiredGuidValidator();
            var product   = new Product {
                ProductType = ProductType.Hardware
            };

            var selector = ValidatorOptions.ValidatorSelectors.DefaultValidatorSelectorFactory();
            var context  = new PropertyValidatorContext(
                new ValidationContext(product, new PropertyChain(), selector)
                , PropertyRule.Create <Product, ProductType>(p => p.ProductType)
                , nameof(product.ProductType)
                , product.ProductType);

            var result = validator.Validate(context);

            result.Should().HaveCount(0);
        }