1 回答

TA貢獻1936條經驗 獲得超7個贊
為什么會出現這個異常
發生異常是因為您正在調用函數
.Including(o => o.Property1.StartsWith("something")) //<-- expects property only
在僅期望獲得屬性表達式的表達式中。
.Including(o => o.Property1) //<-- expects property only
引用原始問題中鏈接的相同文檔,您的示例在進行比較時將僅包含指定的成員。
對于您想要做的事情,您應該查看該Equivalency Comparison Behavior部分,根據您的評論,該部分可能類似于以下示例
[TestClass]
public class ObjectEquivalencyTests {
[TestMethod]
public void ShouldBeEquivalent() {
var expected = new MyObject {
Property1 = "https://www.google.com",
Property2 = "something else"
};
var actual = new MyObject {
Property1 = "https://www.google.com/search?q=test",
Property2 = "something else"
};
actual.Should().BeEquivalentTo(expected, options => options
.Using<string>(ctx => ctx.Subject.Should().StartWith(ctx.Expectation))
.When(info => info.SelectedMemberPath == "Property1")
);
}
}
public class MyObject {
public string Property1 { get; set; }
public string Property2 { get; set; }
}
- 1 回答
- 0 關注
- 114 瀏覽
添加回答
舉報