public void GetRestaurantByIDShouldReturnRestaurantWithMatchingId(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB")
                          .Options;

            Restaurant     r;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    r = rRepo.GetRestaurantByIDAsync(Id).Result;
                }
                else
                {
                    r = rRepo.GetRestaurantByID(Id);
                }
            }

            //Assert
            Assert.Equal(Id, r.Id);
        }
Beispiel #2
0
        public void CreateRestaurant()
        {
            //Arrange
            string Name         = "Colpan";
            string PhoneNumber  = "1234";
            string StreetNumber = "1";
            string Street       = "Rue des palais";
            string City         = "Bruxelles";
            string PostalCode   = "1000";


            //Act
            mockContext.Setup(u => u.Restaurants).Returns(mockSet.Object);
            service = new RestaurantRepo(mockContext.Object);
            var restoExpected = service.Create(resto);

            //Assert
            Assert.AreEqual(restoExpected.Name, Name);
            Assert.AreEqual(restoExpected.PhoneNumber, PhoneNumber);
            Assert.AreEqual(restoExpected.StreetNumber, StreetNumber);
            Assert.AreEqual(restoExpected.Street, Street);
            Assert.AreEqual(restoExpected.City, City);
            Assert.AreEqual(restoExpected.PostalCode, PostalCode);



            mockSet.Verify(u => u.Add(It.IsAny <Restaurant>()), Times.Once());
            mockContext.Verify(u => u.SaveChanges(), Times.Once());
        }
        public void AddRestrauntShouldAddCorrectRestauranttoDB(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddRestaurantTesting3DB")
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            RestaurantRepo rRepo;
            Restaurant     result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    rRepo.AddRestaurantAsync(r).Wait();
                }
                else
                {
                    rRepo.AddRestaurant(r);
                }
                result = context.Restaurant.Find(r.Id);
            }

            //Assert
            Assert.Equal(r, result);
        }
        public void DBContainsRestaurantShouldReturnFalseIfIfDBIsEmpty(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB3")
                          .Options;
            bool           result;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    result = rRepo.DBContainsRestaurantAsync(Id).Result;
                }
                else
                {
                    result = rRepo.DBContainsRestaurant(Id);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.False(result);
        }
        public void DBContainsRestaurantShouldReturnFalseIfRestaurantIdNotInDB(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB")
                          .Options;
            bool           result;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    result = rRepo.DBContainsRestaurantAsync(Id).Result;
                }
                else
                {
                    result = rRepo.DBContainsRestaurant(Id);
                }
            }
            //Assert
            Assert.False(result);
        }
        public void GetAll_AssertReturnType()
        {
            var service  = new RestaurantRepo(_moqContext.Object);
            var restById = service.GetAll();

            Assert.IsInstanceOfType(restById, typeof(IEnumerable <Restaurant>));
        }
        public void GetRestaurantsShouldNotThrowExceptionIfDBIsEmpty()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB1")
                          .Options;

            bool           result = true;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    rRepo.GetRestaurants();
                }
                catch
                {
                    result = false;
                }
            }
            //Assert
            Assert.True(result);
        }
Beispiel #8
0
        public void AddRestaurantToBlacklistShouldSucceedIfUserAndRestaurantAreValid(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            Blacklist      result;

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

            //Assert
            Assert.Equal(username, result.Username);
            Assert.Equal(rId, result.RestaurantId);
        }
        public void GetRestaurantByIDShouldNotThrowExceptionIfIdIsInDB(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB")
                          .Options;
            bool           result = true;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    rRepo.GetRestaurantByIDAsync(Id).Wait();
                }
                else
                {
                    rRepo.GetRestaurantByID(Id);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }
        public void AddRestaurantShouldThrowExceptionIfIdAlreadyInDB(string Id, bool useAsync)
        {
            //Arrange
            string dbName;

            if (useAsync)
            {
                dbName = "EmptyAddRestaurantAsyncTesting1DB";
            }
            else
            {
                dbName = "EmptyAddRestaurantTesting1DB";
            }
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: dbName)
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            Restaurant r2 = new Restaurant {
                Id = Id, Name = Id + " Diner", Lat = "loc", Lon = "loc"
            };
            RestaurantRepo rRepo;
            bool           result = false;

            using (var context = new Project2DBContext(options))
            {
                context.Restaurant.Add(r2);
                context.SaveChanges();
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.AddRestaurantAsync(r).Wait();
                    }
                    else
                    {
                        rRepo.AddRestaurant(r);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
        public void Add_PassedARestaurant_CallsRestaurantRepoAdd()
        {
            var service = new RestaurantRepo(_moqContext.Object);

            service.Add(r);

            _moqSet.Verify(m => m.Add(It.IsAny <Restaurant>()), Times.Once);
        }
        public void Add_PassedARestaurant_CallsContextSaveChanges()
        {
            var service = new RestaurantRepo(_moqContext.Object);

            service.Add(r);

            _moqContext.Verify(m => m.SaveChanges(), Times.Once);
        }
Beispiel #13
0
        public Manage(Form parent, RestaurantRepo repo)
        {
            form      = parent;
            this.repo = repo;
            InitializeComponent();
            var dt = new DataTable();

            dt.Columns.Add("Name");
            dt.Columns.Add("Last Vistited");
        }
        static void Main(string[] args)
        {
            var logger = NLog.LogManager.GetCurrentClassLogger();

            logger.Info("Starting up.");
            string input;

            RestaurantRepo repository  = new RestaurantRepo();
            RestaurantList restaurants = repository.GetRestaurants();

            if (restaurants.Count == 0)
            {
                logger.Warn("Empty restaurant list.  May be indicative of failure to read.");
            }

            Console.WriteLine("WELCOME TO PROJECT 0.");

            do
            {
                DisplayMenu();
                input = GetInput("PLEASE INPUT MENU OPTION. >");
                input = input.ToUpper();
                if (input == Commands.topThree)
                {
                    DisplayTopThree(restaurants);
                }
                else if (input == Commands.allRestaurants)
                {
                    DisplayAllRestaurants(restaurants);
                }
                else if (input == Commands.restaurantDetails)
                {
                    DisplayRestaurantDetails(restaurants);
                }
                else if (input == Commands.restaurantReviews)
                {
                    DisplayRestaurantReviews(restaurants);
                }
                else if (input == Commands.search)
                {
                    SearchRestaurants(restaurants);
                }
                else if (input == Commands.quit)
                {
                }
                else
                {
                    DisplayInvalidInput();
                }
            } while (input != Commands.quit);
            logger.Info("Program shutting down normally.");
        }
Beispiel #15
0
 public RestaurantsController()
 {
     restaurantRepo = new RestaurantRepo();
     restaurantsWeb = new List <RestaurantWeb>();
     reviewsWeb     = new List <ReviewWeb>();
     foreach (var restaurantLib in restaurantRepo.GetRestaurants())
     {
         restaurantsWeb.Add(new RestaurantWeb(restaurantLib));
     }
     foreach (var reviewLib in restaurantRepo.GetReviews())
     {
         reviewsWeb.Add(new ReviewWeb(reviewLib, new RestaurantWeb(reviewLib.restaurant)));
     }
 }
Beispiel #16
0
        public async Task <RestaurantObjects> UpdateRestaurantAsync(long ownerId, long restaurantId, string restaurantName, string restaurantDescription)
        {
            EmployersRestaurants currentConnection = await CheckEmployerRestaurantAsync(ownerId, restaurantId);

            RestaurantObjects currentRestaurant = currentConnection.TheRestaurant;

            currentRestaurant.Name        = restaurantName;
            currentRestaurant.Description = restaurantDescription;

            CheckTheLoggedInPerson();

            await RestaurantRepo.UpdateAsync(currentRestaurant, ModifierId);

            return(currentRestaurant);
        }
Beispiel #17
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);
        }
        public void GetRestaurantsShouldReturnAListWithProperNumberOfRestaurants()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB")
                          .Options;
            RestaurantRepo    rRepo;
            List <Restaurant> rList;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                rList = rRepo.GetRestaurants().ToList();
            }
            //Assert
            Assert.Equal(9, rList.Count);
        }
        static void Main(string[] args)
        {
            var restaurantRepo = new RestaurantRepo();
            var restaurants    = restaurantRepo.GetRestaurants();
            var input          = "";

            while (input.ToLower() != "end")
            {
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("Enter 'restaurants' to see Restaurants");
                Console.WriteLine("Enter 'highest rated' to see the highest rated restaurant");
                Console.WriteLine("Enter 'sorted' to see the sorted restaurants by name");
                Console.WriteLine("Enter 'end' to end program");

                input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    input = "";
                }

                if (input.ToLower() == "restaurants")
                {
                    foreach (var r in restaurants)
                    {
                        Console.WriteLine(r);
                    }
                }

                if (input.ToLower() == "highest rated")
                {
                    Console.WriteLine(restaurantRepo.GetTopRatedRestaurant());
                }

                if (input.ToLower() == "sorted")
                {
                    foreach (var r in HelperLibrary.SortRestaurantsByName(restaurants))
                    {
                        Console.WriteLine(r);
                    }
                }
            }
        }
        public void AddRestaurantShouldThrowExceptionIfLocationIsNull(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddRestaurantTesting2DB")
                          .Options;

            Restaurant r = new Restaurant {
                Id = Id, Name = Id + " Diner"
            };
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.AddRestaurantAsync(r).Wait();
                    }
                    else
                    {
                        rRepo.AddRestaurant(r);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Beispiel #21
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);
        }
Beispiel #22
0
        public void AddRestaurantToBlacklistShouldThrowExceptionIfRestaurantNotInDB(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddTesting3DB")
                          .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.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToBlacklist(username, rId, rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
        public void GetRestaurantByIDShouldThrowExceptionIfIdNotFound(string Id, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledRestaurantDB")
                          .Options;

            bool           result = false;
            RestaurantRepo rRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        rRepo.GetRestaurantByIDAsync(Id).Wait();
                    }
                    else
                    {
                        rRepo.GetRestaurantByID(Id);
                    }
                }
                catch (NotSupportedException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }
            //Assert
            Assert.True(result);
        }
Beispiel #24
0
        /// <summary>
        /// Iterates the dictionary that holds all of the scraped values
        /// saves the values into the database
        /// </summary>
        /// <param name="scrapedStorage"></param>
        public void IterateNodes(Dictionary <string, List <string> > scrapedStorage)
        {
            var newAddress = scrapedStorage["Address"].Select(x => new
            {
                SplitAddress = x.Split(new string[] { "<br>" }, StringSplitOptions.None)
            })
                             .Where(x => x.SplitAddress.Length == 2)
                             .Select(
                x =>
                new
            {
                CityStateZip = x.SplitAddress[1],
                Streets      = x.SplitAddress[0],
                PostalCode   = ScraperExtentions.ExtractPostalCode(x.SplitAddress[1])
            })
                             .ToList();

            ScrapedStorage["CityStateZip"].AddRange(newAddress.Select(x => x.CityStateZip));
            ScrapedStorage["Streets"].AddRange(newAddress.Select(x => x.Streets));
            ScrapedStorage["PostalCode"].AddRange(newAddress.Select(x => x.PostalCode));

            var results = ScrapedStorage["Name"].Zip8(ScrapedStorage["Category"],
                                                      ScrapedStorage["ImageAnchor"], ScrapedStorage["ImageLink"], ScrapedStorage["Phone"],
                                                      ScrapedStorage["CityStateZip"], ScrapedStorage["Streets"], ScrapedStorage["PostalCode"],
                                                      (n1, n2, n3, n4, n5, n6, n7, n8) => new Restaurant
            {
                Name    = n1, Category = n2, ImageReference = n3, ImageSource = n4, PhoneNumber = n5,
                Address = new Address
                {
                    CityStatePostal = n6, Street = n7, PostalCode = n8
                }
            });
            var repo = new RestaurantRepo();

            repo.InsertRestaurants(results);
            EmptyStorage(scrapedStorage);
        }
        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);
        }
Beispiel #27
0
        public async Task <Tuple <RestaurantObjects, EmployersRestaurants> > AddNewRestaurantAsync(long ownerId, string restaurantName, string restaurantDescription)
        {
            CheckTheLoggedInPerson();

            Employers currentEmployer = await CheckEmployerExistenceAsync(ownerId);

            RestaurantObjects restaurantItem = new RestaurantObjects
            {
                Name        = restaurantName,
                Description = restaurantDescription
            };

            await RestaurantRepo.AddAsync(restaurantItem, ModifierId);

            EmployersRestaurants item = new EmployersRestaurants
            {
                EmployerId   = currentEmployer.Id,
                RestaurantId = restaurantItem.Id
            };

            await EmployerRestaurantRepo.AddAsync(item, ModifierId);

            return(new Tuple <RestaurantObjects, EmployersRestaurants>(restaurantItem, item));
        }
Beispiel #28
0
 public async Task <RestaurantObjects> GetRestaurantAsync(long id)
 {
     return(await RestaurantRepo.FindById(id));
 }
Beispiel #29
0
 public AddNew(Form parent, RestaurantRepo repo)
 {
     this.parent = parent;
     this.repo   = repo;
     InitializeComponent();
 }
 public RestaurentService(RestaurantRepo RestaurantRepo)
 {
     _RestaurantRepo = RestaurantRepo;
 }