Ejemplo n.º 1
0
        public CreationOutput StartGame(int person1, int person2, int size)
        {
            CreationOutput output = new CreationOutput();

            if (person1 > 0 && person2 > 0 && person2 == person1 & size > 1)
            {
                output.Message = "Invalid Details";
                return(output);
            }
            if (!gamesService.IsGameValid(person1, person2))
            {
                output.Message = "Player is already playing";
                return(output);
            }
            GameStatus gameStatus = new GameStatus()
            {
                Person1     = person1,
                Person2     = person2,
                BoardSize   = size,
                Board       = new int[size, size],
                PlayerTurn  = person2,
                PlayerMoves = new Dictionary <int, List <Coordinate> >()
            };

            gameStatus.PlayerMoves.Add(person1, new List <Coordinate>());
            gameStatus.PlayerMoves.Add(person2, new List <Coordinate>());

            var guid = gamesService.AddGame(gameStatus);

            output.Message = "Game is started, GameId : " + guid;
            output.Guid    = guid;
            return(output);
        }
Ejemplo n.º 2
0
        public void AddGames_should_return_NameOfGame()
        {
            //arrange
            Games  games    = new Games();
            var    gam      = new GamesService(new XMLProvider <Games>("games.xml"));
            string name     = "games";
            var    expected = games.Name = "games";

            //act
            gam.AddGame(name);
            //assert
            Assert.Equal(expected, games.Name);
        }
Ejemplo n.º 3
0
        public void ChangeGame_should_return_NewNameOfStadium()
        {
            //arrange

            var gam = new GamesService(new XMLProvider <Games>("games.xml"));

            gam.AddGame("game");
            string name     = "game";
            int    index    = 0;
            string expected = "game";

            //act
            gam.ChangeGame(name, index);
            //assert
            Assert.Equal(expected, gam[index].Name);
        }
Ejemplo n.º 4
0
        public async Task AddGame_ShouldAddNewGameCorrectlyWithCorrectData()
        {
            var gamesRepoBuilder = new GameRepositoryBuilder();
            var gameRepo         = gamesRepoBuilder
                                   .WithAll()
                                   .Build();


            var levelsRepoBuilder = new LevelRepositoryBuilder();
            var levelRepo         = levelsRepoBuilder
                                    .WithAll()
                                    .Build();

            var sut = new GamesService(gameRepo, levelRepo, null, null, Mapper);

            var createGameModel = new CreateGameViewModel
            {
                Name        = "Haide na planina",
                Description = "planinaaaaaaaaa",
                Level1      = new CreateLevelViewModel
                {
                    Description = "level1Description", NumberInGame = 1, Points = 3, Image = SetupFileMock().Object
                },
                Level2 = new CreateLevelViewModel
                {
                    Description = "level2Description", NumberInGame = 2, Points = 5, Image = SetupFileMock().Object
                },
                Level3 = new CreateLevelViewModel
                {
                    Description = "level3Description", NumberInGame = 3, Points = 7, Image = SetupFileMock().Object
                }
            };

            var user = new GoUser {
                Id = "7"
            };

            await sut.AddGame(createGameModel, user);

            gamesRepoBuilder.GamesRepoMock.Verify(r => r.AddAsync(It.IsAny <Game>()), Times.Once);
            gamesRepoBuilder.GamesRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once);

            levelsRepoBuilder.LevelsRepoMock.Verify(r => r.AddAsync(It.IsAny <Level>()), Times.Exactly(3));
            levelsRepoBuilder.LevelsRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once);
        }
Ejemplo n.º 5
0
        public void NameofGame()
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Name\n1. Add name of the game\n2. Change name of the game\n0.  Back");
                Console.Write("Action: ");
                string choise = Console.ReadLine();
                Console.Clear();
                switch (choise)
                {
                case "0":
                    return;

                case "1":
                    try
                    {
                        Console.Write("Name of the game: ");
                        var name = validator.validator_name(Console.ReadLine());
                        ges.AddGame(name);
                    }
                    catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); }
                    break;

                case "2":
                    try
                    {
                        Console.WriteLine("Change name of game");
                        int index = IndexGames();
                        Console.WriteLine("Add new name of game");
                        string name = validator.validator_name(Console.ReadLine());
                        ges.ChangeGame(name, index);
                    }
                    catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); }
                    break;

                default:
                    Console.WriteLine("Wrong index\nPress any key to continue...");
                    Console.ReadKey();
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private List <ItemSyncResponse> SyncGames(SyncTransferObject transferObject,
                                                  List <ItemSyncResponse> syncedCategories, string userName)
        {
            var result = new List <ItemSyncResponse>();

            using (var transaction = GamesService.NewTransaction())
            {
                try
                {
                    transferObject.Games.ForEach(game =>
                    {
                        game.Categories = game.Categories
                                          .Select(c =>
                        {
                            if (long.TryParse(c.Id, out _))
                            {
                                var syncedCategory = syncedCategories
                                                     .FirstOrDefault(syncedCat => syncedCat.OfflineId.Equals(c.Id));
                                if (syncedCategory != null)
                                {
                                    c.Id = syncedCategory.Id.ToString();
                                }
                            }
                            return(c);
                        })
                                          .ToList();

                        switch (game.ModelState)
                        {
                        case Models.ModelState.New:
                            var newGame = GamesService.AddGame(Game.FromTransferObject(game), userName);
                            result.Add(new ItemSyncResponse
                            {
                                OfflineId   = game.Id,
                                Id          = newGame.Id,
                                State       = ItemState.Created,
                                Replacement = GameTransferObject.FromGame(newGame)
                            });
                            break;

                        case Models.ModelState.Modified:
                            var gameToUpdate = Game.FromTransferObject(game);
                            var updatedGame  = GamesService.UpdateGame(gameToUpdate, userName);
                            result.Add(new ItemSyncResponse
                            {
                                OfflineId   = game.Id,
                                Id          = gameToUpdate.Id,
                                State       = ItemState.Updated,
                                Replacement = GameTransferObject.FromGame(updatedGame)
                            });
                            break;

                        case Models.ModelState.Deleted:
                            var id = Guid.Parse(game.Id);
                            GamesService.DeleteGame(id);
                            result.Add(new ItemSyncResponse
                            {
                                Id        = id,
                                OfflineId = id.ToString(),
                                State     = ItemState.Deleted
                            });
                            break;
                        }
                    });
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
        public IActionResult AddGame([FromBody] GameDto gameDto)
        {
            var result = gamesService.AddGame(gameDto);

            return(result ? (IActionResult)Ok() : BadRequest());
        }