public void DumpWithoutDeviceTest() { string filename = Path.GetTempPath() + @"dump.pcap"; Packet expectedPacket = PacketBuilder.Build(DateTime.Now, new EthernetLayer { Source = new MacAddress(1), Destination = new MacAddress(2), EtherType = EthernetType.QInQ, }, new PayloadLayer { Data = new Datagram(new byte[] { 1, 2, 3 }) }); PacketDumpFile.Dump(filename, DataLinkKind.Ethernet, PacketDevice.DefaultSnapshotLength, new[] { expectedPacket }); using (PacketCommunicator communicator = new OfflinePacketDevice(filename).Open()) { Packet actualPacket; PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out actualPacket); Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result); Assert.AreEqual(expectedPacket, actualPacket); MoreAssert.IsInRange(expectedPacket.Timestamp.AddMicroseconds(-2), expectedPacket.Timestamp.AddMicroseconds(1), actualPacket.Timestamp); } }
public void DumpWithoutDeviceTest() { string filename = Path.GetTempPath() + @"dump.pcap"; Packet expectedPacket = PacketBuilder.Build(DateTime.Now, new EthernetLayer { Source = new MacAddress(1), Destination = new MacAddress(2), EtherType = EthernetType.QInQ, }, new PayloadLayer { Data = new Datagram(new byte[] {1, 2, 3}) }); PacketDumpFile.Dump(filename, DataLinkKind.Ethernet, PacketDevice.DefaultSnapshotLength, new[] {expectedPacket}); using (PacketCommunicator communicator = new OfflinePacketDevice(filename).Open()) { Packet actualPacket; PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out actualPacket); Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result); Assert.AreEqual(expectedPacket, actualPacket); MoreAssert.IsInRange(expectedPacket.Timestamp.AddMicroseconds(-2), expectedPacket.Timestamp.AddMicroseconds(1), actualPacket.Timestamp); } }