Ejemplo n.º 1
0
        public async Task For_AsyncClassValidator_When_ProvidedNotNullObjToValidate_Then_ValidationErrorsAreReturned()
        {
            // Arrange:
            var asyncClassValidator = new AsyncClassValidator();
            var toValidate          = new TestClass
            {
                StringProperty = "",
                IntField       = 0
            };

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

            // Assert:
            validationErrors.Count.Should().Be(2);

            validationErrors[0].ErrorMessage.Should().Contain("Cannot have value less");
            validationErrors[0].ErrorCode.Should().Be("STR_LESS_THAN_MIN_LENGTH");
            validationErrors[0].PropertyPath.IsEmpty.Should().BeFalse();
            validationErrors[0].PropertyPath.ToString().Should().Be("StringProperty");
            validationErrors[0].ProvidedValue.Should().Be("");

            validationErrors[1].ErrorMessage.Should().Contain("Value must be greater than");
            validationErrors[1].ErrorCode.Should().Be("NUM_LESS_OR_THAN_OR_EQUAL_TO");
            validationErrors[1].PropertyPath.IsEmpty.Should().BeFalse();
            validationErrors[1].PropertyPath.ToString().Should().Be("IntField");
            validationErrors[1].ProvidedValue.Should().Be(0);
        }
Ejemplo n.º 2
0
        public void For_AsyncClassValidator_When_ProvidedNullObjToValidate_Then_ExceptionIsThrown()
        {
            // Arrange:
            var asyncValidator = new AsyncClassValidator();

            // Act:
            Assert.ThrowsAsync <ArgumentNullException>(() => asyncValidator.Validate(null));
        }