public void MakeReceivedPacketTest() { // size is big endian { var packetrule = new PacketRuleSizeBody() { SizeBufferEndian = ECNBufferEndian.Big, SizeLength = 4, }; packetrule.Initialize(); Assert.AreEqual(packetrule.WantSize, packetrule.SizeLength); var expectedSizeBuffer = new byte[] { 0, 0, 0, 10 }; var actual0 = packetrule.MakeReceivedPacket(expectedSizeBuffer); Assert.AreEqual(actual0.Count(), 0); Assert.AreEqual(packetrule.WantSize, 10); var expected = Enumerable.Range(1, 10).Select(x => (byte)x).ToArray(); var actual = packetrule.MakeReceivedPacket(expected).ToList(); Assert.AreEqual(actual.Count(), 1); Assert.IsTrue(actual.FirstOrDefault().ToArray().SequenceEqual(expected)); } // size is little endian { var packetrule = new PacketRuleSizeBody() { SizeBufferEndian = ECNBufferEndian.Little, SizeLength = 4, }; packetrule.Initialize(); Assert.AreEqual(packetrule.WantSize, packetrule.SizeLength); var expectedSizeBuffer = new byte[] { 10, 0, 0, 0 }; var actual0 = packetrule.MakeReceivedPacket(expectedSizeBuffer); Assert.AreEqual(actual0.Count(), 0); Assert.AreEqual(packetrule.WantSize, 10); var expected = Enumerable.Range(1, 10).Select(x => (byte)x).ToArray(); var actual = packetrule.MakeReceivedPacket(expected).ToList(); Assert.AreEqual(actual.Count(), 1); Assert.IsTrue(actual.FirstOrDefault().ToArray().SequenceEqual(expected)); } }