2009-07-09 11 views
1

私はNUnitからのユニットテストをVisualStudio 2010ユニットテストフレームワークに変換しています。次ByteToUShortTest()方法はメッセージで失敗します。VS 2010ユニットテストと符号なしタイプ

Assert.AreEqual failed. Expected:<System.UInt16[]>. Actual:<System.UInt16[]>.

[TestMethod, CLSCompliant(false)] 
public void ByteToUShortTest() 
{ 
    var array = new byte[2]; 
    Assert.AreEqual(ByteToUShort(array), new ushort[1]); 
} 

テストによって呼び出されるコードです:

[CLSCompliant(false)] 
public static ushort[] ByteToUShort(byte[] array) 
{ 
    return ByteToUShort(array, 0, array.Length, EndianType.LittleEndian); 
} 

public enum EndianType 
{ 
    LittleEndian, 
    BigEndian 
} 

[CLSCompliant(false)] 
public static ushort[] ByteToUShort(byte[] array, int offset, int length, EndianType endianType) 
{ 
    // argument validation 
    if ((length + offset) > array.Length) 
     throw new ArgumentException("The length and offset provided extend past the end of the array."); 
    if ((length % 2) != 0) 
     throw new ArgumentException("The number of bytes to convert must be a multiple of 2.", "length"); 

    var temp = new ushort[length/2]; 

    for (int i = 0, j = offset; i < temp.Length; i++) 
    { 
     if (endianType == EndianType.LittleEndian) 
     { 
      temp[i] = (ushort)(((uint)array[j++] & 0xFF) | (((uint)array[j++] & 0xFF) << 8)); 
     } 
     else 
     { 
      temp[i] = (ushort)(((uint)array[j++] & 0xFF) << 8 | ((uint)array[j++] & 0xFF)); 
     } 
    } 

    return temp; 
} 

このテストでは、NUnitので正常に動作していました。タイプが異なると思われる理由は何ですか?

単と多次元配列について

ソリューション、ならびに任意ICollectionため、VisualStudioを2010単位テストフレームワークはCollectionAssertクラスを提供します。

[TestMethod, CLSCompliant(false)] 
public void ByteToUShortTest() 
{ 
    var array = new byte[2]; 
    CollectionAssert.AreEqual(ByteToUShort(array), new ushort[1]); 
} 

答えて

4

これは異なるタイプではなく、インスタンスです。 2つの異なる配列を比較しています。

関連する問題