forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#20 trying to get more info why a couple of tests are failing only in CI
- Loading branch information
Showing
1 changed file
with
20 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Diagnostics; | ||
using App.Metrics.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Conduit.Tests.TestHelpers; | ||
|
||
public static class JsonTestHelpers | ||
{ | ||
public static T SubDoc<T>(this string @this, string subDocKey) | ||
{ | ||
var obj = JObject.Parse(@this); | ||
if (!obj.ContainsKey(subDocKey)) | ||
throw new ArgumentException($"SubDoc '{subDocKey}' not found in JSON."); | ||
return obj[subDocKey].ToObject<T>(); | ||
try | ||
{ | ||
var obj = JObject.Parse(@this); | ||
if (!obj.ContainsKey(subDocKey)) | ||
throw new ArgumentException($"SubDoc '{subDocKey}' not found in JSON."); | ||
return obj[subDocKey].ToObject<T>(); | ||
} | ||
catch | ||
{ | ||
Trace.WriteLine("TRACE There was a problem getting the subdoc of '{subDocKey}' from this JSON string: '{@this}"); | ||
Debug.Print($"DEBUG There was a problem getting the subdoc of '{subDocKey}' from this JSON string: '{@this}"); | ||
var logfactory = (ILoggerFactory)new LoggerFactory(); | ||
var logger = new Logger<Conduit.Web.Program>(logfactory); | ||
logger.LogError($"TRACE There was a problem getting the subdoc of '{subDocKey}' from this JSON string: '{@this}"); | ||
throw; | ||
} | ||
} | ||
} |