Exemple #1
0
        public void PredicateTrueAndRequiredFieldPopulated_Returns_True()
        {
            // Arrange
            var dto = new TestDto
            {
                PredicateProperty = true,
                TestField         = "bob"
            };
            var serviceProvider = new Mock <IServiceProvider>().Object;

            serviceProvider.GetService(dto.GetType());
            var validationContext = new ValidationContext(dto, serviceProvider, new Dictionary <object, object>());
            var sut            = new RequiredIfAttributesMatch(nameof(TestDto.PredicateProperty), true);
            var expectedResult = ValidationResult.Success;

            // Act
            var result = sut.GetValidationResult(dto.TestField, validationContext);

            // Assert
            Assert.Equal(expectedResult, result);
        }