2013-06-18 57 views
0

我的測試代碼片段:
使用(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(); 
      } 
+0

爲什麼你必須創建新的集合'TaskCollection'? –

+0

因爲TasksGet是func 屬性 – zrabzdn

+0

既然你沒有在你的自定義'TaskCollection'上顯示任何構造函數或操作符,我們怎麼可能回答這個問題呢?如何在你的系統中創建一個TaskCollection? –

回答

0

假設這是TaskCollection from codeplex,那麼你不能創建自己的TaskCollection包裹任意Task。這不是預期的用途。您將需要更改設計,或更改託管包裝的來源並重建庫。

+0

我需要用TaskScheduller測試一些功能。我使Shim的上下文。 – zrabzdn

+0

@ user2469940你不能單元測試那些沒有以支持可測試性的方式設計的東西 –