Esempio n. 1
0
        public void SpectatorResponseDeserializationTest(string file, PokerBaaziStartGameResponse expectedResponse)
        {
            var spectatorResponse = ReadPackageFromFile <PokerBaaziResponse <PokerBaaziStartGameResponse> >(file);

            Assert.Multiple(() =>
            {
                Assert.That(spectatorResponse.ClassObj.RoomId, Is.EqualTo(expectedResponse.RoomId));
                Assert.That(spectatorResponse.ClassObj.HandId, Is.EqualTo(expectedResponse.HandId));
                Assert.That(spectatorResponse.ClassObj.SmallBlind, Is.EqualTo(expectedResponse.SmallBlind));
                Assert.That(spectatorResponse.ClassObj.BigBlind, Is.EqualTo(expectedResponse.BigBlind));
                Assert.That(spectatorResponse.ClassObj.TotalAnte, Is.EqualTo(expectedResponse.TotalAnte));
                Assert.That(spectatorResponse.ClassObj.Ante, Is.EqualTo(expectedResponse.Ante));
                Assert.That(spectatorResponse.ClassObj.TournamentId, Is.EqualTo(expectedResponse.TournamentId));

                Assert.That(spectatorResponse.ClassObj.Players.Count, Is.EqualTo(expectedResponse.Players.Count));

                foreach (var player in spectatorResponse.ClassObj.Players)
                {
                    Assert.IsTrue(expectedResponse.Players.TryGetValue(player.Key, out PokerBaaziPlayerInfo expectedPlayer));

                    Assert.That(player.Value.Cards, Is.EqualTo(expectedPlayer.Cards), "Cards must be equal");
                    Assert.That(player.Value.Chips, Is.EqualTo(expectedPlayer.Chips), "Chips must be equal");
                    Assert.That(player.Value.IsBigBlind, Is.EqualTo(expectedPlayer.IsBigBlind), "IsBigBlind must be equal");
                    Assert.That(player.Value.IsDealer, Is.EqualTo(expectedPlayer.IsDealer), "IsDealer must be equal");
                    Assert.That(player.Value.IsSmallBlind, Is.EqualTo(expectedPlayer.IsSmallBlind), "IsSmallBlind must be equal");
                    Assert.That(player.Value.PlayerId, Is.EqualTo(expectedPlayer.PlayerId), "PlayerId must be equal");
                    Assert.That(player.Value.PlayerName, Is.EqualTo(expectedPlayer.PlayerName), "PlayerName must be equal");
                    Assert.That(player.Value.Seat, Is.EqualTo(expectedPlayer.Seat), "Seat must be equal");
                    Assert.That(player.Value.BetAmount, Is.EqualTo(expectedPlayer.BetAmount), "BetAmount must be equal");
                }
            });
        }
        /// <summary>
        /// Processes the specified <see cref="PokerBaaziStartGameResponse"/>
        /// </summary>
        /// <param name="startGameResponse">Response to process</param>
        /// <param name="handHistory">Hand history</param>
        private void ProcessSpectatorResponse(PokerBaaziStartGameResponse startGameResponse, long timestamp, HandHistory handHistory)
        {
            if (!roomsInitResponses.TryGetValue(startGameResponse.RoomId, out PokerBaaziInitResponse initResponse))
            {
                throw new PokerBaaziHandBuilderException(startGameResponse.HandId, $"InitResponse has not been found for room #{startGameResponse.RoomId}");
            }

            var isTournament = startGameResponse.TournamentId != 0;

            handHistory.HandId        = startGameResponse.HandId;
            handHistory.DateOfHandUtc = DateTimeHelper.UnixTimeInMilisecondsToDateTime(timestamp);

            handHistory.TableName = isTournament && !string.IsNullOrEmpty(initResponse.TournamentTableName) ?
                                    initResponse.TournamentTableName : initResponse.TournamentName;

            handHistory.GameDescription = isTournament ?
                                          CreateTournamentGameDescriptor(initResponse, startGameResponse) : CreateCashGameDescriptor(initResponse, startGameResponse);

            handHistory.GameDescription.Identifier = startGameResponse.RoomId;

            if (startGameResponse.Players == null)
            {
                throw new PokerBaaziHandBuilderException(startGameResponse.HandId, $"SpectatorResponse.Players isn't set for room #{startGameResponse.RoomId}");
            }

            // add players
            foreach (var playerInfo in startGameResponse.Players.Values)
            {
                if (playerInfo.PlayerId <= 0)
                {
                    continue;
                }

                var player = new Player
                {
                    PlayerName    = playerInfo.PlayerName,
                    SeatNumber    = playerInfo.Seat + 1,
                    StartingStack = playerInfo.Chips + playerInfo.BetAmount
                };

                if (initResponse.UserId == playerInfo.PlayerId)
                {
                    handHistory.Hero = player;
                }

                if (PokerBaaziUtils.TryParseCards(playerInfo.Cards, out Card[] holeCards))