Esempio n. 1
0
        public void TestContextSelf()
        {
            IDIContext context = new MiniocContext();

            context.s().BindInstance <IDIContext>(context);
            context.s().Bind <IApple>(() => new YellowApple());

            IApple apple = context.Resolve <IApple>();

            Assert.That(apple is YellowApple);
            apple.TestContext(context);
        }
Esempio n. 2
0
        public void TestInjectionPropertiesNotClosedContextException()
        {
            IDIContext context = new MiniocContext();

            context.s().BindInstance <IDIContext>(context);
            context.s().Bind <IApple>(() => new WrongApple());

            Assert.Throws <MiniocException>(() =>
            {
                context.Resolve <IApple>();
            });
        }
Esempio n. 3
0
        public void SingletoneFactorySameContextTest()
        {
            IDIContext context = new MiniocContext();

            context.s().BindInstance <IDIContext>(context);
            context.s().Bind <IApple>(() => new GreenApple());

            IApple apple1 = context.Resolve <IApple>();
            IApple apple2 = context.Resolve <IApple>();

            Assert.That(apple1 is GreenApple);
            Assert.That(apple2 is GreenApple);

            Assert.AreSame(apple1, apple2);
        }
Esempio n. 4
0
        private static IDIContext InternalCreateContext(IDIContext parent, string name)
        {
            IDIContext context = new MiniocContext(parent, name);

            // Binding context itself
            context.s().BindInstance <IDIContext>(context);

            return(context);
        }
Esempio n. 5
0
        public void TestSingletonPersistance()
        {
            MiniocContext context = new MiniocContext();

            context.s().Bind <IOrange>(() => new BlueOrange());

            SingletoneCreation(context);

            IOrange orange = context.Resolve <IOrange>();

            Assert.AreEqual("my_test_orange", orange.tag);
        }
Esempio n. 6
0
        public void SingletoneSameContextTest()
        {
            MiniocContext context = new MiniocContext();

            context.s().Bind <IOrange>(() => new RedOrange());

            IOrange orange1 = context.Resolve <IOrange>();
            IOrange orange2 = context.Resolve <IOrange>();

            Assert.That(orange1 is RedOrange);
            Assert.That(orange2 is RedOrange);

            Assert.AreSame(orange1, orange2);
        }
Esempio n. 7
0
        public void SingletoneFactoryDifferentContextTest()
        {
            IDIContext context1 = new MiniocContext();

            context1.s().Bind <IOrange>(() => new RedOrange());

            IDIContext context2 = new MiniocContext();

            context2.s().Bind <IOrange>(() => new RedOrange());

            IOrange orange1 = context1.Resolve <IOrange>();
            IOrange orange2 = context2.Resolve <IOrange>();

            Assert.That(orange1 is RedOrange);
            Assert.That(orange2 is RedOrange);

            Assert.AreNotSame(orange1, orange2);
        }
Esempio n. 8
0
        public void SingletoneChainedContextTest()
        {
            MiniocContext context1 = new MiniocContext();


            context1.s().Bind <IOrange>(() => new RedOrange());

            MiniocContext context2 = new MiniocContext(context1);

            IOrange orange1 = context1.Resolve <IOrange>();
            IOrange orange2 = context2.Resolve <IOrange>();

            Assert.That(orange1 is RedOrange);
            Assert.That(orange2 is RedOrange);

            Assert.AreSame(orange1, orange2);

            context2.s().Bind <IOrange>(() => new RedOrange());

            orange2 = context2.Resolve <IOrange>();
            Assert.That(orange2 is RedOrange);
            Assert.AreNotSame(orange1, orange2);
        }