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);
        }
        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.");
        }
예제 #3
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)));
     }
 }
        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);
                    }
                }
            }
        }