2017-04-21 114 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通常产生的距离太远。我建议使用多个断言,而不是:) –