Пример #1
0
        public void SendPlayerId_None_ClientReceivedPlayerId(IServerMessageTransceiver server, IClientMessageTransceiver client)
        {
            const int TestPlayerId = 0;

            Task sendPlayerIdTask = null;

            server.ReceivedJoinRequest += (sender, args) =>
            {
                sendPlayerIdTask = server.SendPlayerIdAsync(args.ConnectionId, TestPlayerId);
            };

            int playerId = -1;

            client.ReceivedPlayerId += (sender, args) =>
            {
                playerId = args.PlayerId;
            };

            var sendJoinRequestTask = client.SendJoinRequestAsync();

            sendJoinRequestTask.Wait();
            sendPlayerIdTask.Wait();

            Assert.Equal(TestPlayerId, playerId);
        }
Пример #2
0
        public void SendJoinRequestAsync_None_ServerGetConnectionId(IServerMessageTransceiver server, IClientMessageTransceiver client)
        {
            string connectionId = null;

            server.ReceivedJoinRequest += (sender, args) =>
            {
                connectionId = args.ConnectionId;
            };

            var task = client.SendJoinRequestAsync();

            task.Wait();

            Assert.False(string.IsNullOrEmpty(connectionId));
        }
Пример #3
0
        /// <summary>
        /// ゲームに参加
        /// </summary>
        /// <returns></returns>
        public int JoinGame()
        {
            var task = messageTransceiver.SendJoinRequestAsync();

            task.Wait();

            if (id == -1)
            {
                hasJoined = false;
            }
            else
            {
                hasJoined = true;
            }

            return(id);
        }
Пример #4
0
        public void SendEndMessageAsync(IServerMessageTransceiver server, IClientMessageTransceiver client)
        {
            string connectionId = null;

            server.ReceivedJoinRequest += (_, args) =>
            {
                connectionId = args.ConnectionId;
            };

            EndMessage msg = EndMessage.NotEnd;

            client.ReceivedEndMessage += (_, args) =>
            {
                msg = args.EndMessage;
            };

            client.SendJoinRequestAsync().Wait();

            server.SendEndMessageAsync(connectionId, EndMessage.EndGame).Wait();

            Assert.Equal(EndMessage.EndGame, msg);
        }
Пример #5
0
        public void SendResultOfPlayingAsync_SendResult_ClientReceivedResult(IServerMessageTransceiver server, IClientMessageTransceiver client)
        {
            string connectionId = null;

            server.ReceivedJoinRequest += (_, args) =>
            {
                connectionId = args.ConnectionId;
            };

            ResultOfPlaying result = ResultOfPlaying.NotAccepted;

            client.ReceivedResultOfPlaying += (_, args) =>
            {
                result = args.Result;
            };

            client.SendJoinRequestAsync().Wait();

            server.SendResultOfPlayingAsync(connectionId, ResultOfPlaying.Accepted).Wait();

            Assert.Equal(ResultOfPlaying.Accepted, result);
        }
Пример #6
0
        public void SendStatusAsync_SendStatus_ClientReceivedStatus(IServerMessageTransceiver server, IClientMessageTransceiver client)
        {
            string connectionId = null;

            server.ReceivedJoinRequest += (_, args) =>
            {
                connectionId = args.ConnectionId;
            };

            var sendJoinRequestTask = client.SendJoinRequestAsync();

            sendJoinRequestTask.Wait();

            var publicStatus = new PublicStatus
            {
                field = new List <Card> {
                    new Card(Suit.Joker, 0),
                },
                phase          = Phase.Trading,
                turn           = 1,
                hasFlowed      = true,
                isElevenBack   = false,
                isKakumei      = false,
                isShibari      = false,
                playerStatuses = new List <PublicPlayerStatus>
                {
                    new PublicPlayerStatus
                    {
                        id        = 0,
                        seat      = 2,
                        roleRank  = RoleRank.Heimin,
                        cardCount = 3,
                        hasPassed = false,
                    }
                },
            };

            var privateStatus = new PrivateStatus
            {
                id       = 0,
                seat     = 2,
                roleRank = RoleRank.Heimin,
                hand     = new List <Card> {
                    new Card(Suit.Spades, 1), new Card(Suit.Spades, 2), new Card(Suit.Spades, 3)
                },
                tradingCardCount = 0,
                hasPassed        = false,
            };

            PublicStatus  actualPublicStatus  = null;
            PrivateStatus actualPrivateStatus = null;

            client.ReceivedStatus += (_, args) =>
            {
                actualPublicStatus  = args.PublicStatus;
                actualPrivateStatus = args.PrivateStatus;
            };

            server.SendStatusAsync(connectionId, publicStatus, privateStatus);

            var isEqual =
                publicStatus.field.SequenceEqual(actualPublicStatus.field) &&
                publicStatus.phase == actualPublicStatus.phase &&
                publicStatus.turn == actualPublicStatus.turn &&
                publicStatus.hasFlowed == actualPublicStatus.hasFlowed &&
                publicStatus.isElevenBack == actualPublicStatus.isElevenBack &&
                publicStatus.isKakumei == actualPublicStatus.isKakumei &&
                publicStatus.isShibari == actualPublicStatus.isShibari &&
                publicStatus.playerStatuses.SequenceEqual(actualPublicStatus.playerStatuses);

            isEqual &=
                privateStatus.id == actualPrivateStatus.id &&
                privateStatus.seat == actualPrivateStatus.seat &&
                privateStatus.roleRank == actualPrivateStatus.roleRank &&
                privateStatus.hand.SequenceEqual(actualPrivateStatus.hand) &&
                privateStatus.tradingCardCount == actualPrivateStatus.tradingCardCount &&
                privateStatus.hasPassed == actualPrivateStatus.hasPassed;

            Assert.True(isEqual);
        }