public void CreateGame(CreateGameClientMessage createGameClientMessage)
 {
     this.createGameService.Send(createGameClientMessage);
 }
        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_HandleCreateGame_Then_Success()
        {
            this.playerServiceMock
               .Setup(s => s.GetByName(It.Is<string>(x => x == this.player1.DisplayName)))
               .Returns(this.player1)
               .Verifiable();
            this.playerServiceMock
               .Setup(s => s.GetByName(It.Is<string>(x => x == this.player2.DisplayName)))
               .Returns(this.player2)
               .Verifiable();
            this.playerFactoryMock
                .Setup(f => f.Create(It.Is<IUser>(p => p == this.player1)))
                .Returns(this.sessionPlayer1)
                .Verifiable();
            this.playerFactoryMock
                .Setup(f => f.Create(It.Is<IUser>(p => p == this.player2)))
                .Returns(this.sessionPlayer2)
                .Verifiable();
            this.playerSetupMock.Setup(s => s.GetPlayerReady(It.Is<CreateGameClientMessage>(x => x.UserName == this.player1.DisplayName
                && x.InvitedUserName == this.player2.DisplayName),
                It.Is<TestSessionPlayer>(p => p == this.sessionPlayer1)))
                .Verifiable();
            this.sessionServiceMock.Setup(s => s.Create(It.Is<SessionGamePlayer>(p => p == this.sessionPlayer1),
                It.Is<SessionGamePlayer>(p => p == this.sessionPlayer2)))
                .Returns(this.session)
                .Verifiable();
            this.inviteDecoratorMock
                .Setup(d => d.Decorate(It.Is<GameInviteReceivedServerMessage>(n => n.SessionName == this.sessionName && n.Player1Name == this.player1.Name),
                    It.Is<IGameSession>(s => s == this.session)))
                .Verifiable();

            var createGameClientMessage = new CreateGameClientMessage
            {
                UserName = this.player1.DisplayName,
                InvitedUserName = this.player2.DisplayName,
                AdditionalInformation = "Test"
            };
            var clientContract = new ClientContract
            {
                Type = GamifyClientMessageType.CreateGame,
                Sender = this.player1.DisplayName,
                SerializedClientMessage = this.serializer.Serialize(createGameClientMessage)
            };

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

            gameCreationPluginComponent.HandleClientMessage(clientContract);

            this.playerServiceMock.VerifyAll();
            this.sessionServiceMock.VerifyAll();
            this.playerFactoryMock.VerifyAll();
            this.playerSetupMock.VerifyAll();
            this.inviteDecoratorMock.VerifyAll();
            this.notificationServiceMock.Verify(s => s.Send(It.Is<int>(t => t == GamifyServerMessageType.GameInviteReceived),
                    It.Is<object>(o => ((GameInviteReceivedServerMessage)o).Player1Name == this.player1.Name
                        && ((GameInviteReceivedServerMessage)o).SessionName == this.sessionName),
                    It.Is<string>(x => x == this.player2.Name)));

            Assert.IsTrue(canHandle);
        }
 public void GetPlayerReady(CreateGameClientMessage createGameRequest, SessionGamePlayer gamePlayer)
 {
     this.GetPlayerReady(createGameRequest.AdditionalInformation, gamePlayer);
 }
 public void GetPlayerReady(CreateGameClientMessage createGameRequest, SessionGamePlayer gamePlayer)
 {
     return;
 }