예제 #1
0
        public void IT_When_RejectGame_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 rejectGameRequestObject = new RejectGameClientMessage
                {
                    UserName = player2Name,
                    SessionName = gameInviteNotificationObject.SessionName
                };
                var rejectGameRequest = new GameRequest(GameRequestType.GameRejected)
                {
                    Sender = player2Name,
                    SerializedRequestObject = this.serializer.Serialize(rejectGameRequestObject)
                };

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

            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.GameRejected, notification.Type);
            Assert.IsNotNull(notificationObject);
            Assert.IsTrue(notificationObject is GameRejectedServerMessage);

            var gameRejectedNotificationObject = notificationObject as GameRejectedServerMessage;

            Assert.AreEqual(player1Name, gameRejectedNotificationObject.Player1Name);
            Assert.AreEqual(player2Name, gameRejectedNotificationObject.Player2Name);
            Assert.AreEqual(string.Format("{0}-vs-{1}", player1Name, player2Name), gameRejectedNotificationObject.SessionName);
        }
예제 #2
0
 public void RejectGame(RejectGameClientMessage rejectGameClientMessage)
 {
     this.rejectGameService.Send(rejectGameClientMessage);
 }
        public void UT_When_HandleRejectGame_Then_Success()
        {
            this.sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == this.session.Name)))
                .Returns(this.session)
                .Verifiable();

            var rejectGameClientMessage = new RejectGameClientMessage
            {
                SessionName = this.sessionName,
                UserName = this.player2.Name
            };
            var clientContract = new ClientContract
            {
                Type = GamifyClientMessageType.RejectGame,
                Sender = this.player2.Name,
                SerializedClientMessage = this.serializer.Serialize(rejectGameClientMessage)
            };

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

            gameCreationPluginComponent.HandleClientMessage(clientContract);

            this.sessionServiceMock.VerifyAll();
            this.notificationServiceMock.Verify(s => s.Send(It.Is<int>(t => t == GamifyServerMessageType.GameRejected),
                It.Is<object>(o => ((GameRejectedServerMessage)o).SessionName == this.session.Name
                    && ((GameRejectedServerMessage)o).Player1Name == this.session.Player1Name
                    && ((GameRejectedServerMessage)o).Player2Name == this.session.Player2Name),
                It.Is<string>(x => x == this.session.Player1Name)));

            Assert.IsTrue(canHandle);
        }