public async Task Filter_WhenCalled_ShouldReturnFilteredItems() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item3 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = false }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); await entityRepository.Add(item3); var found = entityRepository.Filter(x => x.Ready); found.Count().ShouldBe(2); }
public async Task Get_WhenItemDoesNotExist_ShouldReturnNull() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); var result = entityRepository.Get("not existing id"); result.ShouldBeNull(); }
public async Task Get_WhenItemExists_ShouldReturnItem() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); var found = entityRepository.Get(added.Id); found.Id.ShouldBe(added.Id); found.IsDeleted.ShouldBe(added.IsDeleted); found.Name.ShouldBe(added.Name); found.Ready.ShouldBe(added.Ready); }
private async Task <Unit> HandleAsync(CreateGame request, CancellationToken cancellationToken) { var game = Game.Create(request.Name); await _gamesRepository.Add(game, cancellationToken); await _unitOfWork.Save(default);
public async Task <CreateGameResult> Handle(CreateGameRequest request, CancellationToken cancellationToken) { Game newGame = Game.CreateNew(request.GameName); await _repo.Add(newGame.ToSnapshot()); return(new CreateGameResult { CreatorId = request.CreatorId, CreatorName = request.CreatorName, Name = newGame.Name, Id = newGame.Id }); }
public async Task GetReadyGames_WhenCalled_ShouldReturnReadyGames() { var repository = new GamesRepository(_dbContext); await repository.Add(new Game { Name = "Example game", CreatedBy = "user", Ready = true }); await repository.Add(new Game { Name = "Example game 1", CreatedBy = "user", Ready = false }); var found = repository.GetReadyGames(); found.Count().ShouldBe(1); var game = found.First(); game.Name.ShouldBe("Example game"); }
public async Task Delete_WhenItemIdIsProvided_ShouldDeleteItemFromDatabase() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); var deleted = await entityRepository.Delete(added.Id); var items = _dbContext.Games.ToList(); items.Count().ShouldBe(0); deleted.Name.ShouldBe(added.Name); deleted.IsDeleted.ShouldBe(added.IsDeleted); deleted.Ready.ShouldBe(added.Ready); }