Example #1
0
        public void SynchronizedLifetimeManagerRecoveryTestWithExceptionReThrownAndRecoverCalled()
        {
            var container = new QuickInjectContainer();

            container.AddBuildPlanVisitor(new LifetimeManagerRequiresRecoveryBuildPlanVisitor());

            var lifetime = new ThrowRecordingSynchronizedLifetimeManager();

            container.RegisterType <Foo>(lifetime, new ParameterizedLambdaExpressionInjectionFactory <Foo>(() => ThrowException()));

            bool exceptionWasReThrown = false;

            try
            {
                container.Resolve <Foo>();
            }
            catch (ArgumentNullException)
            {
                exceptionWasReThrown = true;
            }

            Assert.IsTrue(exceptionWasReThrown);
            Assert.IsTrue(lifetime.RecoverWasCalled);
        }
Example #2
0
        public void SynchronizedLifetimeManagerRecoveryTestWithExceptionReThrownAndRecoverCalled()
        {
            var container = new QuickInjectContainer();
            container.AddBuildPlanVisitor(new LifetimeManagerRequiresRecoveryBuildPlanVisitor());

            var lifetime = new ThrowRecordingSynchronizedLifetimeManager();
            container.RegisterType<Foo>(lifetime, new Microsoft.Practices.Unity.InjectionFactory(c =>
            {
                throw new ArgumentNullException("Foobar");
            }));

            bool exceptionWasReThrown = false;

            try
            {
                container.Resolve<Foo>();
            }
            catch (ArgumentNullException)
            {
                exceptionWasReThrown = true;
            }

            Assert.IsTrue(exceptionWasReThrown);
            Assert.IsTrue(lifetime.RecoverWasCalled);
        }