public static void TestGetHashCode() { byte[] data = new byte[] { 5, 6, 7, 8, 9, 10 }; byte[] other = new byte[] { 5, 6, 7, 8, 9, 11 }; TestingHeaderBlock block1 = new TestingHeaderBlock((HeaderBlockType)33, data); TestingHeaderBlock block2 = new TestingHeaderBlock((HeaderBlockType)33, data); TestingHeaderBlock block3 = new TestingHeaderBlock((HeaderBlockType)33, other); TestingHeaderBlock block4 = new TestingHeaderBlock((HeaderBlockType)34, data); Assert.That(block1.GetHashCode(), Is.EqualTo(block2.GetHashCode())); Assert.That(block1.GetHashCode(), Is.Not.EqualTo(block3.GetHashCode())); Assert.That(block1.GetHashCode(), Is.Not.EqualTo(block4.GetHashCode())); }
public static void TestObjectEquals() { byte[] data = new byte[] { 5, 6, 7, 8, 9, 10 }; byte[] other = new byte[] { 5, 6, 7, 8, 9, 11 }; object block1 = new TestingHeaderBlock((HeaderBlockType)33, data); object block2 = new TestingHeaderBlock((HeaderBlockType)33, data); object block3 = new TestingHeaderBlock((HeaderBlockType)33, other); object block4 = new TestingHeaderBlock((HeaderBlockType)34, data); object nullBlock = null; Assert.That(block1.Equals(block2)); Assert.That(block2.Equals(block1)); Assert.That(!block1.Equals(block3)); Assert.That(!block1.Equals(block4)); Assert.That(!block1.Equals(nullBlock)); }
public static void TestOperatorEquals() { byte[] data = new byte[] { 5, 6, 7, 8, 9, 10 }; byte[] other = new byte[] { 5, 6, 7, 8, 9, 11 }; TestingHeaderBlock block1 = new TestingHeaderBlock((HeaderBlockType)33, data); TestingHeaderBlock block1alias = block1; TestingHeaderBlock block2 = new TestingHeaderBlock((HeaderBlockType)33, data); TestingHeaderBlock block3 = new TestingHeaderBlock((HeaderBlockType)33, other); TestingHeaderBlock block4 = new TestingHeaderBlock((HeaderBlockType)34, data); TestingHeaderBlock nullBlock = null; TestingHeaderBlock nullBlockAlias = nullBlock; Assert.That(block1 == block1alias); Assert.That(block1 == block2); Assert.That(block2 == block1); Assert.That(block1 != block3); Assert.That(block1 != block4); Assert.That(block1 != nullBlock); Assert.That(nullBlock != block1); Assert.That(nullBlock == nullBlockAlias); }