Пример #1
0
        public void InPartialTrust_WhenMethodShouldSucceed_PartialTrustHelper_ReportsSuccess()
        {
            //LogHelper.TraceIfEnabled<PartialTrustHelperFixture>("In WhenTestShouldSucceed_InPartialTrust_PartialTrustHelper_ReportsSuccess");
            PartialTrustHelper <FakeFixture> .RunInPartial(Umbraco.Core.ExpressionHelper.GetMethodInfo <FakeFixture>(x => x.PartialTrustShouldSucceed()));

            Assert.Pass();
        }
        private static bool ShouldTestOnlyInFullTrust()
        {
            var currentTest = PartialTrustHelper <T> .FindCurrentTestMethodInfo();

            // If we can't find a compatible test, it might be because we cannot run it remotely in the
            // AppDomain e.g. if it's a parameterised test, in which case fail with a note
            if (currentTest == null)
            {
                Assert.Fail("Cannot find current test; is test parameterised?");
            }

            return(currentTest.GetCustomAttributes(typeof(TestOnlyInFullTrustAttribute), false).Any());
        }
Пример #3
0
        public void InPartialTrust_WhenMethodShouldNotSucceed_PartialTrustHelper_ReportsFailure()
        {
            //LogHelper.TraceIfEnabled<PartialTrustHelperFixture>("In WhenTestShouldNotSucceed_InPartialTrust_PartialTrustHelper_ReportsFailure");
            try
            {
                PartialTrustHelper <FakeFixture> .RunInPartial(Umbraco.Core.ExpressionHelper.GetMethodInfo <FakeFixture>(x => x.PartialTrustShouldFail()));
            }
            catch (PartialTrustTestException ex)
            {
                Assert.Pass("PartialTrustTestException raised, message: " + ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception was raised but it was not PartialTrustTestException, was: " + ex.Message);
            }

            Assert.Fail("No exception was raised");
        }
        protected void PartialTrustSetup()
        {
            if (ShouldTestOnlyInFullTrust())
            {
                // Do not run this test in partial trust
                TestSetup();
                return;
            }

            // First, run the TestSetup method in the partial trust domain
            _methodRunner.Run(Umbraco.Core.ExpressionHelper.GetMethodInfo <AbstractPartialTrustFixture <T> >(x => x.TestSetup()));

            // Now, run the actual test in the same appdomain
            PartialTrustHelper <T> .CheckRunNUnitTestInPartialTrust(_partialTrustAppDomain, _methodRunner);

            // If we get here, we've had no exceptions, so throw an NUnit SuccessException which will avoid rerunning the test
            // in the existing full-trust appdomain and cause the test to pass
            throw new SuccessException("Automatically avoided running test in full trust as it passed in partial trust");
        }
        protected virtual void FixtureSetup()
        {
            _partialTrustAppDomain = PartialTrustHelper <T> .CreatePartialTrustDomain();

            _methodRunner = PartialTrustHelper <T> .GenerateMarshaller(_partialTrustAppDomain);
        }