Esempio n. 1
0
        public void TestGetObjWithoutInit()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj>();

            PerformTest(() => injector.Resolve<PerfTester>());
        }
Esempio n. 2
0
        public void TestSimpleBinding()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj>();

            Assert.IsNotNull(injector.Resolve<Dependency>());
        }
        public void TestBindingLookup()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj>().WithBinding(b => b.WhenType(t => t != typeof(Dependency)));
            injector.Bind<IMock>().Using<MockObj1>();

            Assert.IsNotNull(injector.Resolve<Dependency>());
        }
        public void TestParamCriteria()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj>().WithBinding(b => b.WhenParam(p => p.Name != "mock1"));
            injector.Bind<IMock>().Using<MockObj1>();

            var obj = injector.Resolve<Dependency1>();
            Assert.AreNotEqual(obj.first, obj.second);
        }
        public void TestParamLocation()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj1>().WithBinding(b => b.AtPosition(1));
            injector.Bind<IMock>().Using<MockObj>();

            var obj = injector.Resolve<Dependency1>();
            Assert.AreNotEqual(obj.first, obj.second);
        }
Esempio n. 6
0
        public void TestNoScope()
        {
            var injector = new SimpleInjector();

            injector.Bind<IMock>().Using<MockObj>();

            var obj = injector.Resolve<IMock>();
            var obj1 = injector.Resolve<IMock>();

            Assert.IsFalse(obj.Equals(obj1));
        }
        public void TestScope()
        {
            var injector = new SimpleInjector();

            var scopeObj = new object();

            injector.Bind<IMock>().Using<MockObj>().WithBinding(b => b.InScope(() => scopeObj));

            var obj = injector.Resolve<IMock>();
            var obj1 = injector.Resolve<IMock>();

            Assert.IsTrue(obj.Equals(obj1));
        }
        public void TestTypeBinding()
        {
            try
            {
                var injector = new SimpleInjector();

                injector.Bind<IMock>().Using<MockObj>().WithBinding(b => b.WhenType(t => t != typeof(Dependency)));

                injector.Resolve<Dependency>();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void TestConcurrentBinding()
        {
            var injector = new SimpleInjector();
            injector.Bind<IMock>().Using<MockObj>().WithBinding(b => b.InScope(() => Thread.CurrentThread));

            var obj = injector.Resolve<IMock>();
            Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);

            Task.Run(() =>
            {
                var obj2 = injector.Resolve<IMock>();
                Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
                Assert.IsFalse(obj2.Equals(obj));
            });
        }
Esempio n. 10
0
        public void TestSelfBind()
        {
            var injector = new SimpleInjector();

            Assert.IsTrue(injector.Equals(injector.Resolve<IInjector>()));
        }