Beispiel #1
0
        public void GetOpenGames_WhenNoOpenGameInRepository_ShouldReturnEmptyListOfGamesModel()
        {
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {new User()
            {
                SessionKey="10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef",
                Id=1
            }}.AsQueryable());
            mock.Setup(g => g.Games.GetAll()).Returns(new Game[]
            {
                new Game()
                {
                    GameStatus="InProgress",
                    RedUserId=2,
                    Title="Title2",
                    RedUser=new User(){Nickname="Kalin"}
                }
            }.AsQueryable());

            GameService gameService = new GameService(mock.Object);
            IEnumerable<GameModel> openGames = gameService.GetOpenGames("10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef");
            Assert.AreEqual(0, openGames.Count());
        }
Beispiel #2
0
        public void GetOpenGames_WhenASingleOpenGameInRepository_ShouldReturnSingleGameModel()
        {
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {new User()
            {
                SessionKey="10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef",
                Id=1
            }}.AsQueryable());
            mock.Setup(g => g.Games.GetAll()).Returns(new Game[]
            {
                new Game()
                {
                    GameStatus="Open",
                    RedUserId=2,
                    Title="Title",
                    RedUser=new User(){Nickname="Kalin"}
                },
                 new Game()
                {
                    GameStatus="InProgress",
                    RedUserId=2,
                    Title="Title2",
                    RedUser=new User(){Nickname="Kalin"}
                }
            }.AsQueryable());

            GameService gameService = new GameService(mock.Object);
            IEnumerable<GameModel> openGames = gameService.GetOpenGames("10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef");
            Assert.AreEqual(openGames.Count(), 1);
            Assert.AreEqual("Kalin", openGames.FirstOrDefault().CreatorNickname);
            Assert.AreEqual("Title", openGames.FirstOrDefault().Title);
            Assert.AreEqual("Open", openGames.FirstOrDefault().Status);
        }