私はこれまで、yahoogroupについてこれまで尋ねましたが、残念なことに答えはありません。NServicebus Test.Handler ExpectSendが期待した結果を出さない
ExpectSendは、ユニットテストに追加されると、テストがこのメッセージに失敗:
Rhino.Mocks.Exceptions.ExpectationViolationException: IBus.Send(callback method:
<>c__DisplayClass2`1.<ExpectSend>b__1); Expected #1, Actual #0
。
これは、Bus.Sendメソッドが呼び出されないようです。しかし、それはです。 .ExpectSendの行が使用されていない場合、テストは成功しました。
[TestMethod()]
public void Should_Handle_Goedkeuring_Which_Results_In_VolledigGoedgekeurdeFactuur()
{
int inkoopFactuurId = 5;
Test.Initialize();
var mock = new Mock<IProcesGoedkeuringDataService>();
mock.Setup(x => x.IsFactuurVolledigGoedgekeurd(inkoopFactuurId)).Returns(true);
Test.Handler<GoedkeuringDoorGebruikerCommandHandler>()
.WithExternalDependencies(h => h.DataService = mock.Object)
.ExpectSend<FactuurVolledigGoedgekeurdCommand>(c =>
c.InkoopFactuurId == inkoopFactuurId)
.OnMessage<GoedkeuringDoorGebruikerCommand>(m =>
SetupMessage(m)); ;
}
ハンドラ:この場合、IsFactuurVolledigGoedgekeurdメソッドはtrueを返します。
public class GoedkeuringDoorGebruikerCommandHandler : IHandleMessages<GoedkeuringDoorGebruikerCommand>
{
public IBus Bus { get; set; }
public IProcesGoedkeuringDataService DataService { get; set; }
public void Handle(GoedkeuringDoorGebruikerCommand message)
{
RegistreerGoedkeuring(message.InkoopFactuurId, message.GebruikerId);
bool volledigGoedgekeurd = IsFactuurVolledigGoedgekeurd(message.InkoopFactuurId);
if (volledigGoedgekeurd)
{
Bus.Send(new FactuurVolledigGoedgekeurdCommand(message.InkoopFactuurId));
}
}
}