예제 #1
0
        public void StartGame_WhenUserIsNotCreator_ShouldThrowException()
        {
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {
                new User
                {
                    Id = 2,
                    Nickname = "creatorNickname",
                    Username = "******",
                    SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef",
                },
            }.AsQueryable());

            mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns(
                new Game()
                {
                    Password = null,
                    GameStatus = "Open",
                    RedUserId = 1,
                    Winner = new User(),
                    BlueUserId = 2,
                });
            GameService gameSerivce = new GameService(mock.Object);
            gameSerivce.StartGame("10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", 1);
        }
예제 #2
0
        public void StartGame_WhenStateIsFullAndUserIsCreator_ShouldUpdateGameState()
        {
            Game updatedGame = new Game();
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {
                new User
                {
                    Id = 1,
                    Nickname = "creatorNickname",
                    Username = "******",
                    SessionKey = "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef",
                },
            }.AsQueryable());

            mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns(
                new Game()
                {
                    Password = null,
                    GameStatus = "Full",
                    RedUserId = 1,
                    Winner = new User(),
                    BlueUserId = 2,
                });

            mock.Setup(u => u.Games.Update(It.IsAny<Game>())).Callback((Game game) => updatedGame = game);

            GameService gameSerivce = new GameService(mock.Object);
            gameSerivce.StartGame("10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef", 1);

            Assert.AreEqual("InProgress", updatedGame.GameStatus);
            Assert.IsTrue(updatedGame.UserInTurn == 1 || updatedGame.UserInTurn == 2);
        }