Exemplo n.º 1
0
        public async Task DeleteAsync_ShouldReturnTrueIfBrewerySucceded()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueIfBrewerySucceded");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name = "Brewery"
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BreweryServices(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, true);
            }
        }
Exemplo n.º 2
0
        public async Task DeleteAsync_ShouldReturnFalseIfBreweryDoesntExistAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldReturnFalseIfBreweryDoesntExistAsync");

            using (var context = new BOContext(options))
            {
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut    = new BreweryServices(context);
                var result = await sut.DeleteAsync(1);

                //Assert
                Assert.AreEqual(result, false);
            }
        }
Exemplo n.º 3
0
        public async Task DeleteAsync_ShouldDeleteBreweryIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteBreweryIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name = "Brewery"
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                //Act
                var sut = new BreweryServices(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.Breweries.FirstOrDefaultAsync(c => c.Name == "Brewery");

                //Assert
                Assert.AreEqual(dbresult.Name, "Brewery");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
            }
        }
Exemplo n.º 4
0
        public async Task DeleteAsync_ShouldDeleteRecordBeersIfExist()
        {
            //Arrange
            var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteRecordBeersIfExist");

            using (var context = new BOContext(options))
            {
                var country = new Country()
                {
                    Name      = "Bulgaria",
                    DeletedOn = DateTime.UtcNow,
                    IsDeleted = true,
                    Breweries = new List <Brewery>()
                    {
                        new Brewery()
                        {
                            Name      = "Brewery",
                            DeletedOn = DateTime.UtcNow,
                            IsDeleted = true,
                        }
                    }
                };
                context.Countries.Add(country);
                await context.SaveChangesAsync();

                var beer = new Beer()
                {
                    Name      = "Carlsberg",
                    ABV       = 5,
                    Country   = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria"),
                    Brewery   = await context.Breweries.FirstOrDefaultAsync(b => b.Name == "Brewery"),
                    DeletedOn = DateTime.UtcNow,
                    IsDeleted = true,
                    Style     = new BeerStyle()
                    {
                        Name        = "Ale",
                        Description = "Some description"
                    },
                    Rating = 5
                };
                context.Beers.Add(beer);
                await context.SaveChangesAsync();
            }

            using (var context = new BOContext(options))
            {
                var breweryDTO = new BreweryDTO()
                {
                    Name    = "Brewery",
                    Country = "Bulgaria"
                };
                //Act
                var sut = new BreweryServices(context);
                await sut.DeleteAsync(1);

                var dbresult = await context.Breweries.FirstOrDefaultAsync(c => c.Name == "Brewery");

                var dbBeerResult = await context.Beers
                                   .Include(b => b.Style)
                                   .Include(b => b.Reviews)
                                   .Include(b => b.Country)
                                   .Include(b => b.WishLists)
                                   .Include(b => b.DrankLists)
                                   .FirstOrDefaultAsync(b => b.Name == "Carlsberg");

                //Assert
                Assert.AreEqual(dbresult.Name, "Brewery");
                Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn);
                Assert.AreEqual(dbresult.IsDeleted, true);
                Assert.AreEqual(dbBeerResult.Name, "Carlsberg");
                Assert.AreEqual(dbBeerResult.DeletedOn, dbBeerResult.ModifiedOn);
                Assert.AreEqual(dbBeerResult.IsDeleted, true);
            }
        }