private static T FromJson <T>(string json, string parameterName, JsonSerializerSettings settings)
 {
     try
     {
         return(JsonConvert.DeserializeObject <T>(json, settings));
     }
     catch (Exception e)
     {
         throw AssertException.CreateFromException($"Could not deserialize {parameterName} to an instance of type {typeof(T)}", e);
     }
 }
 private static string ToJson <T>(T item, string parameterName, JsonSerializerSettings settings)
 {
     try
     {
         return(JsonConvert.SerializeObject(item, settings));
     }
     catch (Exception e)
     {
         throw AssertException.CreateFromException($"Could not serialize{parameterName}.", e);
     }
 }
Beispiel #3
0
 private static JTokenAndSource ParseDocument(string json, string parameterName, JsonAssertOptions options)
 {
     try
     {
         var jObject = JToken.Parse(json);
         return(new JTokenAndSource(json, jObject, options));
     }
     catch (Exception e)
     {
         throw AssertException.CreateFromException($"{parameterName} is not valid Json.", e);
     }
 }