Пример #1
0
        public void FactoryFiveArgWithOutBasicAndOutOfOrderTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            BasicService basicService = new BasicService();

            container.Configure(c =>
                                {
                                    c.Export<FiveArgParameterService>().As<IArrayOfObjectsPropertyService>();
                                    c.ExportInstance(basicService).As<IBasicService>();
                                });

            FiveArgParameterService.ActivateWithOutBasicServiceAndOutOfOrder factory =
                container.Locate<FiveArgParameterService.ActivateWithOutBasicServiceAndOutOfOrder>();

            Assert.NotNull(factory);

            IArrayOfObjectsPropertyService instance = factory(14.0m, "Blah", 9.0, 5);

            Assert.NotNull(instance);
            Assert.Equal(5, instance.Parameters.Length);
            Assert.Equal("Blah", instance.Parameters[0]);
            Assert.Equal(5, instance.Parameters[1]);
            Assert.Equal(9.0, instance.Parameters[2]);
            Assert.Equal(14.0m, instance.Parameters[3]);
            Assert.Equal(basicService, instance.Parameters[4]);
        }
Пример #2
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));
		}
Пример #3
0
        public void RegisterTypeExportTest()
        {
            InjectionContext injectionContext = new InjectionContext(null, null);

            IBasicService testValue = (IBasicService)injectionContext.Locate(typeof(IBasicService));

            Assert.Null(testValue);

            IBasicService newValue = new BasicService();

            injectionContext.Export((x, y) => newValue);

            testValue = (IBasicService)injectionContext.Locate(typeof(IBasicService));

            Assert.NotNull(testValue);
            Assert.True(ReferenceEquals(newValue, testValue));
        }
Пример #4
0
        public void LocateUnknownType()
        {
            InjectionContext injectionContext = new InjectionContext(null, null);

            IBasicService testValue = (IBasicService)injectionContext.Locate(typeof(IBasicService));

            Assert.Null(testValue);

            IBasicService newValue = new BasicService();

            injectionContext.Export((x, y) => newValue);

            Assert.Null(injectionContext.Locate(typeof(ImportConstructorService)));
        }
Пример #5
0
        public void SimpleNonDisposableTest()
        {
            Owned<IBasicService> owned = new Owned<IBasicService>();
            BasicService basicService = new BasicService();

            owned.SetValue(basicService);

            Assert.True(ReferenceEquals(owned.Value, basicService));

            owned.Dispose();
        }
Пример #6
0
        public void FactoryTwoArgWithoutBasicTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            BasicService basicService = new BasicService();

            container.Configure(c =>
                                {
                                    c.Export<TwoArgParameterService>().As<IArrayOfObjectsPropertyService>();
                                    c.ExportInstance(basicService).As<IBasicService>();
                                });

            TwoArgParameterService.ActivateWithOutBasicService factory =
                container.Locate<TwoArgParameterService.ActivateWithOutBasicService>();

            Assert.NotNull(factory);

            IArrayOfObjectsPropertyService instance = factory("Blah");

            Assert.NotNull(instance);

            Assert.Equal(2, instance.Parameters.Length);
            Assert.Equal("Blah", instance.Parameters[0]);
            Assert.Equal(basicService, instance.Parameters[1]);
        }
Пример #7
0
        public void FactoryThreeWithBasicServiceTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            BasicService basicService = new BasicService();

            container.Configure(c => c.Export<ThreeArgParameterService>().As<IArrayOfObjectsPropertyService>());

            ThreeArgParameterService.ActivateWithBasicService factory =
                container.Locate<ThreeArgParameterService.ActivateWithBasicService>();

            Assert.NotNull(factory);

            IArrayOfObjectsPropertyService instance = factory("Blah", 5, basicService);

            Assert.NotNull(instance);

            Assert.Equal(3, instance.Parameters.Length);
            Assert.Equal("Blah", instance.Parameters[0]);
            Assert.Equal(5, instance.Parameters[1]);
            Assert.Equal(basicService, instance.Parameters[2]);
        }
Пример #8
0
        public void FactorySomePropertyServiceWithBasicService()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c =>
                                {
                                    c.Export<ReferenceArgSomePropertyService>().As<ISomePropertyService>();
                                    c.Export<BasicService>().As<IBasicService>();
                                });

            SomePropertyServiceWithBasicService factory =
                container.Locate<SomePropertyServiceWithBasicService>();

            Assert.NotNull(factory);

            BasicService newBasicService = new BasicService();

            ISomePropertyService service = factory(newBasicService);

            Assert.NotNull(service);
            Assert.Same(newBasicService, service.SomeProperty);
        }
Пример #9
0
        public void FactoryOneArgWithBasicTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<OneArgRefParameterService>().As<IArrayOfObjectsPropertyService>());

            OneArgRefParameterService.ActivateWithBasicService factory =
                container.Locate<OneArgRefParameterService.ActivateWithBasicService>();

            Assert.NotNull(factory);

            BasicService basicService = new BasicService();

            IArrayOfObjectsPropertyService instance = factory(basicService);

            Assert.NotNull(instance);
            Assert.Equal(1, instance.Parameters.Length);
            Assert.Equal(basicService, instance.Parameters[0]);
        }