public static IContentAssert <JValue> IsLike(this IContentAssert <JValue> content, [RegexPattern] string pattern, RegexOptions options = RegexOptions.IgnoreCase) { return (Regex.IsMatch(content.Value?.Value <string>() ?? string.Empty, pattern, options) ? content : throw DynamicException.Create("ValueNotLike", $"Selected property value at '{content.Path}' is '{content.Value}' but should be like '{pattern}'.")); }
public static IContentAssert <JValue> IsEqual(this IContentAssert <JValue> content, object expected) { return (content.Value?.Equals(new JValue(expected)) == true ? content : throw DynamicException.Create("ValueNotEqual", $"Selected property value at '{content.Path}' is '{content.Value}' but should be '{expected}'.")); }
public static IContentAssert <JValue> IsNotNull(this IContentAssert <JValue> content) { return (content.Value is null ? throw DynamicException.Create("ValueNull", $"Selected property value at '{content.Path}' is null.") : content); }
public static IContentAssert <JToken> HasProperty(this IContentAssert <JToken> content, string jsonPath) { if (content.Value is null) { throw DynamicException.Create("ContentNull", "There is no content."); } return (content.Value.SelectToken(jsonPath) != null ? content : throw DynamicException.Create("ContentPropertyNotFound", $"There is no such property as '{jsonPath}'")); }
public static IContentAssert <JValue> Value(this IContentAssert <JToken> content, string jsonPath) { if (content.Value is null) { throw DynamicException.Create("ContentNull", "There is no content."); } return (content.Value.SelectToken(jsonPath) is JValue value ? new ContentAssert <JValue>(value) { Path = jsonPath } : throw DynamicException.Create("ContentPropertyNotFound", $"There is no such property as '{jsonPath}'")); }