本文整理汇总了C#中Bus.PublishAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.PublishAsync方法的具体用法?C# Bus.PublishAsync怎么用?C# Bus.PublishAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bus
的用法示例。
在下文中一共展示了Bus.PublishAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_publishing_an_event_should_invoke_all_registered_event_handlers
public void When_publishing_an_event_should_invoke_all_registered_event_handlers()
{
var serviceContainer = new ServiceContainer();
serviceContainer.RegisterAssembly(typeof (BusTests).Assembly, (serviceType, implementingType) => serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof (IHandleMessages<>));
var bus = new Bus(serviceContainer.GetAllInstances);
var message = new Event();
bus.PublishAsync(message);
message.NumberOfTimesHandled.ShouldEqual(2);
}
示例2: PublishAsync_Null_Message_Results_In_An_Exception
public void PublishAsync_Null_Message_Results_In_An_Exception()
{
var _busConfigurationBuilder = new BusConfigurationBuilder();
_busConfigurationBuilder.ConnectionUris.Add(TestingConfiguration.LocalConnectionUri);
var _busConfirguration = _busConfigurationBuilder.Build();
var _SUT = new Bus(_busConfirguration);
_SUT.Connect();
_SUT.PublishAsync<MyEvent>(null);
}
示例3: When_publishing_an_event_should_polymorphic_dispatch_to_all_handlers
public void When_publishing_an_event_should_polymorphic_dispatch_to_all_handlers()
{
var serviceContainer = new ServiceContainer();
serviceContainer.Register<IHandleMessages<Event>, EventHandler>();
serviceContainer.Register<IHandleMessages<Event>, AnotherEventHandler>("Another");
var messageHandler = new MessageHandler();
serviceContainer.RegisterInstance<IHandleMessages<IMessage>>(messageHandler);
var bus = new Bus(serviceContainer.GetAllInstances);
var message = new Event();
bus.PublishAsync(message);
message.NumberOfTimesHandled.ShouldEqual(2);
messageHandler.IsHandled.ShouldBeTrue();
}
示例4: When_event_handler_throws_exception_should_propagate_exception
public void When_event_handler_throws_exception_should_propagate_exception()
{
var serviceContainer = new ServiceContainer();
serviceContainer.Register<IHandleMessages<EventWithException>, EventWithExceptionHandler>();
var bus = new Bus(serviceContainer.GetAllInstances);
Assert.Throws<InvalidOperationException>(() => bus.PublishAsync(new EventWithException()).Wait());
}
示例5: When_sending_the_same_event_multiple_times_should_get_handlers_from_cahce
public void When_sending_the_same_event_multiple_times_should_get_handlers_from_cahce()
{
var serviceContainer = new ServiceContainer();
serviceContainer.RegisterAssembly(typeof (BusTests).Assembly, (serviceType, implementingType) => serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof (IHandleMessages<>));
IBus bus = new Bus(serviceContainer.GetAllInstances);
var message = new Event();
Assert.DoesNotThrow(() =>
{
bus.PublishAsync(message);
bus.PublishAsync(message);
bus.PublishAsync(message);
});
}