我有这个代码来模拟Rebus MessageContext
IBus fakeBus;
IMessageContext messageContext;
[TestInitialize]
public void TestInitialize()
{
fakeBus = new FakeBus();
var mock = new Mock<IMessageContext>();
mock.Setup(m => m.ReturnAddress).Returns("queuename");
mock.Setup(h => h.Headers).Returns(new Dictionary<string, object>());
mock.Setup(m => m.Items).Returns(new Dictionary<string, object>());
mock.Setup(m => m.RebusTransportMessageId).Returns(Guid.NewGuid().ToString());
messageContext = mock.Object;
var fakeContext = FakeMessageContext.Establish(messageContext); // error here
}
但最后一行返回下面的堆栈跟踪。我在这里错过了什么?
旁注:我仍在使用Rebus 0.84。
结果StackTrace:
at Rebus.MessageContext.Establish(IMessageContext messageContext, Boolean overwrite)
at Rebus.Testing.FakeMessageContext.Establish(IMessageContext messageContext)
at MyApp.Messaging.Tests.Handlers.RegisterPaymentCallbackTests.TestInitialize() in C:\CUT.Tests\Handlers\RegisterPaymentCallbackTests.cs:line 57
Result Message: Initialization method MyApp.Tests.Handlers.RegisterPaymentCallbackTests.TestInitialize threw exception. System.InvalidOperationException: Could not find a transaction context. There should always be a transaction context - though it might be a NoTransaction transaction context..