예제 #1
0
        public void TestBinding()
        {
            Binder binder = new Binder();
            var equivalent = new EventEquivalent();

            binder.Bind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));

            var e1 = new SampleEvent1();
            var e2 = new SampleEvent1 { Foo = 1 };
            var e3 = new SampleEvent1 { Foo = 1, Bar = "bar" };

            List<Handler> handlerChain = new List<Handler>();

            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e1, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e2, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e3, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);

            binder.Unbind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(e1, equivalent, handlerChain));
            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(e2, equivalent, handlerChain));
            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(e3, equivalent, handlerChain));
        }
예제 #2
0
 public void OnSpecificSampleEvent1(SampleEvent1 e)
 {
 }
예제 #3
0
 void OnSampleEvent1(SampleEvent1 e)
 {
 }
예제 #4
0
 public void OnSampleEvent1(SampleEvent1 e)
 {
 }
예제 #5
0
        public void TestHandlerChainBuilding()
        {
            Binder binder = new Binder();
            var equivalent = new EventEquivalent();

            binder.Bind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));
            binder.Bind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1));
            binder.Bind(new Event(), new MethodHandler<Event>(OnEvent));

            var e1 = new SampleEvent1();
            var e2 = new SampleEvent1 { Foo = 1 };
            var e3 = new SampleEvent1 { Foo = 1, Bar = "bar" };
            var e4 = new SampleEvent1 { Foo = 2 };
            var e5 = new SampleEvent2 { Foo = 1, Bar = "bar" };
            var e6 = new SampleEvent2 { Foo = 2, Bar = "bar" };

            List<Handler> handlerChain = new List<Handler>();

            handlerChain.Clear();
            Assert.AreEqual(2, binder.BuildHandlerChain(e1, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[1]);

            handlerChain.Clear();
            Assert.AreEqual(3, binder.BuildHandlerChain(e2, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[1]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[2]);

            handlerChain.Clear();
            Assert.AreEqual(3, binder.BuildHandlerChain(e3, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[1]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[2]);

            handlerChain.Clear();
            Assert.AreEqual(2, binder.BuildHandlerChain(e4, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[1]);

            handlerChain.Clear();
            Assert.AreEqual(3, binder.BuildHandlerChain(e5, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[1]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[2]);

            handlerChain.Clear();
            Assert.AreEqual(2, binder.BuildHandlerChain(e6, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[1]);

            binder.Unbind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));

            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e1, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<Event>(OnEvent), handlerChain[0]);

            binder.Unbind(new Event(), new MethodHandler<Event>(OnEvent));

            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e2, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);

            handlerChain.Clear();
            Assert.AreEqual(1, binder.BuildHandlerChain(e3, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(e4, equivalent, handlerChain));
        }