コード例 #1
0
            public void NullSource()
            {
                EventBrokerService service     = new EventBrokerService();
                SpyEventSource     source      = new SpyEventSource();
                EventInfo          sourceEvent = source.GetType().GetEvent("MySource");

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.RegisterSource(null, sourceEvent, "MyEvent");
                });
            }
コード例 #2
0
            public void UnregisterSourceUnwiresHandler()
            {
                EventBrokerService service     = new EventBrokerService();
                SpyEventSource     source      = new SpyEventSource();
                EventInfo          sourceEvent = source.GetType().GetEvent("MySource");

                service.RegisterSource(source, sourceEvent, "MyEvent");

                service.UnregisterSource(source, "MyEvent");

                Assert.False(source.HasHandlers);
            }
コード例 #3
0
            public void RegistrationSourceFirst()
            {
                EventBrokerService service     = new EventBrokerService();
                SpyEventSource     source      = new SpyEventSource();
                SpyEventSink       sink        = new SpyEventSink();
                EventInfo          sourceEvent = source.GetType().GetEvent("MySource");
                MethodInfo         sinkMethod  = sink.GetType().GetMethod("MySink");

                service.RegisterSource(source, sourceEvent, "MyEvent");
                service.RegisterSink(sink, sinkMethod, "MyEvent");

                source.InvokeMySource();

                Assert.Equal(source.SourceText, sink.EventValue);
            }
コード例 #4
0
            public void UnregisterSinkUnwiresHandler()
            {
                EventBrokerService service     = new EventBrokerService();
                SpyEventSource     source      = new SpyEventSource();
                SpyEventSink       sink        = new SpyEventSink();
                EventInfo          sourceEvent = source.GetType().GetEvent("MySource");
                MethodInfo         sinkMethod  = sink.GetType().GetMethod("MySink");

                service.RegisterSource(source, sourceEvent, "MyEvent");
                service.RegisterSink(sink, sinkMethod, "MyEvent");
                service.UnregisterSink(sink, "MyEvent");

                source.InvokeMySource();

                Assert.False(sink.WasCalled);
            }
コード例 #5
0
            public void ExceptionsAreCollectedAndRethrown()
            {
                EventBrokerService    service     = new EventBrokerService();
                SpyEventSource        source      = new SpyEventSource();
                ExceptionThrowingSink sink1       = new ExceptionThrowingSink();
                ExceptionThrowingSink sink2       = new ExceptionThrowingSink();
                EventInfo             sourceEvent = source.GetType().GetEvent("MySource");
                MethodInfo            sinkMethod  = sink1.GetType().GetMethod("MySink");

                service.RegisterSink(sink1, sinkMethod, "MyEvent");
                service.RegisterSink(sink2, sinkMethod, "MyEvent");
                service.RegisterSource(source, sourceEvent, "MyEvent");

                EventBrokerException ex =
                    Assert.Throws <EventBrokerException>(delegate
                {
                    source.InvokeMySource();
                });

                Assert.Equal(2, ex.Exceptions.Count);
            }