本文整理汇总了C#中Bus.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.Publish方法的具体用法?C# Bus.Publish怎么用?C# Bus.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bus
的用法示例。
在下文中一共展示了Bus.Publish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanPublish
public void CanPublish()
{
var mockRepository = new MockRepository();
var config = mockRepository.DynamicMock<IBrokerConfiguration>();
var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
var conn = mockRepository.DynamicMock<IBrokerConnection>();
var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
var message = new TestMessage();
using (mockRepository.Record())
{
SetupResult.For(consumer.MessageType).Return(typeof(TestMessage));
SetupResult.For(connFactory.CreateConnection()).Return(conn);
SetupResult.For(config.Exchange).Return("ex");
SetupResult.For(config.ConnectionFactory).Return(connFactory);
SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
SetupResult.For(conn.IsOpen).Return(true);
Expect.Call(() => conn.Publish<TestMessage>(null))
.IgnoreArguments()
.WhenCalled(mi =>
{
var envelope = mi.Arguments[0];
Assert.IsAssignableFrom(typeof(IMessageEnvelope<TestMessage>), envelope);
Assert.Same(message, ((IMessageEnvelope<TestMessage>)envelope).Message);
});
}
using (mockRepository.Playback())
{
var bus = new Bus(config);
bus.Publish(message);
}
}
示例2: EventTest
public void EventTest()
{
var bus = new Bus(null, new HandlerRegistry());
int called = 0;
bus.Subscribe<WidgetCreatedEvent>((x) => called++);
bus.Subscribe<WidgetCreatedEvent>((x) => called++);
bus.Publish(new WidgetCreatedEvent());
Assert.AreEqual(2, called);
}
示例3: When_testing_something
public void When_testing_something()
{
var bus1 = new Bus();
bus1.Subscribe("first", x => _output.WriteLine("Bus1 => ({0}) => {1}", "first", x.Json));
bus1.Subscribe("second", x => _output.WriteLine("Bus1 => ({0}) => {1}", "second", x.Json));
var bus2 = new Bus();
bus2.Subscribe("first", x => _output.WriteLine("Bus2 => ({0}) => {1}", "first", x.Json));
bus2.Subscribe("second", x => _output.WriteLine("Bus2 => ({0}) => {1}", "second", x.Json));
var exchange = new Exchange();
exchange.AddBus(bus1);
exchange.AddBus(bus2);
bus1.Publish("first", new Message { Json = "a message"});
}
示例4: PublishShouldGetProducerFromContainer
public void PublishShouldGetProducerFromContainer()
{
// Arrange
var mockConfiguration = new Mock<IConfiguration>();
var mockProducer = new Mock<IProducer>();
var mockContainer = new Mock<IBusContainer>();
var mockProessManagerFinder = new Mock<IProcessManagerFinder>();
mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings ());
// Act
var bus = new Bus(mockConfiguration.Object);
bus.Publish(new FakeMessage1(Guid.NewGuid()), null);
// Assert
mockConfiguration.Verify(x => x.GetProducer(), Times.Once());
}
示例5: CreatesNewConnectionIfConnectionClosedWhenPublishing
public void CreatesNewConnectionIfConnectionClosedWhenPublishing()
{
var mockRepository = new MockRepository();
var config = mockRepository.DynamicMock<IBrokerConfiguration>();
var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
var conn = mockRepository.DynamicMock<IBrokerConnection>();
var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
var message = new TestMessage();
using (mockRepository.Record())
{
SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
SetupResult.For(config.Exchange).Return("ex");
SetupResult.For(config.ConnectionFactory).Return(connFactory);
SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
SetupResult.For(conn.IsOpen).Return(false);
Expect.Call(connFactory.CreateConnection()).Repeat.Times(4).Return(conn);
}
using (mockRepository.Playback())
{
var bus = new Bus(config);
bus.Publish(message);
bus.Publish(message);
}
}