// Cannot use standard Assert.Throws() when testing Utf8JsonReader - ref structs and closures don't get along. public static TException AssertThrows <TException>(ref Utf8JsonReader json, AssertThrowsActionUtf8JsonReader action) where TException : Exception { Exception ex; try { action(ref json); ex = null; } catch (Exception e) { ex = e; } if (ex is TException matchingEx) { return(matchingEx); } throw ex is null ? new ThrowsException(typeof(TException)) : new ThrowsException(typeof(TException), ex); }
// Cannot use standard Assert.Throws() when testing Utf8JsonReader - ref structs and closures don't get along. public static void AssertThrows <E>(Utf8JsonReader json, AssertThrowsActionUtf8JsonReader action) where E : Exception { Exception ex; try { action(json); ex = null; } catch (Exception e) { ex = e; } if (ex == null) { throw new ThrowsException(typeof(E)); } if (!(ex is E)) { throw new ThrowsException(typeof(E), ex); } }