2011-06-01 43 views
2

我曾經有過這樣的測試,它通過就好了(佐賀是完整的,一旦所有三個消息已經被處理。如何創建單元測試NServiceBus佐賀當佐賀有一個以上的處理器

 Test.Saga<TestSagaHandler>(sagaId) 
      .When(x => 
      { 
       x.Handle(new TestSagaStartMessageOne 
       { 
        Id = sagaId 
       }); 
       x.Handle(new TestSagaStartMessageTwo 
       { 
        Id = sagaId 
       }); 
       x.Handle(new TestSagaNonStartingMessage 
       { 
        Id = sagaId 
       }); 
      }); 
      .AssertSagaCompletionIs(true); 

我現在想打出來的TestSagaNonStartingMessage到自己的處理程序,並做了以下內容:

 Test.Saga<TestSagaHandler>(sagaId) 
      .When(x => 
      { 
       x.Handle(new TestSagaStartMessageOne 
       { 
        Id = sagaId 
       }); 
       x.Handle(new TestSagaStartMessageTwo 
       { 
        Id = sagaId 
       }); 
      }); 

     Test.Saga<TestSagaHandlerSingleMessage>(sagaId) 
      .When(x => 
       x.Handle(new TestSagaNonStartingMessage 
       { 
        Id = sagaId 
       }) 
      ) 
     .AssertSagaCompletionIs(true); 

然而,處理TestSagaNonStartingMessage時 - 佐賀數據沒有從以前的處理程序持久化了

我是否存在持續性問題,還是測試構建得不好?

回答

1

其他讀者參考,合適的測試結構應該類似於:

Test.Saga<TestSagaHandler>(sagaId) 
     .When(x => 
     { 
      x.Handle(new TestSagaStartMessageOne { Id = sagaId }); 
      x.Handle(new TestSagaStartMessageTwo { Id = sagaId }); 
     }) 
     .When(x => 
      x.Handle(new TestSagaNonStartingMessage { Id = sagaId }) 
     ) 
     .AssertSagaCompletionIs(true); 

作爲烏迪指示的,鏈中的「當」條款在一起。

此外,爲了從試驗導出進一步值,考慮引入例外,如ExpectSend<>ExpectPublish

參考:http://docs.particular.net/nservicebus/testing/

+1

哦,我現在看來是多麼明顯,現在4年後=)謝謝澄清=) – 2015-11-13 14:37:30

3

該測試的構造不正確 - 請查看製造樣品中的測試項目以瞭解其結構。簡短的答案是連鎖第二。當(...)在第一個之後。

+0

由於烏迪,感謝! – 2011-06-03 04:27:33

相關問題