public void Initialize()
        {
            this.serializer = new JsonSerializer();

            var player1 = new TestSessionPlayer()
            {
                SessionName = this.sessionName,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 1",
                    Name = "player1"
                }
            };
            var player2 = new TestSessionPlayer()
            {
                SessionName = this.sessionName,
                PendingToMove = true,
                Information = new User
                {
                    DisplayName = "Player 2",
                    Name = "player2"
                }
            };

            this.session = new GameSession(player1, player2);

            this.moveServiceMock = new Mock<IMoveService<TestMoveObject, TestResponseObject>>();
            this.sessionServiceMock = new Mock<ISessionService>();
            this.sessionHistoryServiceMock = new Mock<ISessionHistoryService<TestMoveObject, TestResponseObject>>();
            this.notificationServiceMock = new Mock<INotificationService>();
            this.moveFactoryMock = new Mock<IMoveFactory<TestMoveObject>>();
            this.moveResultNotificationFactoryMock = new Mock<IMoveResultNotificationFactory>();
        }
        public void Initialize()
        {
            this.serializer = new JsonSerializer();

            var player1s1 = new TestSessionPlayer()
            {
                SessionName = this.session1Name,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 1",
                    Name = "player1"
                }
            };
            var player2s1 = new TestSessionPlayer()
            {
                SessionName = this.session1Name,
                PendingToMove = true,
                Information = new User
                {
                    DisplayName = "Player 2",
                    Name = "player2"
                }
            };
            var player1s2 = new TestSessionPlayer()
            {
                SessionName = this.session2Name,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 1",
                    Name = "player1"
                }
            };
            var player3s2 = new TestSessionPlayer()
            {
                SessionName = this.session2Name,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 3",
                    Name = "player3"
                }
            };

            var session1 = new GameSession(player1s1, player2s1);
            var session2 = new GameSession(player1s2, player3s2);

            this.sessions = new List<IGameSession>();
            this.sessions.Add(session1);
            this.sessions.Add(session2);

            this.sessionServiceMock = new Mock<ISessionService>();
            this.sessionHistoryServiceMock = new Mock<ISessionHistoryService<TestMoveObject, TestResponseObject>>();
            this.notificationServiceMock = new Mock<INotificationService>();
        }
예제 #3
0
        public void UT_When_HandleMove_Then_Success()
        {
            var sessionName = "player1-vs-player2";
            var player1 = new TestSessionPlayer()
            {
                SessionName = sessionName,
                PendingToMove = false,
                Information = new User
                {
                    DisplayName = "Player 1",
                    Name = "player1"
                }
            };
            var player2 = new TestSessionPlayer()
            {
                SessionName = sessionName,
                PendingToMove = true,
                Information = new User
                {
                    DisplayName = "Player 2",
                    Name = "player2"
                }
            };
            var session = new GameSession(player1, player2);

            var testMoveObject = new TestMoveObject { Answer = "Test Answer" };
            var testMove = new TestMove(testMoveObject);

            var moveResponse = new TestResponse(new TestResponseObject { IsCorrect = true }) { IsWin = false };

            var sessionServiceMock = new Mock<ISessionService>();

            sessionServiceMock
                .Setup(s => s.GetByName(It.Is<string>(x => x == sessionName)))
                .Returns(session)
                .Verifiable();

            var moveProcessorMock = new Mock<IMoveProcessor<TestMoveObject, TestResponseObject>>();

            moveProcessorMock
                .Setup(p => p.Process(It.Is<SessionGamePlayer>(x => x == player2), It.Is<IGameMove<TestMoveObject>>(m => m == testMove)))
                .Returns(moveResponse)
                .Verifiable();

            this.moveService = new MoveService<TestMoveObject, TestResponseObject>(sessionServiceMock.Object, moveProcessorMock.Object);

            var response = this.moveService.Handle(sessionName, player1.Information.Name, testMove);

            sessionServiceMock.VerifyAll();
            moveProcessorMock.VerifyAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(moveResponse, response);
        }
예제 #4
0
        public void UT_When_AbandonSession_Then_Success()
        {
            var playerService = Mock.Of<IUserService>();
            var sessionRepository = new TestRepository<GameSession>();
            var sessionPlayerFactory = Mock.Of<ISessionPlayerFactory>();

            this.sessionService = new SessionService(playerService, sessionRepository, sessionPlayerFactory);

            var sessionPlayer1 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player1",
                    DisplayName = "Player 1"
                }
            };
            var sessionPlayer2 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player2",
                    DisplayName = "Player 2"
                }
            };
            var newSession = this.sessionService.Create(sessionPlayer1, sessionPlayer2);

            this.sessionService.Start(newSession);

            var startedSession = this.sessionService.GetByName(newSession.Name);

            this.sessionService.Abandon(startedSession.Name);

            var abandonedSession = this.sessionService.GetByName(newSession.Name);

            Assert.IsNotNull(abandonedSession);
            Assert.AreEqual(SessionState.Abandoned, abandonedSession.State);
            Assert.AreEqual("player1-vs-player2", abandonedSession.Name);
            Assert.IsTrue(abandonedSession.HasPlayer("player1"));
            Assert.IsTrue(abandonedSession.HasPlayer("player2"));
            Assert.AreEqual("player1", abandonedSession.GetVersusPlayer("player2").Information.Name);
            Assert.IsTrue(abandonedSession.Player1.IsReady);
            Assert.IsTrue(abandonedSession.Player1.PendingToMove);
            Assert.AreEqual("player1-vs-player2", abandonedSession.Player1.SessionName);
            Assert.IsTrue(abandonedSession.Player2.IsReady);
            Assert.IsFalse(abandonedSession.Player2.PendingToMove);
            Assert.AreEqual("player1-vs-player2", abandonedSession.Player2.SessionName);
        }
예제 #5
0
        public void UT_When_GetSessionsByPlayer_Then_Success()
        {
            var playerService = Mock.Of<IUserService>();
            var sessionRepository = new TestRepository<GameSession>();
            var sessionPlayerFactory = Mock.Of<ISessionPlayerFactory>();

            this.sessionService = new SessionService(playerService, sessionRepository, sessionPlayerFactory);

            var sessionPlayer1_1 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player1",
                    DisplayName = "Player 1"
                }
            };
            var sessionPlayer1_3 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player1",
                    DisplayName = "Player 1"
                }
            };
            var sessionPlayer1_4 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player1",
                    DisplayName = "Player 1"
                }
            };
            var sessionPlayer2 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player2",
                    DisplayName = "Player 2"
                }
            };
            var sessionPlayer3 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player3",
                    DisplayName = "Player 3"
                }
            };
            var sessionPlayer4 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player4",
                    DisplayName = "Player 4"
                }
            };
            var newSession1 = this.sessionService.Create(sessionPlayer1_1, sessionPlayer2);
            var newSession2 = this.sessionService.Create(sessionPlayer1_3, sessionPlayer3);
            var newSession3 = this.sessionService.Create(sessionPlayer1_4, sessionPlayer4);

            var newSessions = this.sessionService.GetAllByPlayer("player1");

            Assert.IsNotNull(newSessions);
            Assert.AreEqual(3, newSessions.Count());

            Assert.IsNotNull(newSession1);
            Assert.AreEqual("player1-vs-player2", newSession1.Name);
            Assert.AreEqual(SessionState.Pending, newSession1.State);
            Assert.IsTrue(newSession1.HasPlayer("player1"));
            Assert.IsTrue(newSession1.HasPlayer("player2"));
            Assert.AreEqual("player1", newSession1.GetVersusPlayer("player2").Information.Name);
            Assert.IsTrue(newSession1.Player1.IsReady);
            Assert.IsTrue(newSession1.Player1.PendingToMove);
            Assert.AreEqual("player1-vs-player2", newSession1.Player1.SessionName);
            Assert.IsTrue(newSession1.Player2.IsReady);
            Assert.IsFalse(newSession1.Player2.PendingToMove);
            Assert.AreEqual("player1-vs-player2", newSession1.Player2.SessionName);

            Assert.IsNotNull(newSession2);
            Assert.AreEqual("player1-vs-player3", newSession2.Name);
            Assert.AreEqual(SessionState.Pending, newSession2.State);
            Assert.IsTrue(newSession2.HasPlayer("player1"));
            Assert.IsTrue(newSession2.HasPlayer("player3"));
            Assert.AreEqual("player1", newSession2.GetVersusPlayer("player3").Information.Name);
            Assert.IsTrue(newSession2.Player1.IsReady);
            Assert.IsTrue(newSession2.Player1.PendingToMove);
            Assert.AreEqual("player1-vs-player3", newSession2.Player1.SessionName);
            Assert.IsTrue(newSession2.Player2.IsReady);
            Assert.IsFalse(newSession2.Player2.PendingToMove);
            Assert.AreEqual("player1-vs-player3", newSession2.Player2.SessionName);

            Assert.IsNotNull(newSession3);
            Assert.AreEqual("player1-vs-player4", newSession3.Name);
            Assert.AreEqual(SessionState.Pending, newSession3.State);
            Assert.IsTrue(newSession3.HasPlayer("player1"));
            Assert.IsTrue(newSession3.HasPlayer("player4"));
            Assert.AreEqual("player1", newSession3.GetVersusPlayer("player4").Information.Name);
            Assert.IsTrue(newSession3.Player1.IsReady);
            Assert.IsTrue(newSession3.Player1.PendingToMove);
            Assert.AreEqual("player1-vs-player4", newSession3.Player1.SessionName);
            Assert.IsTrue(newSession3.Player2.IsReady);
            Assert.IsFalse(newSession3.Player2.PendingToMove);
            Assert.AreEqual("player1-vs-player4", newSession3.Player2.SessionName);
        }
예제 #6
0
        public void UT_When_CreateSessionWithOnePlayer_Then_Success()
        {
            var gamePlayer = new User { Name = "player2", DisplayName = "Player 2" };
            var sessionPlayer2 = new TestSessionPlayer()
            {
                Information = gamePlayer
            };
            var playerServiceMock = new Mock<IUserService>();

            playerServiceMock
                .Setup(s => s.GetRandom(It.Is<string>(n => n == "player1")))
                .Returns(gamePlayer)
                .Verifiable();

            var playerService = playerServiceMock.Object;
            var sessionRepository = new TestRepository<GameSession>();

            var sessionPlayerFactoryMock = new Mock<ISessionPlayerFactory>();

            sessionPlayerFactoryMock
                .Setup(f => f.Create(It.Is<IUser>(p => p.Name == gamePlayer.Name)))
                .Returns(sessionPlayer2)
                .Verifiable();

            var sessionPlayerFactory = sessionPlayerFactoryMock.Object;

            this.sessionService = new SessionService(playerService, sessionRepository, sessionPlayerFactory);

            var sessionPlayer1 = new TestSessionPlayer()
            {
                Information = new User
                {
                    Name = "player1",
                    DisplayName = "Player 1"
                }
            };
            var newSession = this.sessionService.Create(sessionPlayer1);

            playerServiceMock.VerifyAll();
            sessionPlayerFactoryMock.VerifyAll();

            Assert.IsNotNull(newSession);
            Assert.AreEqual("player1-vs-player2", newSession.Name);
            Assert.AreEqual(SessionState.Pending, newSession.State);
            Assert.IsTrue(newSession.HasPlayer("player1"));
            Assert.IsTrue(newSession.HasPlayer("player2"));
            Assert.AreEqual("player1", newSession.GetVersusPlayer("player2").Information.Name);
            Assert.IsTrue(newSession.Player1.IsReady);
            Assert.IsTrue(newSession.Player1.PendingToMove);
            Assert.AreEqual("player1-vs-player2", newSession.Player1.SessionName);
            Assert.IsTrue(newSession.Player2.IsReady);
            Assert.IsFalse(newSession.Player2.PendingToMove);
            Assert.AreEqual("player1-vs-player2", newSession.Player2.SessionName);
        }