0
我試圖使用ValueSourceAttribute
進行測試。在ValueSourceAttribute上指定的sourceName必須引用非空靜態字段,屬性或方法
下面是一個例子
[Test]
public async Task TestDocumentsDifferentFormats(
[ValueSource(nameof(Formats))] string format,
[ValueSource(nameof(Documents))] IDocument document)
{
有趣的是,Formats
名單(第一個參數)的作品完美,但它解決不了第二個參數,即使以同樣的方式定義。
這是我如何定義文檔靜態列表
public class DocumentFactory
{
public static readonly List<IDocument> Documents=
new List<IDocument>
{
// Init documents
};
}
但是當我嘗試運行我的測試中,它拋出一個錯誤。
The sourceName specified on a ValueSourceAttribute must refer to a non null static field, property or method.
什麼會導致此問題?我會很感激任何幫助。
您應該提到只有在另一個類中聲明'Documents'屬性時纔會出現此問題。 – Fabio
@Fabio是的,它是在另一個類中聲明的,是否有可能解決這個問題? – bxfvgekd