Beispiel #1
0
        public async Task For_Validate_When_RootValidatorHasSetUpAsyncPropertyValidatorAndValidObjectIsPassed_Then_ValidationErrorsAreReturned()
        {
            // Arrange:
            var rootAsyncValidator = new RootAsyncValidatorImplementation();
            Expression <Func <RootValidatorsTestsCommon.TestClass, string> > expression = obj => obj.SomeProperty;

            rootAsyncValidator.SetupAsync(x => x.SomeProperty)
            .AddRule(async x =>
            {
                await Task.CompletedTask;
                return(x != null);
            }, "cannot be null", "NOT_NULL");
            var toValidate = (object)new RootValidatorsTestsCommon.TestClass
            {
                SomeProperty = null
            };

            // Act:
            var validationErrors = await rootAsyncValidator.Validate(toValidate);

            // Assert:
            validationErrors.Count.Should().Be(1);
            validationErrors[0].ErrorMessage.Should().Be("cannot be null");
            validationErrors[0].ErrorCode.Should().Be("NOT_NULL");
            validationErrors[0].PropertyPath.IsEmpty.Should().Be(false);
            validationErrors[0].ProvidedValue.Should().Be(null);
        }
Beispiel #2
0
        public async Task For_ValidateObj_When_ValidObjectIsPassed_Then_ValidationErrorsAreReturned()
        {
            // Arrange:
            var rootAsyncValidator = new RootAsyncValidatorImplementation();
            var toValidate         = (object)new RootValidatorsTestsCommon.TestClass();

            // Act:
            var result = await rootAsyncValidator.Validate(toValidate);

            // Assert:
            result.Count.Should().Be(0);
        }