Ejemplo n.º 1
0
 public void RaiseWithAnEventHandlerThatThrowsAnException () 
 {
     OneThirstyDude dude = new OneThirstyDude ();
     Soda bru = new Soda ();
     bru.Pop += new PopHandler (dude.HandlePopWithException);
     bru.OnPop ("Iron Brew", new EventRaiser ());
 }
Ejemplo n.º 2
0
 public void RaiseWithBadNumberOfArguments () 
 {
     OneThirstyDude dude = new OneThirstyDude ();
     Soda bru = new Soda ();
     bru.Pop += new PopHandler (dude.HandlePop);
     bru.OnPopWithBadNumberOfArguments ("Iron Brew", new EventRaiser ());
 }
Ejemplo n.º 3
0
 public void RaiseWithBadNumberOfArguments () 
 {
     OneThirstyDude dude = new OneThirstyDude ();
     Soda bru = new Soda ();
     bru.Pop += new PopHandler (dude.HandlePop);
     Assert.Throws<TargetParameterCountException>(() => bru.OnPopWithBadNumberOfArguments ("Iron Brew", new EventRaiser ()));
 }
 public void RaiseSwallowsExceptionRaisedByHandlers()
 {
     OneThirstyDude dude = new OneThirstyDude();
     Soda bru = new Soda();
     bru.Pop += new PopHandler(dude.HandlePopWithException);
     bru.OnPop("Iron Brew", new DefensiveEventRaiser());
     Assert.AreEqual("Iron Brew", dude.Soda); // should have got through before exception was thrown
 }
Ejemplo n.º 5
0
        public void RaiseWithAnEventHandlerThatThrowsAnException()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePopWithException);
            Assert.Throws <FormatException>(() => bru.OnPop("Iron Brew", new EventRaiser()), "Iron Brew");
        }
Ejemplo n.º 6
0
        public void RaiseWithBadNumberOfArguments()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePop);
            Assert.Throws <TargetParameterCountException>(() => bru.OnPopWithBadNumberOfArguments("Iron Brew", new EventRaiser()));
        }
Ejemplo n.º 7
0
 public void RaiseWithNullEvent () 
 {
     OneThirstyDude dude = new OneThirstyDude ();
     Soda bru = new Soda ();
     bru.Pop += new PopHandler (dude.HandlePop);
     bru.OnPopWithNullEvent ("Iron Brew", new EventRaiser ());
     Assert.AreEqual (string.Empty, dude.Soda);
 }
Ejemplo n.º 8
0
 public void Raise () 
 {
     OneThirstyDude dude = new OneThirstyDude ();
     Soda bru = new Soda ();
     bru.Pop += new PopHandler (dude.HandlePop);
     bru.OnPop ("Iron Brew", new EventRaiser ());
     Assert.AreEqual ("Iron Brew", dude.Soda);
 }
Ejemplo n.º 9
0
        public void RaiseWithBadNumberOfArguments()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePop);
            bru.OnPopWithBadNumberOfArguments("Iron Brew", new EventRaiser());
        }
Ejemplo n.º 10
0
        public void RaiseWithNullEvent()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePop);
            bru.OnPopWithNullEvent("Iron Brew", new EventRaiser());
            Assert.AreEqual(string.Empty, dude.Soda);
        }
Ejemplo n.º 11
0
        public void Raise()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePop);
            bru.OnPop("Iron Brew", new EventRaiser());
            Assert.AreEqual("Iron Brew", dude.Soda);
        }
Ejemplo n.º 12
0
        public void RaiseSwallowsExceptionRaisedByHandlers()
        {
            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += new PopHandler(dude.HandlePopWithException);
            bru.OnPop("Iron Brew", new DefensiveEventRaiser());
            Assert.AreEqual("Iron Brew", dude.Soda); // should have got through before exception was thrown
        }
		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 RaiseSwallowsExceptionRaisedByHandlerButCallsAllOtherHandlers()
        {
            bool firstCall = false;
            bool secondCall = false;
            bool thirdCall = false;

            OneThirstyDude dude = new OneThirstyDude();
            Soda bru = new Soda();
            bru.Pop += (sender, soda) => firstCall = true;
			bru.Pop += (sender, soda) => { secondCall = true; throw new Exception(); };
			bru.Pop += (sender, soda) => { thirdCall = true; };

            DefensiveEventRaiser eventRaiser = new DefensiveEventRaiser();

            IEventExceptionsCollector exceptions = bru.OnPop( "Iron Brew", eventRaiser );

            Assert.AreEqual(1, exceptions.Exceptions.Count);
            Assert.IsTrue(firstCall);
            Assert.IsTrue(secondCall);
            Assert.IsTrue(thirdCall);
        }
Ejemplo n.º 15
0
        public void RaiseSwallowsExceptionRaisedByHandlerButCallsAllOtherHandlers()
        {
            bool firstCall  = false;
            bool secondCall = false;
            bool thirdCall  = false;

            OneThirstyDude dude = new OneThirstyDude();
            Soda           bru  = new Soda();

            bru.Pop += (sender, soda) => firstCall = true;
            bru.Pop += (sender, soda) => { secondCall = true; throw new Exception(); };
            bru.Pop += (sender, soda) => { thirdCall = true; };

            DefensiveEventRaiser eventRaiser = new DefensiveEventRaiser();

            IEventExceptionsCollector exceptions = bru.OnPop("Iron Brew", eventRaiser);

            Assert.AreEqual(1, exceptions.Exceptions.Count);
            Assert.IsTrue(firstCall);
            Assert.IsTrue(secondCall);
            Assert.IsTrue(thirdCall);
        }
		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));
		}