Esempio n. 1
0
        public void Given_an_EventAggregator_with_a_Dispatcher_when_publishing_a_message_should_handle_it()
        {
            // pushes tasks in Dispatcher queue towards getting worked.
            DispatcherFrame frame = new DispatcherFrame();

            MessageOne      messageOne = null;
            Subject         subject    = new Subject();
            EventAggregator aggregator = new EventAggregator(Dispatcher.CurrentDispatcher);

            aggregator.Subscribe(subject);

            ManualResetEvent manualEvent = new ManualResetEvent(false);
            ThreadStart      threadStart = () =>
            {
                messageOne = aggregator.Publish(new MessageOne {
                    Content = "Some Content"
                });
                frame.Continue = false;
                manualEvent.Set();
            };
            Thread backgroundThread = new Thread(threadStart);

            backgroundThread.Start();
            Dispatcher.PushFrame(frame);

            manualEvent.WaitOne(1000, false);

            Assert.True(messageOne.Content.Equals("Received"));
        }
Esempio n. 2
0
        public void Given_a_subscriber_when_publishing_a_message_should_handle_it()
        {
            Subject subject    = new Subject();
            var     aggregator = new EventAggregator();

            aggregator.Subscribe(subject);
            MessageOne messageOne = aggregator.Publish(new MessageOne {
                Content = "content"
            });

            Assert.True(messageOne.Content.Equals("Received"));
        }