예제 #1
0
 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}'."));
 }
예제 #2
0
 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}'."));
 }
예제 #3
0
 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);
 }
예제 #4
0
        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}'"));
        }
예제 #5
0
        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}'"));
        }