public void AddAllRestaurantsShouldThrowExceptionIfRestaurantListIsNull(bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddRestaurantTesting4DB")
                          .Options;
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.AddNewRestaurantsAsync(null, new List <string>()).Wait();
                    }
                    else
                    {
                        rRepo.AddNewRestaurants(null, new List <string>());
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
        public void AddAllRestaurantsShouldNotThrowExceptionIfKeywordListIsNull(bool useAsync)
        {
            //Arrange
            string dbName;

            if (useAsync)
            {
                dbName = "EmptyAddRestaurantAsyncTesting5DB";
            }
            else
            {
                dbName = "EmptyAddRestaurantTesting5DB";
            }
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;
            RestaurantRepo rRepo;
            bool           result = true;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    rRepo.AddNewRestaurantsAsync(new List <Restaurant>(), null).Wait();
                }
                else
                {
                    rRepo.AddNewRestaurants(new List <Restaurant>(), null);
                }
            }
            //Test will fail and not reach this point if Exception is thrown
            //Assert
            Assert.True(result);
        }
        public void AddAllRestaurantsShouldAddOnlyNewRestaurantsToDB(bool useAsync)
        {
            //Arrange
            string dbName;

            if (useAsync)
            {
                dbName = "EmptyAddRestaurantAsyncTesting7DB";
            }
            else
            {
                dbName = "EmptyAddRestaurantTesting7DB";
            }
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;
            RestaurantRepo    rRepo;
            List <Restaurant> resultList;

            using (var context = new Project2DBContext(options))
            {
                context.Restaurant.Add(new Restaurant {
                    Id = "1a", Name = "1", Lat = "loc", Lon = "loc", Owner = "realUser"
                });
                context.Restaurant.Add(new Restaurant {
                    Id = "6f", Name = "6", Lat = "loc", Lon = "loc"
                });
                context.Restaurant.Add(new Restaurant {
                    Id = "7g", Name = "7", Lat = "loc", Lon = "loc"
                });
                context.SaveChanges();
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);

                if (useAsync)
                {
                    rRepo.AddNewRestaurantsAsync(new List <Restaurant>()
                    {
                        new Restaurant {
                            Id = "1a", Name = "1", Lat = "loc", Lon = "loc", Owner = "realUser"
                        },
                        new Restaurant {
                            Id = "2b", Name = "2", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "3c", Name = "3", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "4d", Name = "4", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "5e", Name = "5", Lat = "loc", Lon = "loc", Owner = "realUser"
                        },
                        new Restaurant {
                            Id = "6f", Name = "6", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "7g", Name = "7", Lat = "loc", Lon = "loc"
                        }
                    }, new List <string>()).Wait();
                }
                else
                {
                    rRepo.AddNewRestaurants(new List <Restaurant>()
                    {
                        new Restaurant {
                            Id = "1a", Name = "1", Lat = "loc", Lon = "loc", Owner = "realUser"
                        },
                        new Restaurant {
                            Id = "2b", Name = "2", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "3c", Name = "3", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "4d", Name = "4", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "5e", Name = "5", Lat = "loc", Lon = "loc", Owner = "realUser"
                        },
                        new Restaurant {
                            Id = "6f", Name = "6", Lat = "loc", Lon = "loc"
                        },
                        new Restaurant {
                            Id = "7g", Name = "7", Lat = "loc", Lon = "loc"
                        }
                    }, new List <string>());
                }

                context.SaveChanges();
                resultList = context.Restaurant.AsNoTracking().ToList();
            }

            //Assert
            Assert.Equal(7, resultList.Count);
        }