Exemple #1
0
        public void Bind_ToStrategy_Strategy_Is_Disposed_With_Container()
        {
            var strategy = new TestBindingStrategy<Bar1>(() => new Bar1());

            ComponentContainer container = new ComponentContainer();
            container.Bind<IBar>().ToStrategy(strategy);

            container.Dispose();

            Assert.IsTrue(strategy.DisposeWasCalled);
        }
Exemple #2
0
        public void Bind_ToStrategy_Calls_Strategy()
        {
            var strategy = new TestBindingStrategy<Bar1>(() => new Bar1());

            ComponentContainer container = new ComponentContainer();
            container.Bind<IBar>().ToStrategy(strategy);

            var bar = container.Resolve<IBar>();

            Assert.IsTrue(strategy.ResolveWasCalled);
        }
Exemple #3
0
        public void Bind_ToStrategy_Where_Strategy_Returns_Null_Throws_Exception()
        {
            var strategy = new TestBindingStrategy<Bar1>(() => null);

            ComponentContainer container = new ComponentContainer();
            container.Bind<IBar>().ToStrategy(strategy);

            var bar = container.Resolve<IBar>();
        }
Exemple #4
0
        public void Rebind_Calls_Dispose_On_Old_Binding()
        {
            var strategy = new TestBindingStrategy<IBar>(() => new Bar1());

            ComponentContainer container = new ComponentContainer();
            container.Bind<IBar>().ToStrategy(strategy);
            container.Rebind<IBar>().To<Bar2>();

            Assert.IsTrue(strategy.DisposeWasCalled);
        }
Exemple #5
0
        public void Bind_ToStrategy_Where_Strategy_Returns_Wrong_Type_Throws_Exception()
        {
            var strategy = new TestBindingStrategy<HasOneImplementor>(() => new HasOneImplementor());

            ComponentContainer container = new ComponentContainer();
            container.Bind<IBar>().ToStrategy(strategy);

            var bar = container.Resolve<IBar>();
        }