Esempio n. 1
0
        public async Task UpdateAsync(ModifyGameDto gameDto)
        {
            if (gameDto == null)
            {
                throw new InvalidServiceOperationException("Is null game dto");
            }

            var exist = await _gameDecorator.AnyAsync(g => g.Id == gameDto.Id);

            if (!exist)
            {
                throw new EntityNotFoundException <GameRoot>(gameDto.Id);
            }

            if (string.IsNullOrWhiteSpace(gameDto.Key))
            {
                var gameName = gameDto.Localizations
                               .FirstOrDefault(localization => localization.CultureName == Culture.En)?.Name;

                gameDto.Key = await GenerateKeyAsync(gameName, KeySeparator);
            }
            else
            {
                await ValidateGameKey(gameDto.Id, gameDto.Key);
            }

            var gameRoot = _mapper.Map <GameRoot>(gameDto);
            await _gameDecorator.UpdateAsync(gameRoot);

            await _unitOfWork.CommitAsync();
        }
Esempio n. 2
0
        public void UpdateAsync_CallsRepository_WhenValid()
        {
            var dto = CreateModifyGameDto();

            A.CallTo(() => _gameDecorator.AnyAsync(A <Expression <Func <GameRoot, bool> > > ._)).Returns(true);

            _gameServices.UpdateAsync(dto);

            A.CallTo(() => _gameDecorator.UpdateAsync(A <GameRoot> ._)).MustHaveHappenedOnceExactly();
        }