예제 #1
0
        public void CreateAsync_SavesToRepository_WhenValidDto()
        {
            var dto      = CreateModifyGameDto();
            var gameRoot = CreateGameRoots()[0];

            A.CallTo(() => _gameDecorator.FindSingleAsync(A <Expression <Func <GameRoot, bool> > > ._))
            .Returns((GameRoot)null);
            A.CallTo(() => _mapper.Map <GameRoot>(A <ModifyGameDto> ._)).Returns(gameRoot);

            _gameServices.CreateAsync(dto);

            A.CallTo(() => _gameDecorator.AddAsync(A <GameRoot> ._)).MustHaveHappenedOnceExactly();
        }
예제 #2
0
        public async Task CreateAsync(ModifyGameDto gameDto)
        {
            if (gameDto == null)
            {
                throw new InvalidServiceOperationException("Is null game dto");
            }

            if (string.IsNullOrWhiteSpace(gameDto.Key))
            {
                var name = gameDto.Localizations.First(localization => localization.CultureName == Culture.En).Name;
                gameDto.Key = await GenerateKeyAsync(name, KeySeparator);
            }
            else
            {
                await ValidateGameKeyExistingAsync(gameDto.Key);
            }

            var game = _mapper.Map <GameRoot>(gameDto);

            game.Details.CreationDate = DateTime.UtcNow;
            await _gameDecorator.AddAsync(game);

            await _unitOfWork.CommitAsync();
        }