正如约翰所提到的,这是固定在
此外,请确保您使用的是此处记录的 NServiceBus.Testing 框架:
例子:
[TestFixture]
public class Tests
{
[Test]
public void Run()
{
Test.Initialize();
Test.Handler<MyMessageHandler>()
.SetIncomingHeader("Test", "abc")
.ExpectReply<ResponseMessage>(m => Test.Bus.GetMessageHeader(m, "MyHeaderKey") == "myHeaderValue")
.OnMessage<RequestMessage>(m => m.String = "hello");
}
}
class MyMessageHandler : IHandleMessages<RequestMessage>
{
public IBus Bus { get; set; }
public void Handle(RequestMessage message)
{
ResponseMessage responseMessage = new ResponseMessage();
Bus.SetMessageHeader(responseMessage, "MyHeaderKey", "myHeaderValue");
Bus.Reply(responseMessage);
}
}
请注意,这是针对 NServiceBus v4/v5 的。对于其他版本,请访问文档。