Ejemplo n.º 1
0
        public void TestGetObjWithInit()
        {
            var injector = new SimpleInjector();

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

            injector.Resolve<PerfTester>();

            PerformTest(() => injector.Resolve<PerfTester>());
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        public void TestSimpleBinding()
        {
            var injector = new SimpleInjector();

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

            Assert.IsNotNull(injector.Resolve<Dependency>());
        }
Ejemplo n.º 5
0
        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>());
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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));
            });
        }
Ejemplo n.º 10
0
        public void TestSelfBind()
        {
            var injector = new SimpleInjector();

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