Пример #1
0
        public static void CheckRunNUnitTestInPartialTrust(AppDomain withAppDomain, PartialTrustMethodRunner <T> marshaller)
        {
            var findMethodInfo = FindCurrentTestMethodInfo();

            try
            {
                RunInPartial(findMethodInfo, withAppDomain, marshaller);
            }
            catch (SuccessException assertPass)
            {
                /* This means the test passed with a direct call to Pass, so do nothing */
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Runs the provided <paramref name="methodInfo"/> in the <paramref name="partiallyTrustedDomain"/>.
        /// If <paramref name="marshaller"/> is provided, it will be used, otherwise a new one will be created.
        /// </summary>
        /// <param name="methodInfo">The method info.</param>
        /// <param name="partiallyTrustedDomain">The partially trusted domain.</param>
        /// <param name="marshaller">The marshaller.</param>
        public static void RunInPartial(MethodInfo methodInfo, AppDomain partiallyTrustedDomain, PartialTrustMethodRunner <T> marshaller = null)
        {
            // Ensure no mistakes creep in and this code is actually running on the fully trusted AppDomain
            Assert.That(AppDomain.CurrentDomain.FriendlyName, Is.Not.StringStarting(PartialTrustAppDomainName));

            if (marshaller == null)
            {
                marshaller = GenerateMarshaller(partiallyTrustedDomain);
            }

            try
            {
                marshaller.Run(methodInfo);
            }
            catch (PartialTrustTestException ex)
            {
                throw ex;
            }
            catch (TargetInvocationException ex)
            {
                // If this gets raised, it could be because the method failed, or an assertion was called (either pass or failure)
                if (ex.InnerException != null)
                {
                    if (ex.InnerException is SuccessException)
                    {
                        /* Do nothing but return - it's NUnit's way of exiting out of a method when Assert.Pass() is called */
                        return;
                    }
                    Assert.Fail(ex.InnerException.ToString());
                }
                Assert.Fail("Failed but InnerException was null; " + ex.Message);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }