/// <summary> /// Temporarily revert to UnmetExpectationExceptions, for this thread only /// </summary> /// <returns></returns> public static IDisposable TemporarilyUseDefaultAssertionsFactoryForThisThread() { var hadThreadSpecificGenerator = ThreadAssertionGenerators.TryGetValue( Thread.CurrentThread, out var originalGenerator ); return(new AutoResetter( () => RegisterAssertionsFactoryForCurrentThread( (s, e) => new UnmetExpectationException(s, e) ), () => { if (hadThreadSpecificGenerator) { RegisterAssertionsFactoryForCurrentThread(originalGenerator); } else { RemoveAssertionsFactoryForCurrentThread(); } })); }
/// <summary> /// Uninstalls any assertions generator for this thread, if there is one /// </summary> public static void RemoveAssertionsFactoryForCurrentThread() { ThreadAssertionGenerators.TryRemove(Thread.CurrentThread, out var _); }