NUnit.Framework.Assertions.AdhocTestExecutionTests.RestoreExecutionContext(TestExecutionContext)

Here are the examples of the csharp api class NUnit.Framework.Assertions.AdhocTestExecutionTests.RestoreExecutionContext(TestExecutionContext) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Example 7

1. Example

Project: nunit
Source File: AdhocTestExecutionTests.cs
[TestCaseSource(typeof(AdhocTests), nameof(AdhocTests.TestMethods))]
        public void CanCallAssertWithoutTestExecutionContext(MethodInfo method)
        {
            var savedContext = ClearExecutionContext();
            Exception testException = null;

            try
            {
                // Currently, we know all the tests are static, without arguments
                method.Invoke(null, null);
            }
            catch(Exception ex)
            {
                testException = ex is TargetInvocationException
                    ? ex.InnerException
                    : ex;
            }
            finally
            {
                RestoreExecutionContext(savedContext);
            }

            // Throw any exception we got only after context is restored
            if (testException != null)
                throw testException;
        }