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(); }
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(); }