public async Task UpdateAsync(Publisher entity) { var isSqlPublisher = await _sqlPublisherRepository.AnyAsync(p => p.Id == entity.Id); if (isSqlPublisher) { await _sqlPublisherRepository.UpdateAsync(entity); await UpdateLocalizationsAsync(entity.Localizations); return; } var mongoPublisher = await _mongoPublisherRepository.FindSingleAsync(p => p.Id == entity.Id); var mongoPublisherAsEntity = _mapper.Map <Publisher>(mongoPublisher); var shouldInsertToSql = !AreEqualPublishers(entity, mongoPublisherAsEntity); if (shouldInsertToSql) { await UpdateGameRootsAndInsert(entity); } else { var localizations = entity.Localizations.Where(localization => localization.CultureName != Culture.En); await UpdateLocalizationsAsync(localizations); } }
public void UpdateAsync_UpdatesExistingPublisher_WhenFound() { var publisher = GetPublisher(); A.CallTo(() => _sqlPublisherRepository.AnyAsync(A <Expression <Func <Publisher, bool> > > ._)).Returns(true); _publisherDecorator.UpdateAsync(publisher); A.CallTo(() => _sqlPublisherRepository.UpdateAsync(publisher)).MustHaveHappenedOnceExactly(); }
public async Task CreateAsync_ThrowsException_WhenExistsWithSameName() { var roleDto = CreateRoleDto(); A.CallTo(() => _roleRepository.AnyAsync(A <Expression <Func <Role, bool> > > ._)).Returns(true); Func <Task> action = async() => await _roleService.CreateAsync(roleDto); await action.Should().ThrowAsync <EntityExistsWithKeyValueException <Role> >(); }
public async Task CreateAsync_ThrowsException_WhenExistsWithSameName() { var testGenreDto = CreateTestGenreDto(GenreName); A.CallTo(() => _genresRepository.AnyAsync(A <Expression <Func <Genre, bool> > > ._)).Returns(true); Func <Task> action = async() => await _genreServices.CreateAsync(testGenreDto); await action.Should().ThrowAsync <EntityExistsWithKeyValueException <Genre> >() .WithMessage($"Entity Genre with Name : {GenreName} already exists."); }
public async Task CreateAsync_ThrowsException_WhenExistsWithSameName() { var testPlatformDto = CreateTestPlatformDto(PlatformName); A.CallTo(() => _platformsRepository.AnyAsync(A <Expression <Func <Platform, bool> > > ._)) .Returns(true); Func <Task> action = async() => await _platformService.CreateAsync(testPlatformDto); await action.Should().ThrowAsync <EntityExistsWithKeyValueException <Platform> >() .WithMessage($"Entity Platform with Name : {PlatformName} already exists."); }
public async Task UpdateAsync_ThrowsException_WhenNegativeQuantity() { var orderDetails = CreateOrderDetails(quantity: -1); var orderDetailsDto = CreateOrderDetailsDto(); A.CallTo(() => _mapper.Map <OrderDetails>(A <OrderDetailsDto> ._)).Returns(orderDetails); A.CallTo(() => _orderDetailsDecorator.AnyAsync(A <Expression <Func <OrderDetails, bool> > > ._)).Returns(true); Func <Task> action = async() => await _orderDetailsService.UpdateAsync(orderDetailsDto); await action.Should().ThrowAsync <ValidationException <OrderDetails> >().WithMessage("Is negative quantity"); }
public async Task DeleteAsync(string id) { var exist = await _roleRepository.AnyAsync(r => r.Id == id); if (!exist) { throw new EntityNotFoundException <Role>(id); } await _roleRepository.DeleteAsync(id); await _unitOfWork.CommitAsync(); }
public async Task DeleteAsync(string id) { var exists = await _genreRepository.AnyAsync(g => g.Id == id); if (!exists) { throw new EntityNotFoundException <Genre>(id); } await _genreRepository.DeleteAsync(id); await _unitOfWork.CommitAsync(); }
public void DeleteAsync_CallsRepository_WhenExists() { A.CallTo(() => _commentsRepository.AnyAsync(A <Expression <Func <Comment, bool> > > ._)).Returns(true); _commentServices.DeleteAsync(Id); A.CallTo(() => _commentsRepository.DeleteAsync(Id)).MustHaveHappenedOnceExactly(); }
public void AnyAsync_CallsSqlRepository_Always() { const bool expectedResult = true; A.CallTo(() => _sqlOrderRepository.AnyAsync(_testExpression)).Returns(expectedResult); var result = _orderDecorator.AnyAsync(_testExpression).Result; result.Should().Be(expectedResult); }
public void AnyAsync_ReturnsResultFromSqlRepository_Always() { const bool expectedResult = true; A.CallTo(() => _sqlGameRootRepository.AnyAsync(A <Expression <Func <GameRoot, bool> > > ._)) .Returns(expectedResult); var any = _gameDecorator.AnyAsync(g => true).Result; any.Should().Be(expectedResult); }
public async Task DeleteAsync(string id) { var exists = await _commentsRepository.AnyAsync(c => c.Id == id); if (!exists) { throw new EntityNotFoundException <Comment>(id); } await _commentsRepository.DeleteAsync(id); await _unitOfWork.CommitAsync(); }
public async Task DeleteAsync(string id) { var exist = await _gameImageRepository.AnyAsync(gameImage => gameImage.Id == id); if (!exist) { throw new EntityNotFoundException <GameImage>(id); } await _gameImageRepository.DeleteAsync(id); await _unitOfWork.CommitAsync(); }
public async Task <User> CreateAsync(User user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (await _userRepository.AnyAsync(x => x.Username == user.Username)) { throw new AppException("Username '" + user.Username + "' is already taken"); } byte[] passwordHash, passwordSalt; HashHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; await _userRepository.AddAsync(user); return(user); }
public async Task UpdateAsync(OrderDetailsDto orderDetailsDto) { if (orderDetailsDto == null) { throw new InvalidServiceOperationException("Is null dto"); } var exists = await _orderDetailsDecorator.AnyAsync(od => od.Id == orderDetailsDto.Id); if (!exists) { throw new EntityNotFoundException <OrderDetails>(orderDetailsDto.Id); } var details = _mapper.Map <OrderDetails>(orderDetailsDto); if (details.Quantity == 0) { await _orderDetailsDecorator.DeleteAsync(details.Id); await _unitOfWork.CommitAsync(); return; } await ValidateQuantityAsync(details); var game = await _gameService.GetByIdAsync(orderDetailsDto.GameId); details.Price = game.Price; details.Discount = game.Discount; await _orderDetailsDecorator.UpdateAsync(details); await _unitOfWork.CommitAsync(); }
public async Task UpdateAsync(OrderDto orderDto) { var exist = await _orderDecorator.AnyAsync(o => o.Id == orderDto.Id); if (!exist) { throw new EntityNotFoundException <Order>(orderDto.Id); } var order = _mapper.Map <Order>(orderDto); _mapper.Map(orderDto.Shipment, order); await _orderDecorator.UpdateAsync(order); await _unitOfWork.CommitAsync(); }
public async Task <bool> AnyAsync(Expression <Func <OrderDetails, bool> > predicate) { var any = await _orderDetailsRepository.AnyAsync(predicate); return(any); }
public async Task <bool> HasActivePoll() { return(await _policyRepository.AnyAsync(new ActivePollPolicySpecification())); }
public async Task <bool> UserVotedInPoll(string userId, long pollId) { var result = await _voteRepository.AnyAsync(new VoteFilterByUserPollSpecification(userId, pollId)); return(result); }
public async Task <bool> AnyAsync(Expression <Func <GameRoot, bool> > predicate) { var any = await _sqlGameRootRepository.AnyAsync(predicate); return(any); }