Beispiel #1
0
        public void TestDuplicateBinding()
        {
            Binding        binding      = new Binding();
            var            equivalent   = new EventEquivalent();
            List <Handler> handlerChain = new List <Handler>();

            // Method handler

            binding.Bind(new SampleEvent1 {
                Foo = 1
            }, new MethodHandler <SampleEvent1>(OnSampleEvent1));
            binding.Bind(new SampleEvent1 {
                Foo = 1
            }, new MethodHandler <SampleEvent1>(OnSampleEvent1));

            binding.Unbind(new SampleEvent1 {
                Foo = 1
            }, new MethodHandler <SampleEvent1>(OnSampleEvent1));

            Assert.Equal(0, binding.BuildHandlerChain(new SampleEvent1 {
                Foo = 1
            }, equivalent, handlerChain));

            // Coroutine method handler

            binding.Bind(new SampleEvent1 {
                Foo = 1
            }, new CoroutineHandler <SampleEvent1>(OnSampleEvent1Coroutine));
            binding.Bind(new SampleEvent1 {
                Foo = 1
            }, new CoroutineHandler <SampleEvent1>(OnSampleEvent1Coroutine));

            binding.Unbind(new SampleEvent1 {
                Foo = 1
            }, new CoroutineHandler <SampleEvent1>(OnSampleEvent1Coroutine));

            Assert.Equal(0, binding.BuildHandlerChain(new SampleEvent1 {
                Foo = 1
            }, equivalent, handlerChain));

            // with EventSink

            var sink = new SampleEventSink();

            sink.Bind(new SampleEvent1 {
                Foo = 1
            }, sink.OnSampleEvent1);
            sink.Bind(new SampleEvent1 {
                Foo = 1
            }, sink.OnSampleEvent1);

            sink.Unbind(new SampleEvent1 {
                Foo = 1
            }, sink.OnSampleEvent1);

            handlerChain.Clear();
            Assert.Equal(0, binding.BuildHandlerChain(new SampleEvent1 {
                Foo = 1
            }, equivalent, handlerChain));
        }
Beispiel #2
0
        public void TestDuplicateBinding()
        {
            Binder binder = new Binder();
            List<Handler> handlerChain = new List<Handler>();

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

            binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));

            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, handlerChain));

            // with EventSink

            var sink = new SampleEventSink();
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            sink.Unbind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, handlerChain));
        }
Beispiel #3
0
        public void TestDuplicateUnbinding()
        {
            Binder binder = new Binder();
            var equivalent = new EventEquivalent();
            List<Handler> handlerChain = new List<Handler>();

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

            binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
            binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, equivalent, handlerChain));
            Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);

            // with EventSink

            var sink = new SampleEventSink();
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            sink.Unbind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, equivalent, handlerChain));
            Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, equivalent, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);
        }