Beispiel #1
0
        public void BuildUpTests_BuildUp_Simple()
        {
            using var container = new StashboxContainer();
            ITest inst = new Test();

            container.BuildUp(inst);
        }
Beispiel #2
0
        public void BuildUpTests_BuildUp_As_InterfaceType()
        {
            using var container = new StashboxContainer();
            container.Register <ITest3, Test3>().Register <ITest, Test>();
            var test3 = new Test3();
            var inst  = (Test3)container.BuildUp <ITest3>(test3);

            Assert.NotNull(inst.Test);
        }
Beispiel #3
0
        public void BuildUpTests_BuildUp()
        {
            using var container = new StashboxContainer();
            container.Register <ITest, Test>();

            var test1 = new Test1();

            container.WireUp <ITest1>(test1);

            var test2 = new Test2();
            var inst  = container.BuildUp(test2);

            Assert.Equal(test2, inst);
            Assert.NotNull(inst);
            Assert.NotNull(inst.Test1);
            Assert.IsType <Test2>(inst);
            Assert.IsType <Test1>(inst.Test1);
            Assert.IsType <Test>(inst.Test1.Test);
        }
Beispiel #4
0
        public void ContainerTests_Throws_Disposed_Exceptions()
        {
            var container = new StashboxContainer();

            container.Dispose();

            Assert.Throws <ObjectDisposedException>(() => container.Activate(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.BeginScope());
            Assert.Throws <ObjectDisposedException>(() => container.BuildUp(new object()));
            Assert.Throws <ObjectDisposedException>(() => container.CanResolve(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.ComposeAssemblies(new[] { this.GetType().GetTypeInfo().Assembly }));
            Assert.Throws <ObjectDisposedException>(() => container.ComposeAssembly(this.GetType().GetTypeInfo().Assembly));
            Assert.Throws <ObjectDisposedException>(() => container.ComposeBy(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.Configure(c => { }));
            Assert.Throws <ObjectDisposedException>(() => container.CreateChildContainer());
            Assert.Throws <ObjectDisposedException>(() => container.GetRegistrationMappings());
#if HAS_SERVICEPROVIDER
            Assert.Throws <ObjectDisposedException>(() => container.GetService(this.GetType()));
#endif
            Assert.Throws <ObjectDisposedException>(() => container.IsRegistered(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.PutInstanceInScope(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.Register(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblies(new[] { this.GetType().GetTypeInfo().Assembly }));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterAssembly(this.GetType().GetTypeInfo().Assembly));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterAssemblyContaining <ITest1>());
            Assert.Throws <ObjectDisposedException>(() => container.RegisterDecorator(this.GetType(), this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterFunc <ITest1>(r => new Test1()));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterInstance(new object()));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterInstances(new object()));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterResolver(null));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterScoped <ITest1, Test1>());
            Assert.Throws <ObjectDisposedException>(() => container.RegisterSingleton <ITest1, Test1>());
            Assert.Throws <ObjectDisposedException>(() => container.RegisterTypes(new [] { this.GetType() }));
            Assert.Throws <ObjectDisposedException>(() => container.RegisterTypesAs <ITest1>(this.GetType().GetTypeInfo().Assembly));
            Assert.Throws <ObjectDisposedException>(() => container.ReMap <ITest1, Test1>());
            Assert.Throws <ObjectDisposedException>(() => container.ReMapDecorator(this.GetType(), this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.Resolve(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.ResolveAll(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.ResolveFactory(this.GetType()));
            Assert.Throws <ObjectDisposedException>(() => container.Validate());
            Assert.Throws <ObjectDisposedException>(() => container.WireUp(new object()));
        }
Beispiel #5
0
        public void InjectionMemberTests_BuildUp()
        {
            using (var container = new StashboxContainer())
            {
                container.RegisterType<ITest, Test>();

                var test1 = new Test1();
                container.BuildUp<ITest1>(test1);

                container.RegisterType<Test2>();

                var inst = container.Resolve<Test2>();

                Assert.IsNotNull(inst);
                Assert.IsNotNull(inst.Test1);
                Assert.IsInstanceOfType(inst, typeof(Test2));
                Assert.IsInstanceOfType(inst.Test1, typeof(Test1));
                Assert.IsInstanceOfType(inst.Test1.Test, typeof(Test));
            }
        }
Beispiel #6
0
        public void BuildUpTests_BuildUp()
        {
            using (var container = new StashboxContainer())
            {
                container.Register <ITest, Test>();

                var test1 = new Test1();
                container.WireUpAs <ITest1>(test1);

                var test2 = new Test2();
                var inst  = container.BuildUp(test2);

                Assert.AreEqual(test2, inst);
                Assert.IsNotNull(inst);
                Assert.IsNotNull(inst.Test1);
                Assert.IsInstanceOfType(inst, typeof(Test2));
                Assert.IsInstanceOfType(inst.Test1, typeof(Test1));
                Assert.IsInstanceOfType(inst.Test1.Test, typeof(Test));
            }
        }