Пример #1
0
        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 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 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());
		}
Пример #4
0
        public void StaticDelegateWithInstanceMethod()
        {
            DelegateFactoryObject fob = new DelegateFactoryObject();

            fob.DelegateType = typeof(PopHandler);
            fob.TargetType   = typeof(OneThirstyDude);
            fob.MethodName   = "HandlePop";
            fob.IsSingleton  = false;
            fob.AfterPropertiesSet();
            fob.GetObject();
        }
		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);
		}
Пример #6
0
        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));
        }
Пример #7
0
        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);
        }
		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));
		}