public void DisposalTest()
        {
            FauxInjectionScope injectionScope = new FauxInjectionScope();

            CompiledExportDelegateInfo info =
                new CompiledExportDelegateInfo
                {
                    ActivationType = typeof(DisposableService),
                    IsTransient = true,
                    TrackDisposable = true,
                    Attributes = new Attribute[0]
                };

            FuncCompiledExportDelegate compiledExport =
                new FuncCompiledExportDelegate(info, (x, y) => new DisposableService(), null, injectionScope);

            ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate();

            Assert.NotNull(activationDelegate);

            FauxInjectionContext context = new FauxInjectionContext
                                                     {
                                                         DisposalScope = new DisposalScope()
                                                     };

            IDisposableService disposableService = (IDisposableService)activationDelegate(injectionScope, context);

            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            context.DisposalScope.Dispose();

            Assert.True(eventFired);
        }
Ejemplo n.º 2
0
		public void ActivateTest()
		{
			FauxInjectionScope scope = new FauxInjectionScope();
			FauxInjectionContext context = new FauxInjectionContext { RequestingScope = scope };

			FuncValueProvider<IBasicService> provider =
				new FuncValueProvider<IBasicService>(() => new BasicService());

			object activated = provider.Activate(scope, context, null, null);

			Assert.NotNull(activated);
			Assert.IsType(typeof(BasicService), activated);
		}
Ejemplo n.º 3
0
		public void ActivateTest()
		{
			FauxInjectionScope scope = new FauxInjectionScope();
			FauxInjectionContext context = new FauxInjectionContext { RequestingScope = scope };

			BasicService basicService = new BasicService();

			InstanceStrategy<IBasicService> instanceStrategy = new InstanceStrategy<IBasicService>(basicService);

			object activatedObject = instanceStrategy.Activate(scope, context, null, null);

			Assert.True(ReferenceEquals(activatedObject, basicService));
		}
        public void MissingDisposalScopeTest()
        {
            FauxInjectionScope injectionScope = new FauxInjectionScope();

            CompiledExportDelegateInfo info =
                new CompiledExportDelegateInfo
                {
                    ActivationType = typeof(DisposableService),
                    IsTransient = true,
                    TrackDisposable = true,
                    Attributes = new Attribute[0]
                };

            FuncCompiledExportDelegate compiledExport =
                new FuncCompiledExportDelegate(info, (x, y) => new DisposableService(), null, injectionScope);

            ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate();

            Assert.NotNull(activationDelegate);

            FauxInjectionContext context = new FauxInjectionContext();

            try
            {
                IDisposableService disposableService = (IDisposableService)activationDelegate(injectionScope, context);

                throw new Exception("Should have thrown a DisposalScopeMissingException");
            }
            catch (DisposalScopeMissingException)
            {
            }
        }