예제 #1
0
 public void AcceptGame(AcceptGameClientMessage acceptGameClientMessage)
 {
     this.acceptGameService.Send(acceptGameClientMessage);
 }
예제 #2
0
        public void IT_When_AcceptGame_Then_Success()
        {
            var player1Name = GetPlayerName();
            var player1GameHandler = this.ConnectPlayer(player1Name);
            var player2Name = GetPlayerName();
            var player2GameHandler = this.ConnectPlayer(player2Name);

            var notification = default(GameNotification);
            var notificationObject = default(object);

            player1GameHandler.Notification += (sender, e) =>
            {
                notification = this.serializer.Deserialize<GameNotification>(e.SerializedNotification);
                notificationObject = this.serializer.Deserialize<object>(notification.SerializedNotificationObject);
            };
            player2GameHandler.Notification += (sender, e) =>
            {
                var gameInviteNotification = this.serializer.Deserialize<GameNotification>(e.SerializedNotification);

                if (gameInviteNotification.Type != (int)GameNotificationType.GameInvite)
                {
                    return;
                }

                var gameInviteNotificationObject = this.serializer.Deserialize<GameInviteReceivedServerMessage>(gameInviteNotification.SerializedNotificationObject);

                var acceptGameRequestObject = new AcceptGameClientMessage
                {
                    UserName = player2Name,
                    SessionName = gameInviteNotificationObject.SessionName
                };
                var acceptGameRequest = new GameRequest(GameRequestType.GameAccepted)
                {
                    Sender = player2Name,
                    SerializedRequestObject = this.serializer.Serialize(acceptGameRequestObject)
                };

                player2GameHandler.OnMessage(this.serializer.Serialize(acceptGameRequest));
            };

            var createGameRequestObject = new CreateGameClientMessage
            {
                UserName = player1Name,
                InvitedUserName = player2Name
            };
            var createGameRequest = new GameRequest(GameRequestType.CreateGame)
            {
                Sender = player1Name,
                SerializedRequestObject = this.serializer.Serialize(createGameRequestObject)
            };

            player1GameHandler.OnMessage(this.serializer.Serialize(createGameRequest));

            Assert.AreEqual((int)GameNotificationType.GameCreated, notification.Type);
            Assert.IsNotNull(notificationObject);
            Assert.IsTrue(notificationObject is GameCreatedServerMessage);

            var gameCreatedNotificationObject = notificationObject as GameCreatedServerMessage;

            Assert.AreEqual(player1Name, gameCreatedNotificationObject.Player1Name);
            Assert.AreEqual(player2Name, gameCreatedNotificationObject.Player2Name);
            Assert.AreEqual(string.Format("{0}-vs-{1}", player1Name, player2Name), gameCreatedNotificationObject.SessionName);
            Assert.IsTrue(string.IsNullOrEmpty(gameCreatedNotificationObject.AdditionalInformation));
        }
        public void UT_When_HandleAcceptGame_Then_Success()
        {
            this.sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == this.session.Name)))
                .Returns(this.session)
                .Verifiable();
            this.sessionServiceMock
                .Setup(s => s.Start(It.Is<IGameSession>(x => x.Name == this.session.Name)))
                .Verifiable();
            this.playerSetupMock.Setup(s => s.GetPlayerReady(It.Is<AcceptGameClientMessage>(x => x.SessionName == this.sessionName),
                It.Is<TestSessionPlayer>(p => p.Information.Name == "player2")))
                .Verifiable();

            var acceptGameClientMessage = new AcceptGameClientMessage
            {
                SessionName = this.sessionName,
                UserName = this.player2.Name,
                AdditionalInformation = "Test"
            };
            var clientContract = new ClientContract
            {
                Type = GamifyClientMessageType.AcceptGame,
                Sender = this.player2.Name,
                SerializedClientMessage = this.serializer.Serialize(acceptGameClientMessage)
            };

            var gameCreationPluginComponent = this.GetGameCreationPluginComponent();
            var canHandle = gameCreationPluginComponent.CanHandleClientMessage(clientContract);

            gameCreationPluginComponent.HandleClientMessage(clientContract);

            this.sessionServiceMock.VerifyAll();
            this.playerSetupMock.VerifyAll();
            this.notificationServiceMock.Verify(s => s.SendBroadcast(It.Is<int>(t => t == GamifyServerMessageType.GameCreated),
                It.Is<object>(o => ((GameCreatedServerMessage)o).SessionName == this.session.Name),
                It.Is<string>(x => x == this.session.Player1Name),
                It.Is<string>(x => x == this.session.Player2Name)));

            Assert.IsTrue(canHandle);
            Assert.IsTrue(this.session.Player1.PendingToMove);
            Assert.IsFalse(this.session.Player2.PendingToMove);
        }
 public void GetPlayerReady(AcceptGameClientMessage gameAcceptedRequest, SessionGamePlayer gamePlayer)
 {
     this.GetPlayerReady(gameAcceptedRequest.AdditionalInformation, gamePlayer);
 }
 public void GetPlayerReady(AcceptGameClientMessage gameAcceptedRequest, SessionGamePlayer gamePlayer)
 {
     return;
 }