共用方式為


CollectionAssert.AllItemsAreInstancesOfType 方法 (ICollection, Type, String, array<Object )

確認指定之集合中的所有項目都是指定之型別的執行個體。 如果集合中存在一個項目,但是指定的型別不在其繼承階層架構內,判斷提示就會失敗。 如果判斷提示失敗,便顯示一則訊息,並套用指定的格式。

命名空間:  Microsoft.VisualStudio.TestTools.UnitTesting
組件:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (在 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 中)

語法

'宣告
Public Shared Sub AllItemsAreInstancesOfType ( _
    collection As ICollection, _
    expectedType As Type, _
    message As String, _
    ParamArray parameters As Object() _
)
public static void AllItemsAreInstancesOfType(
    ICollection collection,
    Type expectedType,
    string message,
    params Object[] parameters
)
public:
static void AllItemsAreInstancesOfType(
    ICollection^ collection, 
    Type^ expectedType, 
    String^ message, 
    ... array<Object^>^ parameters
)
static member AllItemsAreInstancesOfType : 
        collection:ICollection * 
        expectedType:Type * 
        message:string * 
        parameters:Object[] -> unit 
public static function AllItemsAreInstancesOfType(
    collection : ICollection, 
    expectedType : Type, 
    message : String, 
    ... parameters : Object[]
)

參數

  • expectedType
    型別:System.Type
    必須位於 collection 中每個項目之繼承階層架構中的型別。
  • message
    型別:System.String
    要在判斷提示失敗時顯示的訊息。這項訊息會在單元測試結果中出現。
  • parameters
    型別:array<System.Object[]
    在格式化 message 時所要使用的參數陣列。

例外狀況

例外狀況 條件
AssertFailedException

collection 中的項目為 nullNull 參照 (即 Visual Basic 中的 Nothing),或是 expectedType 不在 collection 中所有項目的繼承階層架構內。

.NET Framework 安全性

請參閱

參考

CollectionAssert 類別

AllItemsAreInstancesOfType 多載

Microsoft.VisualStudio.TestTools.UnitTesting 命名空間

其他資源

使用 Assert 類別