Exemplo n.º 1
0
        public IEnumerable <Beer> List()
        {
            var beerList = new List <Beer>();

            _context.Beers.ToList().ForEach(b => beerList.Add(BeerMapper.ToBeer(b)));
            return(beerList);
        }
Exemplo n.º 2
0
        public async Task <Beer> Get(int id)
        {
            var beer = await _context.Beers.FirstOrDefaultAsync(x => x.Id == id);

            var beerDTO = BeerMapper.ToBeer(beer);

            return(beerDTO);
        }
Exemplo n.º 3
0
        public async Task <Beer> Create(Beer beer)
        {
            beer.DrinkingTime = DateTime.Now;
            _context.Beers.Add(BeerMapper.ToDBBeer(beer));
            await _context.SaveChangesAsync();

            return(beer);
        }
Exemplo n.º 4
0
        public void MapBeerToDTO_ShouldReturnEmptyDTOIfFailed()
        {
            //Arrange
            //Act
            var sut = BeerMapper.MapBeerToDTO(null);

            //Assert
            Assert.AreEqual(sut.ID, null);
            Assert.AreEqual(sut.ABV, default);
            Assert.AreEqual(sut.Rating, default);
            Assert.AreEqual(sut.Country, null);
            Assert.AreEqual(sut.Brewery, null);
            Assert.AreEqual(sut.Style, null);
            Assert.AreEqual(sut.Reviews, null);
        }
Exemplo n.º 5
0
        public void MapDTOToBeer_ShouldReturnEmptyCountryIfFailed()
        {
            //Arrange
            //Act
            var sut = BeerMapper.MapDTOToBeer(null);

            //Assert
            Assert.AreEqual(sut.ID, null);
            Assert.AreEqual(sut.Name, null);
            Assert.AreEqual(sut.ABV, default);
            Assert.AreEqual(sut.Rating, default);
            Assert.AreEqual(sut.Country, null);
            Assert.AreEqual(sut.Brewery, null);
            Assert.AreEqual(sut.Style, null);
            Assert.AreEqual(sut.Reviews, null);
            Assert.AreEqual(sut.CreatedOn, default);
            Assert.AreEqual(sut.ModifiedOn, null);
            Assert.AreEqual(sut.DeletedOn, null);
            Assert.AreEqual(sut.IsDeleted, false);
        }
Exemplo n.º 6
0
 public async void Update(Beer beer)
 {
     _context.Beers.Update(BeerMapper.ToDBBeer(beer));
     await _context.SaveChangesAsync();
 }
Exemplo n.º 7
0
 public async void Delete(Beer beer)
 {
     _context.Beers.Remove(BeerMapper.ToDBBeer(beer));
     await _context.SaveChangesAsync();
 }