Exemple #1
0
        private IEnumerable <Restaurant> GetRestaurantsAsync(RestaurantsQuery searchQuery)
        {
            var hotels         = new List <Restaurant>();
            var qnaMakerResult = new QnAMakerResult();
            var randomCount    = new Random();
            var count          = randomCount.Next(1, 5);

            // Filling the hotels results manually just for demo purposes
            for (int i = 1; i <= count; i++)
            {
                var random = new Random(i);
                qnaMakerResult = qnAmakerService.GetMessageFromQnAMaker("Restaurant " + random.Next(1, 5).ToString());
                Restaurant restaurant = new Restaurant()
                {
                    Name            = $"{searchQuery.PlaceName ?? searchQuery.Address} Restaurant {i}",
                    Location        = searchQuery.PlaceName ?? searchQuery.Address,
                    Rating          = random.Next(1, 5),
                    NumberOfReviews = random.Next(0, 5000),
                    PriceStarting   = random.Next(80, 450),
                    Image           = qnaMakerResult.answers.Count > 0 ? qnaMakerResult.answers[0].answer : string.Empty
                };

                hotels.Add(restaurant);
            }

            //hotels.Sort((h1, h2) => h1.PriceStarting.CompareTo(h2.PriceStarting));

            return(hotels);
        }
        public async Task Reserve(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            var message = await activity;

            contentType = message.Locale;

            await context.PostAsync(await translatorService.TranslatorExecute("en", contentType, $"Welcome to the Restaurant finder!"));

            // debug
            await context.PostAsync($"Translate to English: {message.Text}");


            var restaurantsQuery = new RestaurantsQuery();

            EntityRecommendation restaurantEntityRecommendation;

            if (result.TryFindEntity(EntityRestaurantPlan, out restaurantEntityRecommendation))
            {
                restaurantEntityRecommendation.Type = "PlaceName";
            }
            else if (result.TryFindEntity(EntityRestaurantName, out restaurantEntityRecommendation))
            {
                restaurantEntityRecommendation.Type = "PlaceName";
            }

            var restaurantsFormDialog = new FormDialog <RestaurantsQuery>(restaurantsQuery, BuildRestaurantsForm, FormOptions.PromptInStart, result.Entities);

            context.Call(restaurantsFormDialog, this.ResumeAfterRestaurantsFormDialog);
        }
Exemple #3
0
        public void ShouldNotPopulateForOneRestaurantDataOneInvalid()
        {
            string json = @"{
                'businesses' : [
                    {
                        'id': 'iG8DnZCnKHH_KYC8pG14NQ',
                        'alias': 'sublime-doughnuts-atlanta',
                        'name': 'Sublime Doughnuts',
                        'image_url': 'https://s3-media1.fl.yelpcdn.com/bphoto/O2oo77Iu6Q3EsN0E7g184w/o.jpg',
                        'is_closed': 'false',
                        'url': 'https://www.yelp.com/biz/sublime-doughnuts-atlanta?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw',
                        'review_count': '1167',
                        'categories': [
                        {
                            'alias': 'donuts',
                            'title': 'Donuts'
                        },
                        {
                            'alias': 'burgers',
                            'title': 'Burgers'
                        }
                        ],
                        'rating': '4.0',
                        'coordinates': {
                            'latitude': '33.78154',
                            'longitude': '-84.40513'
                        },
                        'transactions': [
                        'pickup',
                        'delivery'
                            ],
                        'location': {
                            'address1': '535 10th St NW',
                            'address2': '',
                            'address3': '',
                            'city': 'Atlanta',
                            'zip_code': '30318',
                            'country': 'US',
                            'state': 'GA',
                            'display_address': [
                            '535 10th St NW',
                            'Atlanta, GA 30318'
                                ]
                        },
                        'phone': '+14048971801',
                        'display_phone': '(404) 897-1801',
                        'distance': '4569.2202838849535'
                    }
                ]
            }";

            JObject firstRestaurant = JObject.Parse(json);
            JArray  restaurants     = (JArray)firstRestaurant.GetValue("businesses");

            var query = new RestaurantsQuery(new RestaurantFilters(), new RestaurantManager());

            RestaurantManager thePopulatedManager = query.PopulateRestaurants(restaurants);

            Assert.AreEqual("", thePopulatedManager.ToString());
        }
        public void ShouldAssembleQueryStringWithOneFilter()
        {
            RestaurantFilters theFilters = new RestaurantFilters();

            theFilters.AddLocation("Atlanta, GA");
            RestaurantsQuery theQuery = new RestaurantsQuery(theFilters, new RestaurantManager());

            Assert.AreEqual("https://api.yelp.com/v3/businesses/search?location=Atlanta, GA", theQuery.AssembleQueryString());
        }
Exemple #5
0
        public void ShouldReturnNullForInvalidQuery()
        {
            RestaurantFilters theFilters = new RestaurantFilters();

            theFilters.AddLocation("Atlanta");
            theFilters.AddRadius("5");
            RestaurantManager theManager = new RestaurantManager();
            RestaurantsQuery  theQuery   = new RestaurantsQuery(theFilters, theManager);

            Assert.AreEqual(null, theQuery.QueryRestaurants("Invalid Query"));
        }
        public void ShouldAssembleQueryStringWithManyFilters()
        {
            RestaurantFilters theFilters = new RestaurantFilters();

            theFilters.AddLocation("Atlanta, GA");
            theFilters.AddOpenNow("true");
            theFilters.AddRadius("8000");
            theFilters.AddPrice("1");
            RestaurantsQuery theQuery = new RestaurantsQuery(theFilters, new RestaurantManager());

            Assert.AreEqual("https://api.yelp.com/v3/businesses/search?location=Atlanta, GA&open_now=true&radius=8000&price=1", theQuery.AssembleQueryString());
        }
Exemple #7
0
        public void ShouldReturnResultsForValidFilters()
        {
            RestaurantFilters theFilters = new RestaurantFilters();

            theFilters.AddLocation("Atlanta");
            theFilters.AddRadius("8000");
            RestaurantManager theManager = new RestaurantManager();
            RestaurantsQuery  theQuery   = new RestaurantsQuery(theFilters, theManager);

            string queryString        = theQuery.AssembleQueryString();
            JArray queriedRestaurants = theQuery.QueryRestaurants(queryString);

            Assert.AreNotEqual(null, theManager = theQuery.PopulateRestaurants(queriedRestaurants));
            Assert.AreNotEqual(null, theManager.ToString());
            Assert.AreNotEqual("", theManager.ToString());
        }
        public void ShouldAssembleQueryStringWithoutFilters()
        {
            RestaurantsQuery theQuery = new RestaurantsQuery(new RestaurantFilters(), new RestaurantManager());

            Assert.AreEqual("https://api.yelp.com/v3/businesses/search?", theQuery.AssembleQueryString());
        }
Exemple #9
0
        public void ShouldPopulateForManyValidRestaurantData()
        {
            string json = @"{
                'businesses' : [
                    {
                        'id': 'iG8DnZCnKHH_KYC8pG14NQ',
                        'alias': 'sublime-doughnuts-atlanta',
                        'name': 'Sublime Doughnuts',
                        'image_url': 'https://s3-media1.fl.yelpcdn.com/bphoto/O2oo77Iu6Q3EsN0E7g184w/o.jpg',
                        'is_closed': 'false',
                        'url': 'https://www.yelp.com/biz/sublime-doughnuts-atlanta?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw',
                        'review_count': '1167',
                        'categories': [
                        {
                            'alias': 'donuts',
                            'title': 'Donuts'
                        },
                        {
                            'alias': 'burgers',
                            'title': 'Burgers'
                        }
                        ],
                        'rating': '4.0',
                        'coordinates': {
                            'latitude': '33.78154',
                            'longitude': '-84.40513'
                        },
                        'transactions': [
                        'pickup',
                        'delivery'
                         ],
                        'price': '$',
                        'location': {
                            'address1': '535 10th St NW',
                            'address2': '',
                            'address3': '',
                            'city': 'Atlanta',
                            'zip_code': '30318',
                            'country': 'US',
                            'state': 'GA',
                            'display_address': [
                            '535 10th St NW',
                            'Atlanta, GA 30318'
                                ]
                        },
                        'phone': '+14048971801',
                        'display_phone': '(404) 897-1801',
                        'distance': '4569.2202838849535'
                    }, 
                    {
                        'id': 'W2uLX3tc3YrhKKxEIPRmAw',
                        'alias': 'georgia-aquarium-atlanta',
                        'name': 'Georgia Aquarium',
                        'image_url': 'https://s3-media4.fl.yelpcdn.com/bphoto/gk6BdrATSGVv6Rk2Yjzscg/o.jpg',
                        'is_closed': 'false',
                        'url': 'https://www.yelp.com/biz/georgia-aquarium-atlanta?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw',
                        'review_count': '2684',
                        'categories': [
                            {
                                'alias': 'aquariums',
                                'title': 'Aquariums'
                            }
                        ],
                        'rating': '4.0',
                        'coordinates': {
                            'latitude': '33.7630463019815',
                            'longitude': '-84.3947916838531'
                        },
                        'transactions': [],
                        'price': '$$',
                        'location': {
                            'address1': '225 Baker St',
                            'address2': '',
                            'address3': '',
                            'city': 'Atlanta',
                            'zip_code': '30313',
                            'country': 'US',
                            'state': 'GA',
                            'display_address': [
                               '225 Baker St',
                               'Atlanta, GA 30313'
                            ]
                        },
                        'phone': '+14045814000',
                        'display_phone': '(404) 581-4000',
                        'distance': '5911.261033815513'
                    },
                    {
                        'id': 'ERoYrBHNmTEEChY3RGaOGQ',
                        'alias': 'egg-harbor-café-atlanta-3',
                        'name': 'Egg Harbor Café',
                        'image_url': 'https://s3-media2.fl.yelpcdn.com/bphoto/tCSCB3NnK6lBdSesFr1eXA/o.jpg',
                        'is_closed': 'false',
                        'url': 'https://www.yelp.com/biz/egg-harbor-caf%C3%A9-atlanta-3?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw',
                        'review_count': '783',
                        'categories': [
                            {
                                'alias': 'breakfast_brunch',
                                'title': 'Breakfast & Brunch'
                            },
                            {
                                'alias': 'gluten_free',
                                'title': 'Gluten-Free'
                            },
                            {
                                'alias': 'sandwiches',
                                'title': 'Sandwiches'
                            }
                        ],
                        'rating': '4.5',
                        'coordinates': {
                            'latitude': '33.8051032144595',
                            'longitude': '-84.3941098822784'
                        },
                        'transactions': [
                            'delivery'
                        ],
                        'price' : '$$$',
                        'location': {
                            'address1': '1820 Peachtree Road NW',
                            'address2': '',
                            'address3': '',
                            'city': 'Atlanta',
                            'zip_code': '30309',
                            'country': 'US',
                            'state': 'GA',
                            'display_address': [
                               '1820 Peachtree Road NW',
                               'Atlanta, GA 30309'
                            ]
                        },
                        'phone': '+14702251901',
                        'display_phone': '(470) 225-1901',
                        'distance': '2096.338243923308'
                    }
                ]
            }";

            JObject firstRestaurant = JObject.Parse(json);
            JArray  restaurants     = (JArray)firstRestaurant.GetValue("businesses");

            var query = new RestaurantsQuery(new RestaurantFilters(), new RestaurantManager());

            RestaurantManager thePopulatedManager = query.PopulateRestaurants(restaurants);

            Assert.AreEqual(
                "Restaurant (name: Sublime Doughnuts price: $ location: 535 10th St NW, Atlanta, GA 30318 hours:  distance: 4569.2202838849535 review score: 4 review count: 1167 menu URL: https://www.yelp.com/biz/sublime-doughnuts-atlanta?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw image URL: https://s3-media1.fl.yelpcdn.com/bphoto/O2oo77Iu6Q3EsN0E7g184w/o.jpg id: iG8DnZCnKHH_KYC8pG14NQ)\n" +
                "Restaurant (name: Georgia Aquarium price: $$ location: 225 Baker St, Atlanta, GA 30313 hours:  distance: 5911.261033815513 review score: 4 review count: 2684 menu URL: https://www.yelp.com/biz/georgia-aquarium-atlanta?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw image URL: https://s3-media4.fl.yelpcdn.com/bphoto/gk6BdrATSGVv6Rk2Yjzscg/o.jpg id: W2uLX3tc3YrhKKxEIPRmAw)\n" +
                "Restaurant (name: Egg Harbor Café price: $$$ location: 1820 Peachtree Road NW, Atlanta, GA 30309 hours:  distance: 2096.338243923308 review score: 4.5 review count: 783 menu URL: https://www.yelp.com/biz/egg-harbor-caf%C3%A9-atlanta-3?adjust_creative=I7CeCNvUlMowfnqP0AdBMw&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=I7CeCNvUlMowfnqP0AdBMw image URL: https://s3-media2.fl.yelpcdn.com/bphoto/tCSCB3NnK6lBdSesFr1eXA/o.jpg id: ERoYrBHNmTEEChY3RGaOGQ)\n",
                thePopulatedManager.ToString());
        }
Exemple #10
0
        public void ShouldNotPopulateIfDataIsNull()
        {
            RestaurantsQuery theQuery = new RestaurantsQuery(new RestaurantFilters(), new RestaurantManager());

            Assert.ThrowsException <ArgumentException>(() => theQuery.PopulateRestaurants(null));
        }