public void InstancePrototypeDelegate()
        {
            DelegateFactoryObject fob = new DelegateFactoryObject();

            fob.IsSingleton  = false;
            fob.DelegateType = typeof(PopHandler);
            OneThirstyDude dude = new OneThirstyDude();

            fob.TargetObject = dude;
            fob.MethodName   = "HandlePop";
            fob.IsSingleton  = false;
            fob.AfterPropertiesSet();
            PopHandler one = (PopHandler)fob.GetObject();
            PopHandler two = (PopHandler)fob.GetObject();

            Assert.IsFalse(ReferenceEquals(one, two));
        }
        public void StaticDelegateWithInstanceMethod()
        {
            DelegateFactoryObject fob = new DelegateFactoryObject();

            fob.DelegateType = typeof(PopHandler);
            fob.TargetType   = typeof(OneThirstyDude);
            fob.MethodName   = "HandlePop";
            fob.IsSingleton  = false;
            fob.AfterPropertiesSet();
            Assert.Throws <ArgumentException>(() => fob.GetObject());
        }
        public void InstanceSingletonDelegate()
        {
            DelegateFactoryObject fob = new DelegateFactoryObject();

            fob.DelegateType = typeof(PopHandler);
            OneThirstyDude dude = new OneThirstyDude();

            fob.TargetObject = dude;
            fob.MethodName   = "HandlePop";
            fob.AfterPropertiesSet();
            PopHandler popper = (PopHandler)fob.GetObject();

            Assert.IsNotNull(popper);
            Assert.AreEqual(fob.MethodName, popper.Method.Name);
            string soda = "The Drink Of Champions";

            popper(this, soda);
            Assert.AreEqual(soda, dude.Soda);
            PopHandler other = (PopHandler)fob.GetObject();

            Assert.IsTrue(ReferenceEquals(popper, other));
        }
        public void StaticDelegate()
        {
            DelegateFactoryObject fob = new DelegateFactoryObject();

            fob.DelegateType = typeof(PopHandler);
            fob.TargetType   = typeof(OneThirstyDude);
            fob.MethodName   = "StaticHandlePop";
            fob.IsSingleton  = false;
            fob.AfterPropertiesSet();
            PopHandler popper = (PopHandler)fob.GetObject();

            Assert.IsNotNull(popper);
            Assert.AreEqual(fob.MethodName, popper.Method.Name);
        }