Esempio n. 1
0
        public static void TestMethods()
        {
            DataHmac hmac = new DataHmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            Assert.That(hmac.Length, Is.EqualTo(16), "The length should always be 16.");
            Assert.That(hmac.GetBytes(), Is.EquivalentTo(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), "Check that GetBytes() returns the expected.");
            Assert.That(hmac, Is.EqualTo(new DataHmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 })), "Check Equals() override.");
            Assert.That(hmac == new DataHmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), Is.True, "Check operator== override.");
            Assert.That(hmac != new DataHmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }), Is.False, "Check operator!= override.");

            DataHmac hmac2 = new DataHmac(new byte[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });
            Assert.That(hmac.GetHashCode(), Is.Not.EqualTo(0), "The hash code should not be zero (can be, but it's not in this case).");
            Assert.That(hmac.GetHashCode(), Is.EqualTo(hmac2.GetHashCode()), "The hash code for two different instances with same value should be the same.");

            Assert.That(hmac.Equals(null), Is.False, "An instance is never equal to null.");
            Assert.That(hmac.Equals(new object()), Is.False, "An instance is never equal to another instance of a differing type.");
            DataHmac hmacSynonym = hmac;
            Assert.That(hmac == hmacSynonym, Is.True, "These should compare equal via reference equality.");
        }