public void SubscribeEventWithTargetThatDoesntUseMainThreadContextWorks(ThreadTarget threadTarget) { var subscription = new EventAggregatorService(this.subscriptionLogger) .Subscribe <TestEvent>(e => {}, false, EventPriority.Normal, threadTarget); subscription.Should().NotBeNull(); }
public void Teardown() { this.subscriptionLogger = null; this.synchronizationContext = null; this.eventAggregator = null; }
public void Setup() { this.subscriptionLogger = new NullLogger <ISubscription>(); this.synchronizationContext = new TestSynchronizationContext(); this.eventAggregator = new EventAggregatorService(this.subscriptionLogger); this.eventAggregator.SetMainThreadSynchronizationContext(this.synchronizationContext); }
public void Failed_Subscribe_Plugin_Test() { // 1) arrange var ex = new Exception(); IPublisherCreator pulisherCreator = new FailedPublisherCreator_Mock(ex); IEventAggregatorService eventAggregator = new EventAggregatorService(errorHandler, pulisherCreator, eventConteiner); // 2) act eventAggregator.SubscribePlugin(plugin); // 3) assert errorHandler.AssertWasCalled(x => x.OnSubscriptionFailed(plugin, ex)); }
public void SubscribeEventAggregatorWithoutSynchronizationContextThrowsException() { var aggregator = new EventAggregatorService(this.subscriptionLogger); Action act = () => aggregator.Subscribe <TestEvent>( x => {}, false, EventPriority.Normal, ThreadTarget.MainThread); act.Should() .Throw <InvalidOperationException>().WithMessage($"*{nameof(SynchronizationContext)}*"); }
public void Unsubscribe_Not_Contains_Plugin_Test() { // 1) arrange var eventConteiner = MockRepository.GenerateMock <IEventContainer>(); IEventAggregatorService eventAggregator = new EventAggregatorService(errorHandler, publisherCreator, eventConteiner); // 2) act eventAggregator.UnsubscribePlugin(plugin); // 3) assert errorHandler.AssertWasNotCalled( x => x.OnUnsubscriptionFailed(plugin, new ExternalException()), option => option.IgnoreArguments()); }
public void Publish_Using_Filed_Publisher_Test() { // 1) arrange var eventConteiner = MockRepository.GenerateMock <IEventContainer>(); var eventAggregator = new EventAggregatorService(errorHandler, publisherCreator, eventConteiner); // 2) act eventAggregator.SubscribePlugin(plugin); eventAggregator.GlobalPublish(e); // 3) assert errorHandler.AssertWasCalled(x => x.OnPublishFailed(plugin, e, ex)); eventConteiner.AssertWasCalled(x => x.Store(plugin, e)); }
public void Subscribe_Plugin_Test() { // 1) arrange var eventPublisher = new EventPublisher_Mock(); var publisherCreator = new PublisherCreator_Mock(eventPublisher); IEventAggregatorService eventAggregator = new EventAggregatorService(errorHandler, publisherCreator, eventConteiner); // 2) act eventAggregator.SubscribePlugin(plugin); // 3) assert errorHandler.AssertWasNotCalled( x => x.OnSubscriptionFailed(plugin, new ExternalException()), option => option.IgnoreArguments()); }
public void Publish_Using_Filed_Publisher_Assert_Count_Queued_Events_Test() { // 1) arrange var eventQueue = new EventQueue(); var eventConteiner = new UnpublishedEventsContainer(eventQueue); var eventAggregator = new EventAggregatorService(errorHandler, publisherCreator, eventConteiner); // 2) act eventAggregator.SubscribePlugin(plugin); eventAggregator.GlobalPublish(e); int actual = eventQueue.GetCount(plugin); int expected = 1; // 3) assert Assert.Equal(expected, actual); }
public void BuildEventAggregatorWorks() { var aggregator = new EventAggregatorService(this.subscriptionLogger); }