public void MultipleTryBuildTest(string folder)
        {
            var testFolder = Path.Combine(TestDataFolder, folder);

            DirectoryAssert.Exists(testFolder);

            var logFiles = Directory.GetFiles(testFolder, "*.txt");

            var capturedPackets = new List <CapturedPacket>();

            foreach (var logFile in logFiles)
            {
                capturedPackets.AddRange(TcpImporterTestUtils.ReadCapturedPackets(logFile, null));
            }

            capturedPackets = capturedPackets.OrderBy(x => x.CreatedTimeStamp).ToList();

            var handHistories = new List <HandHistory>();

            var packetManager    = new PPPokerPacketManager();
            var handBuilder      = new PPPHandBuilder();
            var debugPPPImporter = new DebugPPPImporter();

            foreach (var capturedPacket in capturedPackets)
            {
                if (!packetManager.TryParse(capturedPacket, out IList <PPPokerPackage> packages))
                {
                    continue;
                }

                foreach (var package in packages)
                {
                    if (!PPPImporterStub.IsAllowedPackage(package))
                    {
                        continue;
                    }

                    package.Timestamp = capturedPacket.CreatedTimeStamp;

                    debugPPPImporter.LogPackage(capturedPacket, package);

                    if (handBuilder.TryBuild(package, out HandHistory handHistory))
                    {
                        handHistories.Add(handHistory);
                        LogProvider.Log.Info($"Hand #{handHistory.HandId} has been sent. [{package.ClientPort}]");
                    }
                }
            }

            WriteHandHistoriesToFile(handHistories);

            Assert.IsTrue(handHistories.Count > 0);
        }
예제 #2
0
        public void MultipleTryBuildTest(string folder, int expectedTotalHands)
        {
            var testFolder = Path.Combine(TestDataFolder, folder);

            DirectoryAssert.Exists(testFolder);

            var logFiles = Directory.GetFiles(testFolder, "*.txt.");

            var capturedPackets = new List <CapturedPacket>();

            foreach (var logFile in logFiles)
            {
                capturedPackets.AddRange(TcpImporterTestUtils.ReadCapturedPackets(logFile, null));
            }

            capturedPackets = capturedPackets.OrderBy(x => x.CreatedTimeStamp).ToList();

            var handHistories = new List <HandHistory>();

            var packetManager   = new PokerKingPacketManager();
            var handBuilder     = new PKHandBuilder();
            var debugPKImporter = new DebugPKImporter();

            foreach (var capturedPacket in capturedPackets)
            {
                if (!packetManager.TryParse(capturedPacket, out IList <PokerKingPackage> packages))
                {
                    continue;
                }

                var isFastFold = PKImporterHelper.IsFastFoldPort(capturedPacket.Destination.Port) ||
                                 PKImporterHelper.IsFastFoldPort(capturedPacket.Source.Port);

                foreach (var package in packages)
                {
                    package.IsFastFold = isFastFold;

                    if (!PKImporterStub.IsAllowedPackage(package))
                    {
                        continue;
                    }

                    package.Timestamp = capturedPacket.CreatedTimeStamp;

                    debugPKImporter.LogPackage(capturedPacket, package);

                    if (package.PackageType == PackageType.RequestJoinRoom)
                    {
                        debugPKImporter.ParsePackage <RequestJoinRoom>(package,
                                                                       body => LogProvider.Log.Info($"User {package.UserId} entered room {body.RoomId}."),
                                                                       () => LogProvider.Log.Info($"User {package.UserId} entered room."));

                        continue;
                    }

                    var port = destinationPorts.Contains(capturedPacket.Destination.Port) ? capturedPacket.Destination.Port : capturedPacket.Source.Port;

                    if (package.PackageType == PackageType.RequestLeaveRoom)
                    {
                        debugPKImporter.ParsePackage <RequestLeaveRoom>(package,
                                                                        body =>
                        {
                            LogProvider.Log.Info($"User {package.UserId} left room {body.RoomId}.");
                            handBuilder.CleanRoom(port, body.RoomId);
                        },
                                                                        () => LogProvider.Log.Info($"User {package.UserId} left room {package.RoomId}."));

                        continue;
                    }

                    if (isFastFold && package.PackageType == PackageType.NoticeQuickLeave)
                    {
                        debugPKImporter.ParsePackage <NoticeQuickLeave>(package,
                                                                        body =>
                        {
                            handBuilder.CleanFastFoldRooms(package, port, out List <HandHistory> fastFoldHandHistories);

                            foreach (var fastFoldHandHistory in fastFoldHandHistories)
                            {
                                LogProvider.Log.Info($"Hand #{fastFoldHandHistory.HandId} user #{package.UserId} room #{package.RoomId}");
                                handHistories.Add(fastFoldHandHistory);
                            }

                            LogProvider.Log.Info($"User {package.UserId} left room {body.RoomId} (Fast Fold).");
                        },
                                                                        () => LogProvider.Log.Info($"User {package.UserId} left room {package.RoomId} (Fast Fold)."));

                        continue;
                    }

                    if (handBuilder.TryBuild(package, port, out HandHistory handHistory))
                    {
                        handHistories.Add(handHistory);
                        LogProvider.Log.Info($"Hand #{handHistory.HandId} has been sent. [{package.UserId}]");
                    }
                }
            }

            WriteHandHistoriesToFile(handHistories);

            Assert.That(handHistories.Count, Is.EqualTo(expectedTotalHands));
        }