Esempio n. 1
0
        public async Task UpdateAsync_ShouldChangeNameAndCountryOfBreweryAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldChangeNameOfBreweryAsync");

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

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

                var dbresult = await context.Breweries.Include(b => b.Country).FirstOrDefaultAsync(b => b.ID == 1);

                //Assert
                Assert.AreEqual(dbresult.Name, "Brewery2");
                Assert.AreEqual(dbresult.Country.Name, "Belgium");
            }
        }
Esempio n. 2
0
        public async Task UpdateAsync_ShouldReturnNullIfBreweryDTONullAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldReturnNullIfBreweryDTONullAsync");

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

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

                //Assert
                Assert.AreEqual(result, null);
            }
        }
Esempio n. 3
0
        public async Task UpdateAsync_ShouldReturnNullIfBreweryNonExistantAsync()
        {
            //Arrange
            var options = InMemory.GetOptions("UpdateAsync_ShouldReturnNullIfBreweryNonExistantAsync");

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

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

                //Assert
                Assert.AreEqual(result, null);
            }
        }