public void TestBindClassGetInterface()
        {
            var injector = new Injector();

            var testClass = new TestClassFromInterface();

            injector.Bind <TestClassFromInterface>(testClass);

            Assert.Throws <InjectorException>(() => { injector.GetInstance <ITestInterface>(); },
                                              "injector should throw on get interface if just the class was bound.");
        }
        public void TestBindInterface()
        {
            var injector  = new Injector();
            var testClass = new TestClassFromInterface();

            injector.Bind <ITestInterface>(testClass);

            Assert.Throws <InjectorException>(() => { injector.GetInstance <TestClassFromInterface>(); },
                                              "getting class should throw if only interface bound.");

            Assert.DoesNotThrow(() => { injector.GetInstance <ITestInterface>(); }, "Injector should have instance.");

            Assert.AreEqual(testClass, injector.GetInstance <ITestInterface>(), "instance should be the same");
        }
        public void TestPostConstruct()
        {
            var injector       = new Injector();
            var testClass      = new TestClass();
            var otherTestClass = new TestClassFromInterface();

            injector.Bind <TestClass>(testClass);
            injector.Bind <ITestInterface>(otherTestClass);

            var injectingClass = new TestInjectingClass();

            injector.Bind <TestInjectingClass>(injectingClass);
            injector.PostBindings();

            Assert.IsTrue(injectingClass.PostConstructExecuted, "PostConstruct method should be executed");
        }
        public void TestInject()
        {
            var injector       = new Injector();
            var testClass      = new TestClass();
            var otherTestClass = new TestClassFromInterface();

            injector.Bind <TestClass>(testClass);
            injector.Bind <ITestInterface>(otherTestClass);

            var injectingClass = new TestInjectingClass();

            injector.Inject(injectingClass);

            Assert.AreEqual(testClass, injectingClass.GetTestClass(), "instance should be injected");
            Assert.AreEqual(otherTestClass, injectingClass.GetOtherTestClass(), "instance should be injected");
        }
        public void TestPostBindings()
        {
            var injector       = new Injector();
            var testClass      = new TestClass();
            var otherTestClass = new TestClassFromInterface();

            injector.Bind <TestClass>(testClass);
            injector.Bind <ITestInterface>(otherTestClass);

            var injectingClass = new TestInjectingClass();

            injector.Bind <TestInjectingClass>(injectingClass);
            injector.PostBindings();

            Assert.AreEqual(injectingClass, injector.GetInstance <TestInjectingClass>(), "should return bound instance");

            Assert.AreEqual(testClass, injectingClass.GetTestClass(), "instance should be injected");
            Assert.AreEqual(otherTestClass, injectingClass.GetOtherTestClass(), "instance should be injected");
        }