Exemplo n.º 1
0
        public void ModelWithRequiredIfHasValueAttribute_ValidModel_ReturnsExpectedResults()
        {
            // Arrange
            var model = new ModelWithRequiredIfHasValueAttribute
            {
                DateInitialState = new DateTime(2020, 12, 3),
                InitialState     = 100000m
            };

            // Act
            var result = ModelValidator.Validate(model);

            // Assert
            AssertIsValid(result);
        }
Exemplo n.º 2
0
        public void ModelWithRequiredIfHasValueAttribute_InvalidModel_ReturnsExpectedResults()
        {
            // Arrange
            var model = new ModelWithRequiredIfHasValueAttribute
            {
                DateInitialState = new DateTime(2020, 12, 3),
                InitialState     = null
            };

            // Act
            var result = ModelValidator.Validate(model);

            // Assert
            AssertIsNotValid(result, nameof(model.InitialState), typeof(RequiredIfHasValueAttribute), ValidationType.RequiredIfHasValue);
            var attribute = (RequiredIfHasValueAttribute)GetValidationAttribute(result, nameof(model.InitialState));

            Assert.That(attribute.DependentProperty, Is.EqualTo(nameof(model.DateInitialState)));
        }