/** * 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.")); } }
/** * 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()))); // } }
/** * 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.")); } }
/** * 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()))); // } }
/** * 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")); } }
/** * 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")); } }
/** * 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")); } }
internal StateValidationVisitor(Dictionary <string, State> states, ValidationContext context) { _states = states; _currentContext = context; _problemReporter = context.ProblemReporter; }
/** * 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); }