Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is Assert.AreEqual<byte[]>(one, two); comparing objects or values

Why T cannot be a byte[]? See the description at

https://msdn.microsoft.com/de-de/library/ms243446.aspx

        byte[] one = { 0x1, 0x2, 0x3, 0x4, 0x5 };
        byte[] two = { 0x1, 0x2, 0x3, 0x4, 0x5 };

        //don't fail
        Assert.AreEqual(Convert.ToBase64String(one), Convert.ToBase64String(two));
        //fail
        Assert.AreEqual<byte[]>(one, two);
like image 375
steininger Avatar asked May 27 '16 13:05

steininger


Video Answer


1 Answers

You are comparing that one byte array has reference equality with another byte array (i.e. that both variables point to the same array), which in this case they don't.

A better approach is to test using SequenceEqual:

using System.Linq;

Assert.IsTrue(one.SequenceEqual(two));
like image 169
RB. Avatar answered Sep 20 '22 20:09

RB.