public void RegisterHandlerMethod() { Publisher p = new Publisher(); Subscriber s = new Subscriber(); this.testee.RegisterHandlerMethod(EventTopics.SimpleEvent, s, s.Handle, new Handlers.Publisher()); this.testee.Register(p); p.CallSimpleEvent(); Assert.IsTrue(s.Called, "event was not handled."); s.Reset(); this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.Handle); p.CallSimpleEvent(); Assert.IsFalse(s.Called, "event should not have been handled."); }
public void ExceptionHandlingMultipleException() { Publisher p = new Publisher(); SubscriberThrowingException s1 = new SubscriberThrowingException(); SubscriberThrowingException s2 = new SubscriberThrowingException(); this.testee.Register(p); this.testee.Register(s1); this.testee.Register(s2); Assert.Throws <SubscriberThrowingException.TestException>( () => p.CallSimpleEvent()); }
public void DisposeUnregistersPublicationByProperty() { Publisher p = new Publisher(); Subscriber s = new Subscriber(); this.testee.Register(p); this.testee.Register(s); this.testee.Dispose(); Assert.Throws <NullReferenceException>( () => p.CallSimpleEvent(), "Should result in a null reference exception because the event should not be registered by the event topic anymore."); }
public void SubscriptionsInCodeCanBeRemoved() { Publisher p = new Publisher(); Subscriber s = new Subscriber(); this.testee.Register(p); this.testee.AddSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent, new Handlers.Publisher()); this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent); p.CallSimpleEvent(); Assert.IsFalse(s.SimpleEventCalled); }
public void GlobalPublicationMatcher() { var publicationMatcher = new TestPublicationMatcher(); var publisher = new Publisher(); var subscriber = new Subscriber(); this.testee.Register(publisher); this.testee.Register(subscriber); this.testee.AddGlobalMatcher(publicationMatcher); publisher.CallSimpleEvent(); subscriber.SimpleEventCalled.Should().BeFalse(); }
public void ExceptionHandlingWithExtensionHandlingException() { Publisher p = new Publisher(); SubscriberThrowingException s = new SubscriberThrowingException(); var exceptionHandlingExtension = new ExceptionHandlingExtension(); this.testee.AddExtension(exceptionHandlingExtension); this.testee.Register(p); this.testee.Register(s); p.CallSimpleEvent(); exceptionHandlingExtension.HandledException .Should().BeOfType <SubscriberThrowingException.TestException>(); }
public void ExceptionHandlingMultipleException() { Publisher p = new Publisher(); SubscriberThrowingException s1 = new SubscriberThrowingException(); SubscriberThrowingException s2 = new SubscriberThrowingException(); this.testee.Register(p); this.testee.Register(s1); this.testee.Register(s2); Assert.Throws<SubscriberThrowingException.TestException>( () => p.CallSimpleEvent()); }
public void ExceptionHandlingWithExtensionHandlingException() { Publisher p = new Publisher(); SubscriberThrowingException s = new SubscriberThrowingException(); var exceptionHandlingExtension = new ExceptionHandlingExtension(); this.testee.AddExtension(exceptionHandlingExtension); this.testee.Register(p); this.testee.Register(s); p.CallSimpleEvent(); exceptionHandlingExtension.HandledException .Should().BeOfType<SubscriberThrowingException.TestException>(); }
public void DisposeUnregistersPublicationByProperty() { Publisher p = new Publisher(); Subscriber s = new Subscriber(); this.testee.Register(p); this.testee.Register(s); this.testee.Dispose(); Assert.Throws<NullReferenceException>( () => p.CallSimpleEvent(), "Should result in a null reference exception because the event should not be registered by the event topic anymore."); }
public void ExceptionHandling() { try { Publisher p = new Publisher(); SubscriberThrowingException s = new SubscriberThrowingException(); this.testee.Register(p); this.testee.Register(s); p.CallSimpleEvent(); Assert.Fail("must not be reached."); } catch (EventTopicException e) { Assert.IsTrue(e.InnerException is SubscriberThrowingException.TestException); } }