本文整理汇总了C#中Bus.PublishRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.PublishRequest方法的具体用法?C# Bus.PublishRequest怎么用?C# Bus.PublishRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bus
的用法示例。
在下文中一共展示了Bus.PublishRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublishRequestShouldPublishMessagesAndReturnResponses
public void PublishRequestShouldPublishMessagesAndReturnResponses()
{
// Arrange
var mockConfiguration = new Mock<IConfiguration>();
var mockProducer = new Mock<IProducer>();
var mockContainer = new Mock<IBusContainer>();
var mockProessManagerFinder = new Mock<IProcessManagerFinder>();
var mockRequestConfiguration = new Mock<IRequestConfiguration>();
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());
mockConfiguration.Setup(x => x.GetRequestConfiguration(It.IsAny<Guid>())).Returns(mockRequestConfiguration.Object);
var task = new Task(() => { });
Action<FakeMessage2> action = null;
mockRequestConfiguration.Setup(x => x.SetHandler(It.IsAny<Action<object>>())).Returns(task).Callback<Action<FakeMessage2>>(r =>
{
action = r;
});
var message = new FakeMessage1(Guid.NewGuid())
{
Username = "Tim Watson"
};
var r1 = new FakeMessage2(Guid.NewGuid());
var r2 = new FakeMessage2(Guid.NewGuid());
mockProducer.Setup(x => x.Publish(It.IsAny<Type>(), It.IsAny<byte[]>(), It.IsAny<Dictionary<string, string>>())).Callback(() =>
{
action(r1);
action(r2);
task.Start();
});
// Act
var bus = new Bus(mockConfiguration.Object);
var responses = bus.PublishRequest<FakeMessage1, FakeMessage2>(message, 1, null, 1000);
// Assert
Assert.Equal(2, responses.Count);
Assert.True(responses.Contains(r1));
Assert.True(responses.Contains(r2));
}