Skip to content

Commit

Permalink
#20 trying to get more info why a couple of tests are failing only in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroves committed Sep 25, 2023
1 parent a0b8182 commit baf9899
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Conduit/Conduit.Tests/TestHelpers/JsonTestHelpers.cs
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;
}
}
}

0 comments on commit baf9899

Please sign in to comment.