我正在使用 NServiceBus5.2.21、NServiceBus.Testing5.2.1、Moq4.0.1、NUnit3.2.0
问题:ExpectSend<>
一直失败
“ExpectedSendInvocation 未完成”
何时_bus.Send()
正确调用。不知道我在这里缺少什么。
测试:
[TestFixture]
public class GeneralLedgerHanlderTest
{
private Mock<ISendGeneralLedgerToSap> _toSapMock;
[SetUp]
public void Setup()
{
_toSapMock = new Mock<ISendGeneralLedgerToSap>();
_toSapMock.Setup(x => x.SendSoapMessageToSap(It.IsAny<GeneralLedgerSapCommand>()));
}
[Test]
public void HandlerMustSendAuditLog()
{
NServiceBus.Testing.Test.Handler(bus => new GeneralLedgerToSapHandler(bus, _toSapMock.Object))
.ExpectSend<GeneralLedgerAuditCommand>(command => command.SagaReferenceId == "ab")
.OnMessage(new GeneralLedgerSapCommand { SagaReferenceId = "ab" });
}
}
处理程序:
public class GeneralLedgerToSapHandler : IHandleMessages<GeneralLedgerSapCommand>
{
private readonly IBus _bus;
private readonly ISendGeneralLedgerToSap _sendSoapToSap;
public GeneralLedgerToSapHandler(IBus bus, ISendGeneralLedgerToSap sendSoapToSap)
{
_bus = bus;
_sendSoapToSap = sendSoapToSap;
}
public void Handle(GeneralLedgerSapCommand message)
{
_sendSoapToSap.SendSoapMessageToSap(message);
var goodsReceiptAuditCommand = new GeneralLedgerAuditCommand
{
SagaReferenceId = message.SagaReferenceId,
};
_bus.Send(EndPointName.SpmAuditLogService, goodsReceiptAuditCommand);
}
}