2017-04-21 113 views
3

的多個屬性有沒有辦法做這樣的事情使用FluentAssertionsFluentAssertions斷言一個對象

response.Satisfy(r => 
    r.Property1== "something" && 
    r.Property2== "anotherthing")); 

我試圖避免編寫多個斷言語句。這是我用了最長時間的https://sharptestex.codeplex.com/。但是SharpTestEx不支持.Net Core。

+1

我應該做這驗證主題的多個屬性? –

回答

5

您應該能夠使用通用Match斷言通過斷言

response.Should() 
     .Match<MyResponseObject>((x) => 
      x.Property1 == "something" && 
      x.Property2 == "anotherthing" 
     ); 
+0

雖然此代碼有效,但斷言失敗時的錯誤消息非常尷尬。與FluentAssertions通常產生的距離太遠。我建議使用多個斷言,而不是:) –