public void WireWithInstanceHandler () 
 {
     StaticEventHandlerValue wirer = new StaticEventHandlerValue ();
     wirer.EventName = "Ping";
     wirer.MethodName = "OnPing";
     PingSource source = new PingSource ();
     wirer.Wire (source, new PingListener ());
 }
 public void BailsIfMethodDoesntExist () 
 {
     PingSource source = new PingSource ();
     InstanceEventHandlerValue wirer
         = new InstanceEventHandlerValue (source, "Roo");
     wirer.EventName = "Ping";
     Assert.Throws<FatalObjectException>(() => wirer.Wire (source, typeof (StaticPingListener)));
 }
 public void WireWithStaticHandler () 
 {
     PingSource source = new PingSource ();
     InstanceEventHandlerValue wirer
         = new InstanceEventHandlerValue (source, "OnPing");
     wirer.EventName = "Ping";
     wirer.Wire (source, typeof (StaticPingListener));
 }
 public void WireWithInstanceHandler () 
 {
     StaticEventHandlerValue wirer = new StaticEventHandlerValue ();
     wirer.EventName = "Ping";
     wirer.MethodName = "OnPing";
     PingSource source = new PingSource ();
     Assert.Throws<FatalObjectException>(() => wirer.Wire (source, new PingListener ()));
 }
 public void BailsIfMethodDoesntExist () 
 {
     PingSource source = new PingSource ();
     InstanceEventHandlerValue wirer
         = new InstanceEventHandlerValue (source, "Roo");
     wirer.EventName = "Ping";
     wirer.Wire (source, typeof (StaticPingListener));
 }
Example #6
0
        public void BailsIfMethodDoesntExist()
        {
            PingSource source = new PingSource();
            InstanceEventHandlerValue wirer
                = new InstanceEventHandlerValue(source, "Roo");

            wirer.EventName = "Ping";
            wirer.Wire(source, typeof(StaticPingListener));
        }
 public void Instantiation () 
 {
     PingSource source = new PingSource ();
     StaticEventHandlerValue wirer
         = new StaticEventHandlerValue (source, "OnPing");
     Assert.IsNotNull (wirer.Source);
     Assert.AreEqual ("OnPing", wirer.MethodName);
     Assert.IsTrue (wirer.ToString ().IndexOf (wirer.MethodName) > 0);
 }
Example #8
0
        public void BailsIfMethodDoesntExist()
        {
            PingSource source = new PingSource();
            InstanceEventHandlerValue wirer
                = new InstanceEventHandlerValue(source, "Roo");

            wirer.EventName = "Ping";
            Assert.Throws <FatalObjectException>(() => wirer.Wire(source, typeof(StaticPingListener)));
        }
Example #9
0
        public void WireWithStaticHandler()
        {
            PingSource source = new PingSource();
            InstanceEventHandlerValue wirer
                = new InstanceEventHandlerValue(source, "OnPing");

            wirer.EventName = "Ping";
            wirer.Wire(source, typeof(StaticPingListener));
        }
        public void Instantiation()
        {
            PingSource source = new PingSource();
            StaticEventHandlerValue wirer
                = new StaticEventHandlerValue(source, "OnPing");

            Assert.IsNotNull(wirer.Source);
            Assert.AreEqual("OnPing", wirer.MethodName);
            Assert.IsTrue(wirer.ToString().IndexOf(wirer.MethodName) > 0);
        }
        public void WireWithInstanceHandler()
        {
            StaticEventHandlerValue wirer = new StaticEventHandlerValue();

            wirer.EventName  = "Ping";
            wirer.MethodName = "OnPing";
            PingSource source = new PingSource();

            Assert.Throws <FatalObjectException>(() => wirer.Wire(source, new PingListener()));
        }
        public void WireWithInstanceHandler()
        {
            StaticEventHandlerValue wirer = new StaticEventHandlerValue();

            wirer.EventName  = "Ping";
            wirer.MethodName = "OnPing";
            PingSource source = new PingSource();

            wirer.Wire(source, new PingListener());
        }
 public void Wire () {
     InstanceEventHandlerValue wirer = new InstanceEventHandlerValue ();
     wirer.EventName = "Ping";
     wirer.MethodName = "OnPing";
     PingSource source = new PingSource ();
     PingListener sink = new PingListener ();
     wirer.Wire (source, sink);
     source.OnPing ();
     Assert.IsTrue (sink.GotPing, "The event handler did not get notified when the event was raised.");
     Assert.AreEqual (1, sink.PingCount, "The event handler was not get notified exactly once when the event was raised exactly once.");
 }
 public void Wire () 
 {
     PingSource source = new PingSource ();
     StaticEventHandlerValue wirer
         = new StaticEventHandlerValue (source, "OnPing");
     wirer.EventName = "Ping";
     Type sink = typeof (StaticPingListener);
     wirer.Wire (source, sink);
     source.OnPing ();
     Assert.IsTrue (StaticPingListener.GotPing, "The event handler did not get notified when the event was raised.");
     Assert.AreEqual (1, StaticPingListener.PingCount, "The event handler was not get notified exactly once when the event was raised exactly once.");
 }
        public void Wire()
        {
            PingSource source = new PingSource();
            StaticEventHandlerValue wirer
                = new StaticEventHandlerValue(source, "OnPing");

            wirer.EventName = "Ping";
            Type sink = typeof(StaticPingListener);

            wirer.Wire(source, sink);
            source.OnPing();
            Assert.IsTrue(StaticPingListener.GotPing, "The event handler did not get notified when the event was raised.");
            Assert.AreEqual(1, StaticPingListener.PingCount, "The event handler was not get notified exactly once when the event was raised exactly once.");
        }
Example #16
0
        public void Wire()
        {
            InstanceEventHandlerValue wirer = new InstanceEventHandlerValue();

            wirer.EventName  = "Ping";
            wirer.MethodName = "OnPing";
            PingSource   source = new PingSource();
            PingListener sink   = new PingListener();

            wirer.Wire(source, sink);
            source.OnPing();
            Assert.IsTrue(sink.GotPing, "The event handler did not get notified when the event was raised.");
            Assert.AreEqual(1, sink.PingCount, "The event handler was not get notified exactly once when the event was raised exactly once.");
        }
        public void AutowireExplicitlyWithBadSignatureMethod ()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "Ping";
            wirer.MethodName = "OnPinged"; // signature is incompatible
            wirer.Wire (source, listener);

            // raise the event on the source
            source.OnPing ();

            // ascertain that the event listener was not notified of the raised event
            Assert.IsFalse (listener.GotPing, "The listener was (incorrectly) notified of the raised event.");
            Assert.IsFalse (listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse (listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #18
0
        public void AutowireAllHandlersWithCompatibleSignatures()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up (any methods on the listener that have a compatible signature will be wired up)
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName = "^Ping$";
            wirer.Wire(source, listener);

            // raise the event on the source
            source.OnPing();

            // ascertain that the event handler was indeed notified of the raised event
            Assert.IsTrue(listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsFalse(listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse(listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #19
0
        public void AutowiringIsCaseInsensitive()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName  = "pInG";
            wirer.MethodName = "onpiNg";
            wirer.Wire(source, listener);

            // raise the event (s) on the source
            source.OnPing();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsFalse(listener.GotPinging, "The listener was (incorrectly) notified of the raised event.");
            Assert.IsTrue(listener.GotPing, "The listener was not  notified of the raised event.");
            Assert.IsFalse(listener.GotPinged, "The listener was (incorrectly) notified of the raised event.");
        }
        public void AutowireExplicitly ()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "Ping";
            wirer.MethodName = "OnPing";
            wirer.Wire (source, listener);

            // raise the event on the source
            source.OnPing ();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue (listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsTrue (listener.PingCount == 1, "The listener was notified more than once for a single raising of the source event (registered to listen more than once?)");
            Assert.IsFalse (listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse (listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #21
0
        public void AutowireExplicitlyWithBadSignatureMethod()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName  = "Ping";
            wirer.MethodName = "OnPinged"; // signature is incompatible
            wirer.Wire(source, listener);

            // raise the event on the source
            source.OnPing();

            // ascertain that the event listener was not notified of the raised event
            Assert.IsFalse(listener.GotPing, "The listener was (incorrectly) notified of the raised event.");
            Assert.IsFalse(listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse(listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #22
0
        public void TestDefaultMethodMatching()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PerversePingListener();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName  = "^Ping$";
            wirer.MethodName = ".+${event}.+"; // matches 'WhatClubDoYouUsePingAhGood'
            wirer.Wire(source, listener);

            // raise the event on the source
            source.OnPing();

            // ascertain that the event listener was not notified of the raised event
            Assert.IsTrue(listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsFalse(listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse(listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #23
0
        public void AutowireAllEventsOnSource()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up (any methods on the listener that have a signature compatible
            // with any event exposed on the source will be wired up)
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.Wire(source, listener);

            // raise the event (s) on the source
            source.OnPinging();
            source.OnPing();
            source.OnPinged();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue(listener.GotPinging, "The listener was not notified of the raised event.");
            Assert.IsTrue(listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsTrue(listener.GotPinged, "The listener was not notified of the raised event.");
        }
Example #24
0
        public void AutowireExplicitly()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName  = "Ping";
            wirer.MethodName = "OnPing";
            wirer.Wire(source, listener);

            // raise the event on the source
            source.OnPing();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue(listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsTrue(listener.PingCount == 1, "The listener was notified more than once for a single raising of the source event (registered to listen more than once?)");
            Assert.IsFalse(listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse(listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
Example #25
0
        public void AllCompatibleSignaturesAreWired()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource   source   = new PingSource();
            PingListener listener = new PingListener();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue();

            wirer.EventName  = "Pinging";
            wirer.MethodName = ".+"; // both OnPinging and OnPinged have compatible sigs :'(
            wirer.Wire(source, listener);

            // raise the event (s) on the source
            source.OnPinging();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue(listener.GotPinging, "The listener was not notified of the raised event.");
            Assert.IsFalse(listener.GotPing, "The listener was (incorrectly) notified of the raised event.");
            // the moral of the story is...
            //     don't use greedy method name regex's for autowiring, be explicit
            Assert.IsTrue(listener.GotPinged, "The listener was not notified of the raised event.");
        }
        public void AutowireAllEventsOnSource () 
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up (any methods on the listener that have a signature compatible
            // with any event exposed on the source will be wired up)
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.Wire (source, listener);

            // raise the event (s) on the source
            source.OnPinging ();
            source.OnPing ();
            source.OnPinged ();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue (listener.GotPinging, "The listener was not notified of the raised event.");
            Assert.IsTrue (listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsTrue (listener.GotPinged, "The listener was not notified of the raised event.");
        }
        public void AutowiringIsCaseInsensitive () 
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "pInG";
            wirer.MethodName = "onpiNg";
            wirer.Wire (source, listener);

            // raise the event (s) on the source
            source.OnPing ();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsFalse (listener.GotPinging, "The listener was (incorrectly) notified of the raised event.");
            Assert.IsTrue (listener.GotPing, "The listener was not  notified of the raised event.");
            Assert.IsFalse (listener.GotPinged, "The listener was (incorrectly) notified of the raised event.");
        }
        public void AutowireAllHandlersWithCompatibleSignatures () 
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up (any methods on the listener that have a compatible signature will be wired up)
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "^Ping$";
            wirer.Wire (source, listener);

            // raise the event on the source
            source.OnPing ();

            // ascertain that the event handler was indeed notified of the raised event
            Assert.IsTrue (listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsFalse (listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse (listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }
        public void AllCompatibleSignaturesAreWired () 
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PingListener ();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "Pinging";
            wirer.MethodName = ".+"; // both OnPinging and OnPinged have compatible sigs :'(
            wirer.Wire (source, listener);

            // raise the event (s) on the source
            source.OnPinging ();

            // ascertain that the event listener was indeed notified of the raised event
            Assert.IsTrue (listener.GotPinging, "The listener was not notified of the raised event.");
            Assert.IsFalse (listener.GotPing, "The listener was (incorrectly) notified of the raised event.");
            // the moral of the story is...
            //     don't use greedy method name regex's for autowiring, be explicit
            Assert.IsTrue (listener.GotPinged, "The listener was not notified of the raised event.");
        }
        public void TestDefaultMethodMatching ()
        {
            // create the event source, and a listener to wire to an event (s) on the source
            PingSource source = new PingSource ();
            PingListener listener = new PerversePingListener ();

            // wire them up
            IEventHandlerValue wirer = new AutoWiringEventHandlerValue ();
            wirer.EventName = "^Ping$";
            wirer.MethodName = ".+${event}.+"; // matches 'WhatClubDoYouUsePingAhGood'
            wirer.Wire (source, listener);

            // raise the event on the source
            source.OnPing ();

            // ascertain that the event listener was not notified of the raised event
            Assert.IsTrue (listener.GotPing, "The listener was not notified of the raised event.");
            Assert.IsFalse (listener.GotPinging, "The listener was (incorrectly) notified of an event that wasn't raised.");
            Assert.IsFalse (listener.GotPinged, "The listener was (incorrectly) notified of an event that wasn't raised.");
        }