我的測試代碼片段:
使用(ShimsContext.Create()){
taskService =新ShimTaskService { TargetServerGet =()=> 「192.168.100.1」, UserNameGet =( )=> 「用戶」, UserAccountDomainGet =()=> 「TESTDOMAIN」, UserPasswordGet =()=> 「p/W」, RootFolderGet =()=>新ShimTaskFolder { TasksGet =()=>新List {new ShimTask {NameGet =()=> taskName}}; }} 我 有錯誤:不能轉換任務以TaskCollection
> Cannot convert lambda expression to type system.collections.generic.List< Microsoft.Win32.TaskScheduler.Task>
> to return type system.collections.generic.List<
> Microsoft.Win32.TaskScheduler.TaskCollection>. How convert this
> collection?
// TaskGet:
public FakesDelegates.Func<TaskCollection> TasksGet { set; }
// TaskCollection:
public sealed class TaskCollection : IEnumerable<Task>, IEnumerable, IDisposable
{
public int Count { get; }
public Task this[int index] { get; }
public Task this[string name] { get; }
public void Dispose();
public IEnumerator<Task> GetEnumerator();
}
爲什麼你必須創建新的集合'TaskCollection'? –
因爲TasksGet是func屬性 –
zrabzdn
既然你沒有在你的自定義'TaskCollection'上顯示任何構造函數或操作符,我們怎麼可能回答這個問題呢?如何在你的系統中創建一個TaskCollection? –