Esempio n. 1
0
        /// <summary>
        /// Edits a <see cref="Game"/> entity in the data store.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity containing data to add to the data store.</param>
        /// <param name="oldGame">The <see cref="Game"/> entity containing data to remove from the data store.</param>
        public void EditGame(Game newGame, Game oldGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(EditGame)}: {nameof(newGame)}");
            Guard.ThrowIfNull(oldGame, $"{GetType()}.{nameof(EditGame)}: {nameof(oldGame)}");

            var selectedGame = _gameRepository.GetGame(oldGame.ID);

            if (selectedGame is null)
            {
                throw new EntityNotFoundException(
                          $"{GetType()}.{nameof(EditGame)}: The selected Game entity could not be found.");
            }

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            var selectedGameDecorator = new GameDecorator(selectedGame);

            selectedGameDecorator.Edit(newGameDecorator);

            _gameRepository.Update(selectedGame);

            var oldGameDecorator = new GameDecorator(oldGame);

            EditTeams(Direction.Down, oldGameDecorator);
            EditTeams(Direction.Up, newGameDecorator);

            _sharedRepository.SaveChanges();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a <see cref="Game"/> entity to the data store asynchronously.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity to add to the data store.</param>
        public async Task AddGameAsync(Game newGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(AddGameAsync)}: {nameof(newGame)}");

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            await _gameRepository.AddAsync(newGame);

            await EditTeamsAsync(Direction.Up, newGameDecorator);

            await _sharedRepository.SaveChangesAsync();
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a <see cref="Game"/> entity to the data store.
        /// </summary>
        /// <param name="newGame">The <see cref="Game"/> entity to add to the data store.</param>
        public void AddGame(Game newGame)
        {
            Guard.ThrowIfNull(newGame, $"{GetType()}.{nameof(AddGame)}: {nameof(newGame)}");

            var newGameDecorator = new GameDecorator(newGame);

            newGameDecorator.DecideWinnerAndLoser();

            _gameRepository.Add(newGame);

            EditTeams(Direction.Up, newGameDecorator);

            _sharedRepository.SaveChanges();
        }
Esempio n. 4
0
        public override void TestShift()
        {
            Game          game      = Game.Create(initialValues);
            GameDecorator decorator = (GameDecorator)game.Shift(1);

            Assert.AreEqual(0, game[0, 0]);
            Assert.AreEqual(1, game[1, 0]);
            Assert.AreEqual(new Point(0, 0), game.GetLocation(0));
            Assert.AreEqual(new Point(1, 0), game.GetLocation(1));

            Assert.AreEqual(1, decorator[0, 0]);
            Assert.AreEqual(0, decorator[1, 0]);
            Assert.AreEqual(new Point(0, 0), decorator.GetLocation(1));
            Assert.AreEqual(new Point(1, 0), decorator.GetLocation(0));
        }
Esempio n. 5
0
        private async Task EditTeamsAsync(Direction direction, GameDecorator gameDecorator)
        {
            var processGameStrategy = _processGameStrategyFactory.CreateStrategy(direction);

            // TODO - 2020-09-25: Implement ObjectNotFoundException class so it can be caught and used here.
            //try
            //{
            await processGameStrategy.ProcessGameAsync(gameDecorator);

            //}
            //catch (ObjectNotFoundException ex)
            //{
            //    Log.Error("ObjectNotFoundException in GamesService.EditTeams: " + ex.Message);
            //    _sharedService.ShowExceptionMessage(ex, "ObjectNotFoundException");
            //}
        }
Esempio n. 6
0
        /// <summary>
        /// Deletes a <see cref="Game"/> entity from the data store.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Game"/> entity to delete.</param>
        public void DeleteGame(int id)
        {
            var oldGame = _gameRepository.GetGame(id);

            if (oldGame is null)
            {
                throw new EntityNotFoundException(
                          $"{GetType()}.{nameof(DeleteGame)}: A Game entity with ID={id} could not be found.");
            }

            var oldGameDecorator = new GameDecorator(oldGame);

            EditTeams(Direction.Down, oldGameDecorator);
            _gameRepository.Delete(id);
            _sharedRepository.SaveChanges();
        }
Esempio n. 7
0
        /// <summary>
        /// Deletes a <see cref="Game"/> entity from the data store asynchronously.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Game"/> entity to delete.</param>
        public async Task DeleteGameAsync(int id)
        {
            var oldGame = await _gameRepository.GetGameAsync(id);

            if (oldGame is null)
            {
                throw new EntityNotFoundException(
                          $"{GetType()}.{nameof(DeleteGameAsync)}: A Game entity with ID={id} could not be found.");
            }

            var oldGameDecorator = new GameDecorator(oldGame);

            await EditTeamsAsync(Direction.Down, oldGameDecorator);

            await _gameRepository.DeleteAsync(id);

            await _sharedRepository.SaveChangesAsync();
        }
Esempio n. 8
0
        public void Setup()
        {
            _sqlGameRootRepository      = A.Fake <IAsyncRepository <GameRoot> >();
            _publisherDecorator         = A.Fake <IPublisherDecorator>();
            _productRepository          = A.Fake <IProductRepository>();
            _gameDetailsRepository      = A.Fake <IAsyncRepository <GameDetails> >();
            _gameLocalizationRepository = A.Fake <IAsyncRepository <GameLocalization> >();
            _gameRootAggregator         = A.Fake <IAggregator <GameFilterData, IEnumerable <GameRoot> > >();
            _mapper = A.Fake <IMapper>();

            _gameDecorator = new GameDecorator(
                _sqlGameRootRepository,
                _publisherDecorator,
                _productRepository,
                _gameRootAggregator,
                _gameDetailsRepository,
                _gameLocalizationRepository,
                _mapper);
        }
Esempio n. 9
0
        public void Shift_ExistingValue_TilesMoved()
        {
            List <int> sequenceOfNumbers = new List <int>()
            {
                1, 6, 3, 4, 5, 7, 8, 2, 0
            };
            ImmutableGame game      = new ImmutableGame(sequenceOfNumbers);
            IGame         decorator = new GameDecorator(game);

            decorator.Shift(2);
            List <int> newSequenceOfNumbers = new List <int>()
            {
                1, 6, 3, 4, 5, 7, 8, 0, 2
            };
            List <int> newSequenceOfNumbersInDecorator = new List <int>();
            List <int> newSequenceOfNumbersInOldGame   = new List <int>();

            foreach (var valueTile in game.Tiles)
            {
                newSequenceOfNumbersInOldGame.Add(valueTile);
            }
            foreach (var valueTile in decorator.Tiles)
            {
                newSequenceOfNumbersInDecorator.Add(valueTile);
            }
            for (int i = 0; i < sequenceOfNumbers.Count; i++)
            {
                Assert.AreEqual(newSequenceOfNumbers[i], newSequenceOfNumbersInDecorator[i]);
            }

            for (int i = 0; i < sequenceOfNumbers.Count; i++)
            {
                if (i != 7 && i != 8)
                {
                    Assert.AreEqual(newSequenceOfNumbers[i], newSequenceOfNumbersInOldGame[i]);
                }
                else
                {
                    Assert.AreNotEqual(newSequenceOfNumbers[i], newSequenceOfNumbersInOldGame[i]);
                }
            }
        }