Ejemplo n.º 1
0
        public void TestGetFromPool()
        {
            IPool <ClassToBeInjected> pool = new Pool <ClassToBeInjected> ();

            // Format the pool
            pool.size             = 4;
            pool.instanceProvider = new TestInstanceProvider();

            IInjectionBinding binding = new InjectionBinding(resolver);

            binding.Bind <IPool <ClassToBeInjected> > ().To <Pool <ClassToBeInjected> > ().ToValue(pool);

            IPool <ClassToBeInjected> myPool = factory.Get(binding) as Pool <ClassToBeInjected>;

            Assert.NotNull(myPool);

            ClassToBeInjected instance1 = myPool.GetInstance() as ClassToBeInjected;

            Assert.NotNull(instance1);

            ClassToBeInjected instance2 = myPool.GetInstance() as ClassToBeInjected;

            Assert.NotNull(instance2);

            Assert.AreNotSame(instance1, instance2);
        }
Ejemplo n.º 2
0
        virtual protected IEvent CreateEvent(object eventType, object data)
        {
            IEvent retv = eventPool.GetInstance();

            retv.type   = eventType;
            retv.target = this;
            retv.data   = data;
            return(retv);
        }
        public void TestGetInstance()
        {
            binding.Size = 4;
            for (int a = 0; a < binding.Size; a++)
            {
                b.To(new ClassToBeInjected());
            }

            for (int a = binding.Size; a > 0; a--)
            {
                Assert.AreEqual(a, binding.Available);
                ClassToBeInjected instance = binding.GetInstance() as ClassToBeInjected;
                Assert.IsNotNull(instance);
                Assert.IsInstanceOf <ClassToBeInjected> (instance);
                Assert.AreEqual(a - 1, binding.Available);
            }
        }
Ejemplo n.º 4
0
        public void TestCleanupInjections()
        {
            injectionBinder.Bind <ISimpleInterface> ().To <SimpleInterfaceImplementer> ();
            commandBinder.Bind(SomeEnum.ONE).To <CommandWithInjection> ().Pooled();

            commandBinder.ReactTo(SomeEnum.ONE);
            IPool <CommandWithInjection> pool = pooledCommandBinder.GetPool <CommandWithInjection> ();

            CommandWithInjection cmd = pool.GetInstance() as CommandWithInjection;

            Assert.AreEqual(1, pool.instanceCount);                     //These just assert our expectation that there's one instance
            Assert.AreEqual(0, pool.available);                         //and we're looking at it.

            Assert.IsNull(cmd.injected);
        }
Ejemplo n.º 5
0
        public void TestCleanupInjections()
        {
            injectionBinder.Bind <ISimpleInterface> ().To <SimpleInterfaceImplementer> ();
            commandBinder.Bind(singleSignal).To <CommandWithInjectionPlusSignalPayload> ().Pooled();

            singleSignal.Dispatch(42);
            IPool <CommandWithInjectionPlusSignalPayload> pool = pooledCommandBinder.GetPool <CommandWithInjectionPlusSignalPayload> ();

            CommandWithInjectionPlusSignalPayload cmd = pool.GetInstance() as CommandWithInjectionPlusSignalPayload;

            Assert.AreEqual(1, pool.instanceCount);                     //These just assert our expectation that there's one instance
            Assert.AreEqual(0, pool.available);                         //and we're looking at it.

            Assert.IsNull(cmd.injected);
        }
        public void TestExceptionsIfNotPool()
        {
            Binding failBinding = new Binding();
            IPool   fb          = (failBinding as IPool);

            assertThrowsFailedFacade(
                delegate(){ Console.WriteLine(fb.Available); }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.Clean(); }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.GetInstance(); }
                );
            assertThrowsFailedFacade(
                delegate(){ Console.WriteLine(fb.InflationType); }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.InflationType = PoolInflationType.DOUBLE; }
                );
            assertThrowsFailedFacade(
                delegate(){ Console.WriteLine(fb.OverflowBehavior); }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.OverflowBehavior = PoolOverflowBehavior.WARNING; }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.ReturnInstance("hello"); }
                );
            assertThrowsFailedFacade(
                delegate(){ Console.WriteLine(fb.Size); }
                );
            assertThrowsFailedFacade(
                delegate(){ fb.Size = 1; }
                );
        }