Example #1
0
            public void NullEventID()
            {
                EventBrokerService service = new EventBrokerService();

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.UnregisterSink(new object(), null);
                });
            }
Example #2
0
            public void NullSource()
            {
                EventBrokerService service = new EventBrokerService();

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.UnregisterSource(null, "MyEvent");
                });
            }
Example #3
0
            public void NullMethod()
            {
                EventBrokerService service = new EventBrokerService();
                SpyEventSink       sink    = new SpyEventSink();

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.RegisterSink(sink, null, "MyEvent");
                });
            }
Example #4
0
            public void NullEvent()
            {
                EventBrokerService service = new EventBrokerService();
                SpyEventSource     source  = new SpyEventSource();

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.RegisterSource(source, null, "MyEvent");
                });
            }
Example #5
0
            public void NullEventID()
            {
                EventBrokerService service    = new EventBrokerService();
                SpyEventSink       sink       = new SpyEventSink();
                MethodInfo         sinkMethod = sink.GetType().GetMethod("MySink");

                Assert.Throws <ArgumentNullException>(delegate
                {
                    service.RegisterSink(sink, sinkMethod, null);
                });
            }
Example #6
0
            public void InvalidMethodSignature()
            {
                EventBrokerService service    = new EventBrokerService();
                SpyEventSink       sink       = new SpyEventSink();
                MethodInfo         sinkMethod = sink.GetType().GetMethod("NonSinkMethod");

                Assert.Throws <ArgumentException>(delegate
                {
                    service.RegisterSink(sink, sinkMethod, "MyEvent");
                });
            }
Example #7
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");
                });
            }
Example #8
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);
            }
Example #9
0
            public void SourcesAreStoredWithWeakReferences()
            {
                SpyEventSource.FinalizerCalled = false;
                EventBrokerService service     = new EventBrokerService();
                EventInfo          sourceEvent = typeof(SpyEventSource).GetEvent("MySource");

                service.RegisterSource(new SpyEventSource(), sourceEvent, "MyEvent");

                GC.Collect();
                GC.WaitForPendingFinalizers();

                Assert.True(SpyEventSource.FinalizerCalled);
            }
Example #10
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);
            }
Example #11
0
            public void SinksAreStoredWithWeakReferences()
            {
                EventBrokerService service    = new EventBrokerService();
                MethodInfo         sinkMethod = typeof(ExceptionThrowingSink).GetMethod("MySink");

                service.RegisterSink(new ExceptionThrowingSink(), sinkMethod, "MyEvent");

                GC.Collect();
                GC.WaitForPendingFinalizers();

                Assert.DoesNotThrow(delegate
                {
                    service.Fire("MyEvent", this, new EventArgs <string>("Hello world"));
                });
            }
            public EventSource(EventBrokerService service,
                               object source,
                               EventInfo eventInfo,
                               string eventID)
            {
                this.service   = service;
                this.source    = new WeakReference(source);
                this.eventInfo = eventInfo;
                this.eventID   = eventID;

                handlerMethod = GetType().GetMethod("SourceHandler");
                Delegate @delegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, handlerMethod);

                eventInfo.AddEventHandler(source, @delegate);
            }
Example #13
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);
            }
Example #14
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);
            }
        public override object BuildUp(IBuilderContext context,
                                       object buildKey,
                                       object existing)
        {
            IEventBrokerPolicy policy  = context.Policies.Get <IEventBrokerPolicy>(buildKey);
            EventBrokerService service = context.Locator.Get <EventBrokerService>();

            if (policy != null && service != null)
            {
                foreach (KeyValuePair <string, MethodInfo> kvp in policy.Sinks)
                {
                    service.RegisterSink(existing, kvp.Value, kvp.Key);
                }

                foreach (KeyValuePair <string, EventInfo> kvp in policy.Sources)
                {
                    service.RegisterSource(existing, kvp.Value, kvp.Key);
                }
            }

            return(base.BuildUp(context, buildKey, existing));
        }