Esempio n. 1
0
        public void AddRestaurantToFavoritesShouldSucceedIfUserAndRestaurantAreValid(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            Favorite       result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    uRepo.AddRestaurantToFavoritesAsync(username, rId, rRepo).Wait();
                }
                else
                {
                    uRepo.AddRestaurantToFavorites(username, rId, rRepo);
                }
                result = context.Favorite.Find(rId, username);
            }

            //Assert
            Assert.Equal(username, result.Username);
            Assert.Equal(rId, result.RestaurantId);
        }
Esempio n. 2
0
        public void AddRestaurantToFavoritesShouldThrowExceptionIfRestrauntAlreadyInUsersBlacklist(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddFavoritesTestingDB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            bool           result = false;

            using (var context = new Project2DBContext(options))
            {
                context.Favorite.Add(new Favorite {
                    Username = username, RestaurantId = rId
                });
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.AddRestaurantToFavoritesAsync(username, rId, rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToFavorites(username, rId, rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Esempio n. 3
0
        public void AddRestaurantToFavoritesShouldThrowExceptionIfUserNotInDB(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB9")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.AddRestaurantToFavoritesAsync(username, "literally anything", rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToFavorites(username, "literally anything", rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }