//[TestCase(@"Packets\218.98.62.171.9188-192.168.0.102.60431.txt", "NGQ0ODUwZTBiZjRhMGZhMQ==", @"Packets\218.98.62.171.9188-192.168.0.102.60431-cmd.txt", "yyyy/M/dd H:mm:ss")]
        //[TestCase(@"Packets\218.98.62.171.9188-192.168.0.102.60462.txt", "YWMzYjJhYjg0MjljMmQxZA==", @"Packets\218.98.62.171.9188-192.168.0.102.60462-cmd.txt", "yyyy/M/dd H:mm:ss")]
        public void TryParseTest(string file, string decryptKey, string expectedCommandsFile, string dateFormat)
        {
            var packets          = ReadCapturedPackets(file, dateFormat);
            var expectedCommands = !string.IsNullOrEmpty(expectedCommandsFile) ?
                                   GetPackageTypeList <PackageCommand>(expectedCommandsFile) :
                                   new List <PackageCommand>();

            var packetManager = new PokerMasterPacketManager();

            var decryptKeyBytes = Convert.FromBase64String(decryptKey);

            var bodyDecryptor = new BodyDecryptor();

            var expectedCommandsIndex = 0;

            using (ShimsContext.Create())
            {
                foreach (var packet in packets)
                {
                    ShimDateTime.NowGet = () => packet.CreatedTimeStamp;

                    if (packetManager.TryParse(packet, out IList <PokerMasterPackage> packages))
                    {
                        foreach (var package in packages)
                        {
                            Console.WriteLine(package.Cmd);

                            if (expectedCommands.Count > 0)
                            {
                                Assert.That(package.Cmd, Is.EqualTo(expectedCommands[expectedCommandsIndex++]));
                            }

                            if (package.Cmd == PackageCommand.Cmd_SCLoginRsp)
                            {
                                var body = bodyDecryptor.Decrypt(package.Body);

                                File.WriteAllBytes(@"d:\dta.bin", body);

                                if (!SerializationHelper.TryDeserialize(body, out SCLoginRsp sCLoginRsp))
                                {
                                    Assert.Fail($"Packet {packet.SequenceNumber} was incorrectly combined with other packets. So result can't be deserialized.");
                                }
                            }

                            if (package.Cmd == PackageCommand.Cmd_SCGameRoomStateChange)
                            {
                                var body = bodyDecryptor.Decrypt(package.Body, decryptKeyBytes, false);

                                if (!SerializationHelper.TryDeserialize(body, out SCGameRoomStateChange sCGameRoomStateChange))
                                {
                                    Assert.Fail($"Packet {packet.SequenceNumber} was incorrectly combined with other packets. So result can't be deserialized.");
                                }
                            }
                        }
                    }
                }
            }
        }
        public void TryParsePacketTest(string file)
        {
            var bytes         = ReadPacketFile(file);
            var packetManager = new PokerMasterPacketManager();

            var capturedPacket = new CapturedPacket
            {
                Bytes            = bytes,
                CreatedTimeStamp = DateTime.Parse("08/02/2018 12:28:28"),
                Destination      = new IPEndPoint(IPAddress.Parse("192.168.0.105"), 27633),
                Source           = new IPEndPoint(IPAddress.Parse("47.52.92.161"), 9188),
                SequenceNumber   = 1962805251
            };

            var dumpFiles = Directory.GetFiles(@"d:\Temp\Dump\", "*.*", SearchOption.TopDirectoryOnly);

            var sqNo = 1u;

            foreach (var dumpFile in dumpFiles)
            {
                var dumpCaptPack = new CapturedPacket
                {
                    Bytes            = File.ReadAllBytes(dumpFile).Skip(25).ToArray(),
                    CreatedTimeStamp = DateTime.Parse("08/02/2018 12:28:28"),
                    Destination      = new IPEndPoint(IPAddress.Parse("192.168.0.105"), 27633),
                    Source           = new IPEndPoint(IPAddress.Parse("47.52.92.161"), 9188),
                    SequenceNumber   = sqNo++
                };

                if (packetManager.TryParse(dumpCaptPack, out IList <PokerMasterPackage> dumpPacks))
                {
                    var dmpPack = dumpPacks.FirstOrDefault();

                    if (dmpPack.Cmd == PackageCommand.Cmd_SCLoginRsp)
                    {
                        var bodyDecryptor = new BodyDecryptor();


                        var key = Encoding.UTF8.GetBytes("116ff58c0b178429");

                        var bodyBytes = bodyDecryptor.Decrypt(dmpPack.Body, key, false);

                        File.WriteAllBytes(@"d:\dmp.bin", bodyBytes);
                    }
                }
            }

            var result = packetManager.TryParse(capturedPacket, out IList <PokerMasterPackage> actualPackages);

            Assert.IsTrue(result);
            Assert.IsNotNull(actualPackages);
            CollectionAssert.IsNotEmpty(actualPackages);
        }
        public void DeserializationTest(string file, string username)
        {
            var body = ReadPacketFile(file);

            var bodyDecryptor = new BodyDecryptor();

            var bytes = bodyDecryptor.Decrypt(body);

            var scLoginRsp = SerializationHelper.Deserialize <SCLoginRsp>(bytes);

            Assert.IsNotNull(scLoginRsp);
            Assert.IsNotNull(scLoginRsp.UserInfo);
            Assert.That(scLoginRsp.UserInfo.Nick, Is.EqualTo(username));
        }