示例#1
0
        public async Task CreateBeer_WhenBeerIsValid_ReturnsNewlyInsertedBeer()
        {
            // Arrange
            using var unitOfWork = UnitOfWork;
            var beerToInsert = new Beer
            {
                Name      = "Lazy Hazy",
                CreatedAt = DateTime.UtcNow,
                UpdatedAt = DateTime.UtcNow,
                BreweryId = 1,
                BeerStyle = BeerStyle.NewEnglandIpa
            };

            // Act
            var beerId = await unitOfWork.BeerRepository.CreateBeerAsync(beerToInsert, CancellationTestToken);

            var insertedBeer = await unitOfWork.BeerRepository.GetBeerByIdAsync(beerId, CancellationTestToken);

            unitOfWork.Commit();

            insertedBeer.ShouldNotBeNull();
            insertedBeer.ShouldBeOfType <Beer>();
            insertedBeer.Brewery !.ShouldNotBeNull();
            insertedBeer.Brewery !.Address !.ShouldNotBeNull();
            insertedBeer.Brewery !.Beers.ShouldNotBeEmpty();
            insertedBeer.Brewery !.Beers.Count.ShouldBe(4);
            insertedBeer.Brewery !.Beers.ShouldContain(b => b.Id == insertedBeer.Id);
            insertedBeer.Brewery !.Beers.FirstOrDefault(b => b.Id == insertedBeer.Id)?.Name.ShouldBe(beerToInsert.Name);
        }
 public Beer GetBy(string name)
 {
     return(Beers.FirstOrDefault(e => e.Name == name));
 }
 public Beer GetBy(int beerId)
 {
     return(Beers.FirstOrDefault(e => e.BeerId == beerId));
 }
 public Beer GetBeerById(int id)
 {
     return(Beers.FirstOrDefault(b => b.BeerId == id));
 }