Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #5
0
        public void EventSimple2()
        {
            TypeDefinition <ITestEvents> typeDefinition = new TypeDefinition <ITestEvents>();
            ITestEvents   test              = typeDefinition.Create();
            IEventTrigger trigger           = typeDefinition.CreateEventTrigger(test, nameof(ITestEvents.Simple));
            bool          simpleEventCalled = false;
            bool          otherEventCalled  = false;

            test.Simple          += delegate { simpleEventCalled = true; };
            test.WithParameters  += delegate { otherEventCalled = true; };
            test.WithReturnValue += delegate { return(otherEventCalled = true); };
            trigger.Notify();
            Assert.IsTrue(simpleEventCalled);
            Assert.IsFalse(otherEventCalled);
        }
Exemple #6
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);
        }
Exemple #7
0
        public IPersonCollection CreatePersonCollection()
        {
            List <IPerson> persons = new List <IPerson>();
            CollectionChangedImplementation <IPerson> collectionChanged =
                new CollectionChangedImplementation <IPerson>(person => persons.IndexOf(person));
            TypeDefinition <IPersonCollection> typeDefinition =
                new TypeDefinition <IPersonCollection>(
                    new LinkedObjects(
                        new MappedMethod("Remove", collectionChanged, nameof(collectionChanged.PreRemove)),
                        persons,
                        collectionChanged));
            IEventTrigger trigger = null;

            typeDefinition.RegisterEvent(
                nameof(IPersonCollection.CollectionChanged),
                eventTrigger => trigger = eventTrigger);
            IPersonCollection personCollection = typeDefinition.Create();

            collectionChanged.CollectionChanged += (sender, args) => trigger.Notify(sender, args);
            return(personCollection);
        }