Beispiel #1
0
        public void GetAnotherOpponentInGame_WhenUserIsRedUser_ShouldReturnBlueUser()
        {
            Mock<IUowData> mock = new Mock<IUowData>();
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {new User()
            {
                SessionKey="10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef",
                Id=1
            }}.AsQueryable());
            mock.Setup(g => g.Games.GetById(It.IsAny<int>())).Returns(
                  new Game()
                {
                    GameStatus = "InProgress",
                    RedUserId = 1,
                    BlueUserId = 2,
                    Title = "Title2",
                    RedUser = new User() { Id = 1, Nickname = "RedUser" },
                    BlueUser = new User() { Id = 2, Nickname = "BlueUser" },
                });

            BaseService baseService = new BaseService(mock.Object);
            User otherUser = baseService.GetAnotherOpponentInGame(1, "10043IOvy7N9Bn9BDAk2mtT7ZcYKtZbBpdp00ZoIpJikyIJtef");

            Assert.AreEqual(2, otherUser.Id);
        }
Beispiel #2
0
 public void GetGameById_WhenIdIsNegative_ShouldThrowException()
 {
     BaseService gameService = new BaseService(null);
     gameService.GetGameById(-5);
 }
Beispiel #3
0
 public void GetGameById_WhenIdIs2_ShouldReturnGameWithId2()
 {
     Mock<IUowData> mock = new Mock<IUowData>();
     mock.Setup(m => m.Games.GetById(2)).Returns(new Game
     {
         Id = 2
     });
     BaseService gameService = new BaseService(mock.Object);
     Game game = gameService.GetGameById(2);
     Assert.AreEqual(game.Id, 2);
 }
Beispiel #4
0
 public void GetUserBySessionKey_WhenValidSessionKey_ShouldReturnUser()
 {
     Mock<IUowData> mock = new Mock<IUowData>();
     mock.Setup(m => m.Users.GetAll()).Returns(new User[]
     {
         new User { SessionKey = "other" },
         new User { SessionKey = "other" },
         new User { SessionKey = "100448Sitruv4IfYOGRSp6PqmxNFYr11vvZKQpCcLzmWThbTI3" },
         new User { SessionKey = "other" },
     }.AsQueryable());
     BaseService userService = new BaseService(mock.Object);
     User user = userService.GetUserBySessionKey("100448Sitruv4IfYOGRSp6PqmxNFYr11vvZKQpCcLzmWThbTI3");
     Assert.AreEqual(user.SessionKey, "100448Sitruv4IfYOGRSp6PqmxNFYr11vvZKQpCcLzmWThbTI3");
 }
Beispiel #5
0
        public void GetUserBySessionKey_WhenValidSessionKeyButNoUsersWithHim_ShouldThrowException()
        {
            Mock<IUowData> mock = new Mock<IUowData>();
            mock.Setup(m => m.Users.GetAll()).Returns(new User[]
            {
                new User { SessionKey = "other" },
                new User { SessionKey = "other" },
                new User { SessionKey = "other" },
                new User { SessionKey = "other" },
            }.AsQueryable());

            BaseService userService = new BaseService(mock.Object);
            userService.GetUserBySessionKey("100448Sitruv4IfYOGRSp6PqmxNFYr11vvZKQpCcLzmWThbTI3");
        }
Beispiel #6
0
 public void GetGameById_WhenNoGameWithId2_ShouldThrowException()
 {
     Mock<IUowData> mock = new Mock<IUowData>();
     mock.Setup(m => m.Games.GetById(It.IsAny<int>())).Returns(default(Game));
     BaseService gameService = new BaseService(mock.Object);
     Game game = gameService.GetGameById(2);
 }