本文整理汇总了C#中EventAggregator.AttachTo方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.AttachTo方法的具体用法?C# EventAggregator.AttachTo怎么用?C# EventAggregator.AttachTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventAggregator
的用法示例。
在下文中一共展示了EventAggregator.AttachTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: a_published_message_is_received_by_multiple_subscribers
public void a_published_message_is_received_by_multiple_subscribers()
{
// When the bus publishes a message, it is sent through the socket
var consumer = new ZeroConsumer<Message>("tcp://localhost:5562");
var bus = new BusAdapter();
bus.AttachConsumer(consumer);
// Meanwhile, the aggregator waits for messages from the same socket
var producer = new ZeroProducer<Message>("tcp://*:5562");
var aggregator = new EventAggregator<Message>();
aggregator.AttachTo(producer);
// While two test consumers are subscribed to the aggregator
// (the syntax looks like it's the other way around)
var confirmById = new FakeEventConsumer();
var confirmAsReceived = new TestConsumer();
aggregator.SubscribeTo(confirmById);
aggregator.SubscribeTo(confirmAsReceived);
// When we drop a message on the bus, the test consumer should get it
var @event = new FakeEvent();
bus.Publish(@event);
// Pause the thread so the producer (via aggregator) can send to the test consumer
var timeout = TimeSpan.FromSeconds(1).TotalMilliseconds;
Thread.Sleep((int)timeout);
Assert.IsTrue(confirmAsReceived.Received);
Assert.AreEqual(@event.Id, confirmById.Id);
producer.Dispose();
consumer.Dispose();
}