public void HaveAttributeGeneric()
		{
			ExportStrategyFilter filter = ExportsThat.HaveAttribute<SomeTestAttribute>();

			FauxExportStrategy failStrategy = new FauxExportStrategy(() => new object())
			                                  {
				                                  Attributes = new Attribute[0]
			                                  };

			FauxExportStrategy passStrategy = new FauxExportStrategy(() => new object())
			                                  {
				                                  Attributes = new Attribute[] { new SomeTestAttribute() }
			                                  };

			Assert.True(filter(new FauxInjectionContext(), passStrategy));
			Assert.False(filter(new FauxInjectionContext(), failStrategy));
		}
		public void HaveAttributeFiltered()
		{
			ExportStrategyFilter filter = ExportsThat.HaveAttribute(typeof(SomeTestAttribute),
				attribute => ((SomeTestAttribute)attribute).TestValue == 5);

			FauxExportStrategy failStrategy = new FauxExportStrategy(() => new object())
			                                  {
				                                  Attributes = new Attribute[0]
			                                  };

			FauxExportStrategy failStrategy2 = new FauxExportStrategy(() => new object())
			                                   {
				                                   Attributes = new Attribute[] { new SomeTestAttribute() }
			                                   };

			FauxExportStrategy passStrategy = new FauxExportStrategy(() => new object())
			                                  {
				                                  Attributes = new Attribute[] { new SomeTestAttribute { TestValue = 5 } }
			                                  };

			Assert.True(filter(new FauxInjectionContext(), passStrategy));
			Assert.False(filter(new FauxInjectionContext(), failStrategy));
			Assert.False(filter(new FauxInjectionContext(), failStrategy2));
		}
		public void OrFiltered()
		{
			ExportStrategyFilter filter = ExportsThat.HaveAttribute<SomeTestAttribute>(attribute => attribute.TestValue == 5).Or.
																	HaveAttribute<SomeTestAttribute>(attribute => attribute.TestValue == 3);

			FauxExportStrategy failStrategy = new FauxExportStrategy(() => new object())
			{
				Attributes = new Attribute[] { new SomeTestAttribute { TestValue = 0 } }
			};

			FauxExportStrategy passStrategy = new FauxExportStrategy(() => new object())
			{
				Attributes = new Attribute[] { new SomeTestAttribute { TestValue = 5 } }
			};

			FauxExportStrategy passStrategy2 = new FauxExportStrategy(() => new object())
			{
				Attributes = new Attribute[] { new SomeTestAttribute{TestValue = 3} }
			};

			Assert.True(filter(new FauxInjectionContext(), passStrategy));
			Assert.True(filter(new FauxInjectionContext(), passStrategy2));
			Assert.False(filter(new FauxInjectionContext(), failStrategy));
		}
        public void RemoveTest()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            FauxExportStrategy tenExport = new FauxExportStrategy(() => 10) { Priority = 10 };

            collection.AddExport(new FauxExportStrategy(() => 5) { Priority = 5 }, null);
            collection.AddExport(tenExport, null);
            collection.AddExport(new FauxExportStrategy(() => 1) { Priority = 1 }, null);

            Assert.Equal(10, collection.Activate(null, null, new FauxInjectionContext(), null, null));

            collection.RemoveExport(tenExport, null);

            Assert.Equal(5, collection.Activate(null, null, new FauxInjectionContext(), null, null));
            Assert.Equal(2, collection.ActivateAll<int>(new FauxInjectionContext(), null, null).Count());
        }
        public void ImportMethodTest()
        {
            FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService())
                                                         {
                                                             ExportTypes = new[] { typeof(IBasicService) }
                                                         };

            FauxInjectionScope injectionScope = new FauxInjectionScope();

            injectionScope.AddStrategy(basicService);

            CompiledExportDelegateInfo info = new CompiledExportDelegateInfo
                                                         {
                                                             ActivationType = typeof(ImportMethodService),
                                                             Attributes = new Attribute[0]
                                                         };

            info.ImportMethod(new ImportMethodInfo
                                    {
                                        MethodToImport =
                                            typeof(ImportMethodService).GetRuntimeMethod("ImportMethod", new[] { typeof(IBasicService) })
                                    });

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

            ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate();

            Assert.NotNull(activationDelegate);

            ImportMethodService propertyService =
                (ImportMethodService)activationDelegate(injectionScope, new InjectionContext(null, injectionScope));

            Assert.NotNull(propertyService);
        }
        public void ImportPropertyRootTransientTest()
        {
            FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService())
                                                         {
                                                             ExportTypes = new[] { typeof(IBasicService) }
                                                         };

            FauxInjectionScope injectionScope = new FauxInjectionScope();

            injectionScope.AddStrategy(basicService);

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

            info.ImportProperty(new ImportPropertyInfo
                                      {
                                          Property =
                                              typeof(ImportPropertyService).GetProperty("BasicService")
                                      });

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

            ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate();

            Assert.NotNull(activationDelegate);

            IImportPropertyService propertyService =
                (IImportPropertyService)activationDelegate(injectionScope, new InjectionContext(null, injectionScope));

            Assert.NotNull(propertyService);
            Assert.NotNull(propertyService.BasicService);
        }
        public void ImportPropertyNonRootTransienTest()
        {
            FauxExportStrategy basicService = new FauxExportStrategy(() => new BasicService())
                                                         {
                                                             ExportTypes = new[] { typeof(IBasicService) }
                                                         };

            InjectionKernelManager manager =
                new InjectionKernelManager(null, DependencyInjectionContainer.CompareExportStrategies, new BlackList());
            InjectionKernel injectionScope =
                new InjectionKernel(manager, null, null, "Root", DependencyInjectionContainer.CompareExportStrategies);

            injectionScope.AddStrategy(basicService);

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

            info.ImportProperty(new ImportPropertyInfo
                                      {
                                          Property =
                                              typeof(ImportPropertyService).GetProperty("BasicService")
                                      });

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

            ExportActivationDelegate activationDelegate = compiledExport.CompileDelegate();

            Assert.NotNull(activationDelegate);

            IInjectionScope requestingScope = injectionScope.CreateChildScope();

            IImportPropertyService propertyService =
                (IImportPropertyService)activationDelegate(injectionScope, new InjectionContext(null, requestingScope));

            Assert.NotNull(propertyService);
            Assert.NotNull(propertyService.BasicService);
        }