Esempio n. 1
0
        public async Task <HotelListVM> FetchAllHotels(DataSourceRequests req)
        {
            var response = new HotelListVM();

            response.Hotels = await _hotelRepository.FetchAllHotelsAsync(req);

            response.TotalRecords = response.Hotels.Count();
            return(response);
        }
Esempio n. 2
0
        public async Task <HttpResponseMessage> FetchAllHotelAsync(DataSourceRequests request)
        {
            if (RequestThrottler.IsThrottled(request.ApiKey))
            {
                return(Request.CreateResponse((HttpStatusCode)429, "Too many requests."));
            }

            var result = await _hotelService.FetchAllHotels(request);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Esempio n. 3
0
        public async Task TryGetHotels()
        {
            HotelService       _hotelService = new HotelService(new HotelRepository());
            DataSourceRequests req           = new DataSourceRequests
            {
                ApiKey = "TEST200",
                Sort   = "DESC"
            };

            var result = await _hotelService.FetchAllHotels(req);

            Assert.IsTrue(result.TotalRecords > 0);
        }
        public Task <List <Hotel> > FetchAllHotelsAsync(DataSourceRequests request = null)
        {
            IEnumerable <Hotel> result = this.GetHotels();

            if (request.Search != string.Empty)
            {
                result = result.Where(r => r.CITY.StartsWith(request.Search)).ToList();
            }

            if (request.Sort.ToUpper() == "DESC")
            {
                result = result.OrderByDescending(r => r.PRICE).ToList();
            }
            else
            {
                result = result.OrderBy(r => r.PRICE).ToList();
            }

            return(Task.FromResult(result.ToList()));
        }
Esempio n. 5
0
        public async Task SortByPriceLowToHigh()
        {
            bool               sorted        = false;
            HotelService       _hotelService = new HotelService(new HotelRepository());
            DataSourceRequests req           = new DataSourceRequests
            {
                ApiKey = "TESTASC",
                Sort   = "ASC"
            };

            var result = await _hotelService.FetchAllHotels(req);

            for (int i = 0; i < result.Hotels.Count - 1; i++)
            {
                if (result.Hotels[i].PRICE <= result.Hotels[i + 1].PRICE)
                {
                    sorted = true;
                }
            }

            Assert.IsTrue(sorted);
        }
Esempio n. 6
0
        public async Task TryGetAllHotelsInBangkokOnly()
        {
            int                hotelInBangkokCount = 0;
            HotelService       _hotelService       = new HotelService(new HotelRepository());
            DataSourceRequests req = new DataSourceRequests
            {
                ApiKey = "TESTASC",
                Search = "Bangkok",
                Sort   = "ASC"
            };

            var result = await _hotelService.FetchAllHotels(req);

            for (int i = 0; i < result.Hotels.Count; i++)
            {
                if (result.Hotels[i].CITY.Equals("Bangkok"))
                {
                    hotelInBangkokCount++;
                }
            }

            Assert.IsTrue(hotelInBangkokCount == result.TotalRecords);
        }