Exemplo n.º 1
0
        public void EventWithReturnValue3()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestEvents      test    = factory.Generate <ITestEvents>();
            IEventTrigger    trigger = factory.CreateEventTrigger(test, nameof(ITestEvents.WithReturnValue));

            test.WithReturnValue += value => false;
            test.WithReturnValue += value => true;
            bool returnValue = (bool)trigger.Notify("123");

            Assert.AreEqual(true, returnValue);
        }
Exemplo n.º 2
0
        public void EventSimpleRemoved1()
        {
            BeethovenFactory factory           = new BeethovenFactory();
            ITestEvents      test              = factory.Generate <ITestEvents>();
            IEventTrigger    trigger           = factory.CreateEventTrigger(test, nameof(ITestEvents.Simple));
            bool             simpleEventCalled = false;
            Action           delegate1         = delegate { simpleEventCalled = true; };

            test.Simple += delegate1;
            test.Simple -= delegate1;
            trigger.Notify();
            Assert.IsFalse(simpleEventCalled);
        }
Exemplo n.º 3
0
        public void EventWithParameters2()
        {
            BeethovenFactory factory   = new BeethovenFactory();
            ITestEvents      test      = factory.Generate <ITestEvents>();
            IEventTrigger    trigger   = factory.CreateEventTrigger(test, nameof(ITestEvents.WithParameters));
            double           gotValue1 = 0;
            string           gotValue2 = null;

            test.WithParameters += (value1, value2) => gotValue1 = value1;
            test.WithParameters += (value1, value2) => gotValue2 = value2;
            trigger.Notify(54.0, "abe");
            Assert.AreEqual(54.0, gotValue1);
            Assert.AreEqual("abe", gotValue2);
        }
Exemplo n.º 4
0
        public void EventWithReturnValue1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestEvents      test    = factory.Generate <ITestEvents>();
            IEventTrigger    trigger = factory.CreateEventTrigger(test, nameof(ITestEvents.WithReturnValue));
            bool             withReturnValueEventCalled = false;
            bool             otherEventCalled           = false;

            test.Simple          += delegate { otherEventCalled = true; };
            test.WithParameters  += delegate { otherEventCalled = true; };
            test.WithReturnValue += delegate { return(withReturnValueEventCalled = true); };
            trigger.Notify("");
            Assert.IsTrue(withReturnValueEventCalled);
            Assert.IsFalse(otherEventCalled);
        }
Exemplo n.º 5
0
        public void EventWithReturnValue2()
        {
            BeethovenFactory factory  = new BeethovenFactory();
            ITestEvents      test     = factory.Generate <ITestEvents>();
            IEventTrigger    trigger  = factory.CreateEventTrigger(test, nameof(ITestEvents.WithReturnValue));
            string           gotValue = null;

            test.WithReturnValue += value =>
            {
                gotValue = value;
                return(true);
            };
            bool returnValue = (bool)trigger.Notify("123");

            Assert.AreEqual(true, returnValue);
            Assert.AreEqual("123", gotValue);
        }