BudgetAnalyser.Engine.GlobalFilterCriteria.Validate C# (CSharp) Method

Validate() public method

Validate the instance and populate any warnings and errors into the validationMessages string builder.
public Validate ( StringBuilder validationMessages ) : bool
validationMessages StringBuilder A non-null string builder that will be appended to for any messages.
return bool
        public bool Validate(StringBuilder validationMessages)
        {
            if (validationMessages == null) throw new ArgumentNullException(nameof(validationMessages));

            if (Cleared)
            {
                BeginDate = null;
                EndDate = null;
                return true;
            }

            var valid = true;
            if (BeginDate == null)
            {
                validationMessages.AppendLine("Begin date cannot be blank unless filter is 'Cleared'.");
                valid = false;
            }

            if (EndDate == null)
            {
                validationMessages.AppendLine("End date cannot be blank unless filter is 'Cleared'.");
                valid = false;
            }

            if (BeginDate > EndDate)
            {
                validationMessages.AppendLine("Begin Date cannot be after the End Date.");
                valid = false;
            }

            return valid;
        }

Usage Example

 public void ValidateShouldThrowGivenNullValidationMessages()
 {
     var subject = new GlobalFilterCriteria { BeginDate = new DateTime(), EndDate = DateTime.Now };
     Assert.IsFalse(subject.Validate(null));
 }
All Usage Examples Of BudgetAnalyser.Engine.GlobalFilterCriteria::Validate