示例#1
0
        public void CreateGame_WhenCreateGameModelIsValid_ShouldAddGameToRepository()
        {
            Game newGame = new Game();
            CreateGameModel createGameModel = new CreateGameModel()
            {
                SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                Password = null,
                Title = "Title",
            };

            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {
                new User
                {
                    SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                    Nickname = "Kalinskia",
                    Username = "******",
                },
            }.AsQueryable());
            mock.Setup(u => u.Games.Add(It.IsAny<Game>())).Callback((Game game) => newGame = game);
            GameService gameservice = new GameService(mock.Object);
            gameservice.CreateGame(createGameModel);
            Assert.AreEqual("Title", newGame.Title);
            Assert.IsNull(newGame.Password);
            Assert.AreEqual("Title", newGame.Title);
            Assert.AreEqual("100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL", newGame.RedUser.SessionKey);
            Assert.AreEqual("Kalinskia", newGame.RedUser.Nickname);
            Assert.AreEqual("Kalin", newGame.RedUser.Username);
            Assert.AreEqual(9, newGame.MovesLeft);
            Assert.AreEqual("Open", newGame.GameStatus);
            Assert.IsNull(newGame.UserInTurn);
            Assert.IsNull(newGame.Winner);
            Assert.IsNull(newGame.BlueUser);
        }
示例#2
0
        public void CreateGame_WhenPasswordIsTooLong_ShouldThrowException()
        {
            GameService gameservice = new GameService(mock.Object);

            CreateGameModel createGameModel = new CreateGameModel()
            {
                SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                Password = "******",
                Title = "Title",
            };
            gameservice.CreateGame(createGameModel);
        }
示例#3
0
 public void CreateGame_WhenCreateGameModelIsNull_ShouldThrowException()
 {
     GameService gameservice = new GameService(mock.Object);
     gameservice.CreateGame(null);
 }
示例#4
0
 public void CreateGame_WhenSessionKeyIsInvalid_ShouldThrowException()
 {
     GameService gameservice = new GameService(mock.Object);
     CreateGameModel createGameModel = new CreateGameModel()
     {
         SessionKey = "InvalidSessionKey",
         Password = null,
         Title = "Title",
     };
     gameservice.CreateGame(createGameModel);
 }