Exemplo n.º 1
0
        /// <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();
                }
            }));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Uninstalls any assertions generator for this thread, if there is one
 /// </summary>
 public static void RemoveAssertionsFactoryForCurrentThread()
 {
     ThreadAssertionGenerators.TryRemove(Thread.CurrentThread, out var _);
 }