示例#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 CreateGameAndNotifyOthersClients(CreateGameModel createGameModel)
        {
            try
            {
            GameServise.CreateGame(createGameModel);

            Clients.Others.createdNewGame();
            }
             catch (ServerErrorException ex)
             {
                 Clients.Caller.serverErrorException(ex.Message);
             }
        }
示例#3
0
 public void CreateGame(CreateGameModel gameModel)
 {
     //TODO: Validate Title
     if(gameModel==null)
     {
         throw new ArgumentNullException("CreateGameModel is null");
     }
     ValidateGamePassword(gameModel.Password);
     User redUser = GetUserBySessionKey(gameModel.SessionKey);
     Game game = new Game()
     {
         Title = gameModel.Title,
         Password = gameModel.Password,
         RedUser = redUser,
         GameStatus = GameStatusType.Open,
         MovesLeft = 9
     };
     this.Data.Games.Add(game);
     this.Data.SaveChanges();
 }
示例#4
0
        public void CreateGame_WhenPasswordIsTooLong_ShouldThrowException()
        {
            GameService gameservice = new GameService(mock.Object);

            CreateGameModel createGameModel = new CreateGameModel()
            {
                SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                Password = "******",
                Title = "Title",
            };
            gameservice.CreateGame(createGameModel);
        }
示例#5
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);
 }