2013-06-04 41 views
2

我有一個處理程序,需要發送本地消息從存儲庫中檢索的實體的每個實例。傳遞給NServiceBus.Testing.Handler<>::ExpectSendLocal()的回調僅在我的處理函數中第一次調用IBus::SendLocal()時被調用。我已經嘗試鏈接第二個Handler<>::ExpectSendLocal(),但它的回調只在第一個上調用。下面是一個例子的處理程序:如何驗證在NServiceBus處理程序中的多個操作

public FooHandler : IHandleMessages<IFoo> 
{ 
    public void Handle(IFoo message) 
    { 
     var bars = new [] {new Bar {Zap = "Zap1"}, new Bar {Zap = "Zap2"}}; 
     foreach (var bar in bars) 
     { 
      this.Bus().SendLocal<IBarProcessed>(barMsg => { 
      barMsg.Zap = bar.Zap; 
      }); 
      bar.IsProcessed = true; 
     } 
    } 
} 

下面是遞增計數IBus::SendLocal()期望一個例子的單元測試:

public void When_IFoo_message_received() 
{ 
    int actualCount = 0; 
    new NServiceBus.Testing.Handler<FooHandler>() 
      .ExpectSendLocal<IBarProcessed>(completed => actualCount++) 
      .OnMessage<IFoo>(); 
    Assert.AreEqual(2, actualCount); // fails because actualCount is one 
} 

這裏是一個例子的單元測試該鏈NServiceBus.Testing.Handler<FooHandler>.ExpectSendLocal()和檢查來自2個消息2個不同的值:

public void When_IFoo_message_received() 
{ 
    new NServiceBus.Testing.Handler<FooHandler>() 
      .ExpectSendLocal<IBarProcessed>(completed => { 
       Assert.AreEqual("Zap1", completed.Zap); 
      }) 
      .ExpectSendLocal<IBarProcessed>(completed => { 
       Assert.AreEqual("Zap2", completed.Zap); // fails because it's the value from the first one e.g. "Zap1" 
      }) 
      .OnMessage<IFoo>(); 
} 

回答

1

這看起來像一個bug,你會介意提出一個github問題嗎?

+0

當然可以。謝謝。 – gabe

相關問題