예제 #1
0
 /**
  * Asserts the string is not null and not empty, reporting to {@link ProblemReporter} with this context if it is.
  *
  * @param propertyValue Value to Assert on.
  * @param propertyName  Name of property.
  */
 public void AssertStringNotEmpty(string propertyValue, string propertyName)
 {
     if (string.IsNullOrEmpty(propertyValue))
     {
         ProblemReporter.Report(new Problem(this, $"{propertyName} is a required property."));
     }
 }
예제 #2
0
        /**
         * Asserts that the string represents a valid reference path expression.
         *
         * @param path         Path expression to validate.
         * @param propertyName Name of property.
         */
        public void AssertIsValidReferencePath(string path, string propertyName)
        {
            if (path == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                ProblemReporter.Report(new Problem(this, $"{propertyName} cannot be empty"));
            }

            //TODO: Find how to validate JPath query
            // try
            // {
            //     if (!JsonPath.isPathDefinite(path))
            //     {
            //         problemReporter.Report(new Problem(this,
            //             string.Format("{0} with value '{0}' is not a definite reference path.",
            //                 propertyName, path)));
            //     }
            // }
            // catch (InvalidPathException e)
            // {
            //     problemReporter.Report(new Problem(this,
            //         string.Format("{0} with value '{0}' is not a valid JsonPath. {0}", propertyName, path,
            //             e.getMessage())));
            // }
        }
예제 #3
0
 /**
  * Asserts the value is not null, reporting to {@link ProblemReporter} with this context if it is.
  *
  * @param propertyValue Value to Assert on.
  * @param propertyName  Name of property.
  */
 public void AssertNotNull(object propertyValue, string propertyName)
 {
     if (propertyValue == null)
     {
         ProblemReporter.Report(new Problem(this, $"{propertyName} is a required property."));
     }
 }
예제 #4
0
        /**
         * Asserts that the string represents a valid JsonPath expression.
         *
         * @param path         Path expression to validate.
         * @param propertyName Name of property.
         */
        public void AssertIsValidJsonPath(string path, string propertyName)
        {
            if (path == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                ProblemReporter.Report(new Problem(this, $"{propertyName} cannot be empty"));
            }

            //  JPath is an internal class of Newtonsoft... can't be used here
            //  JPath test = new JPath(path);
            //  TODO: Find how to validate JPath query
            // try
            // {
            //     JsonPath.compile(path);
            // }
            // catch (InvalidPathException e)
            // {
            //     problemReporter.Report(new Problem(this,
            //         string.Format("{0} with value '{1}' is not a valid JsonPath. {2}", propertyName, path,
            //             e.getMessage())));
            // }
        }
예제 #5
0
 /**
  * Asserts the integer is either null or non-negative, reporting to {@link ProblemReporter} with this context if it is.
  *
  * @param integer      Value to Assert on.
  * @param propertyName Name of property.
  */
 public void AssertIsNotNegativeIfPresent(int?integer, string propertyName)
 {
     if (integer.HasValue && integer < 0)
     {
         ProblemReporter.Report(new Problem(this, $"{propertyName} must be non negative"));
     }
 }
예제 #6
0
 /**
  * Asserts the map is not null and not empty, reporting to {@link ProblemReporter} with this context if it is.
  *
  * @param map          Map to Assert on.
  * @param propertyName Name of property.
  */
 public void AssertNotEmpty(IDictionary map, string propertyName)
 {
     if (map == null || map.Count == 0)
     {
         ProblemReporter.Report(new Problem(this,
                                            $"{propertyName} requires one or more entries"));
     }
 }
예제 #7
0
 /**
  * Asserts the collection is not null and not empty, reporting to {@link ProblemReporter} with this context if it is.
  *
  * @param collection   Collection to Assert on.
  * @param propertyName Name of property.
  */
 public void AssertNotEmpty(IEnumerable collection, string propertyName)
 {
     if (!collection.GetEnumerator().MoveNext())
     {
         ProblemReporter.Report(new Problem(this,
                                            $"{propertyName} requires one or more items"));
     }
 }
예제 #8
0
 internal StateValidationVisitor(Dictionary <string, State> states, ValidationContext context)
 {
     _states          = states;
     _currentContext  = context;
     _problemReporter = context.ProblemReporter;
 }
예제 #9
0
 /**
  * Sets the problem reporter to report problems in Assertion methods.
  *
  * @return This object for method chaining.
  */
 public Builder ProblemReporter(ProblemReporter problemReporter)
 {
     _problemReporter = problemReporter;
     return(this);
 }