public async Task <IActionResult> Hotel(string zipcode) { var client = new HttpClient(); var httpResponseLatLong = await client.GetAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={zipcode}&key=AIzaSyDDQ1uMLrSYDQtlX-VIFyyiXMB5_dRJNqU"); httpResponseLatLong.EnsureSuccessStatusCode(); var contentLatLong = await httpResponseLatLong.Content.ReadAsStringAsync(); var resultLatLong = JsonConvert.DeserializeObject <Rootobject>(contentLatLong); HotelResponse result = new HotelResponse(); if (resultLatLong != null && resultLatLong.results.Length > 0 && resultLatLong.results[0].geometry != null) { //string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={resultLatLong.results[0].geometry.location.lat}.1298305&radius=1500&type=lodging&keyword=hotels&key=%20AIzaSyAuKgJKHj3zOAMfx9bGAK8in1s4pYhl0JA"; var httpResponse = await client.GetAsync($"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={resultLatLong.results[0].geometry.location.lat},{resultLatLong.results[0].geometry.location.lng}&radius=5000&keyword=hotel&key=AIzaSyAuKgJKHj3zOAMfx9bGAK8in1s4pYhl0JA"); httpResponse.EnsureSuccessStatusCode(); var content = await httpResponse.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <HotelResponse>(content); } //ViewBag["result"] = result; return(View(result)); }
private HotelAvailabilityResponse SetMockedHotelAvailabilityResponse() { var response = new HotelAvailabilityResponse(); response.Count = 2; response.CheckIn = DateTime.Now.AddDays(30); response.CheckOut = DateTime.Now.AddDays(35); var availableHotels = new List <HotelResponse>(); var availableHotelFirst = new HotelResponse(); availableHotelFirst.Code = "01"; availableHotelFirst.AvailableRooms = new List <HotelAvailableRoom> { new HotelAvailableRoom { Id = 1, Code = "ROM_01", Price = 100 }, }; availableHotels.Add(availableHotelFirst); var availableHotelSecond = new HotelResponse(); availableHotelSecond.Code = "02"; availableHotelSecond.AvailableRooms = new List <HotelAvailableRoom> { new HotelAvailableRoom { Id = 3, Code = "ROM_03", Price = 150 }, }; availableHotels.Add(availableHotelSecond); response.AvailableHotels = availableHotels; return(response); }
public void GetHotelsTranslate() { HotelSearchByCityName hotelSearchByCity = new HotelSearchByCityName(); HotelResponse hotelResponse = hotelSearchByCity.GetHotels(); Assert.IsNull(hotelResponse.HotelStatus); Assert.IsNotNull(hotelResponse.Hotels); }
public void GetHotelsTestByCityName() { HotelSearchByCityName hotelSearchByCity = new HotelSearchByCityName(); hotelSearchByCity.CityName = "goa"; HotelResponse hotelResponse = hotelSearchByCity.GetHotels(); Assert.IsNull(hotelResponse.HotelStatus); Assert.IsNotNull(hotelResponse.Hotels); }
/// Returns HotelResponse object which contains hotels by city name search public HotelResponse GetHotels() { /* database code * HotelResponse hotelResponse = new HotelResponse(); * HotelOperations hotelOperations = new HotelOperations(); * try * { * ParseHotel hotelParse = new ParseHotel(); * hotelResponse.Hotels = hotelParse.Parse(hotelOperations.SearchByCity(CityName)); * * } * catch (Exception exception) * { * hotelResponse.HotelStatus.IsFailed = true; * hotelResponse.HotelStatus.Errors.Add(exception.ToString()); * } * return hotelResponse; */ //xml code //xml read and parse List <Task> tasks = new List <Task>(); HotelResponse hotelResponse = new HotelResponse(); SerializeOperaionsXML serializeOperaionsXML = new SerializeOperaionsXML(); SerializeJsonProvider2 serjson2 = new SerializeJsonProvider2(); TranslateHotel translateHotel = new TranslateHotel(); var xmlReadtask = Task.Run(() => serializeOperaionsXML.ReadXml()); tasks.Add(xmlReadtask); var jsonReadtask = Task.Run(() => serjson2.ReadJson()); tasks.Add(jsonReadtask); Console.WriteLine("waiting for 20 sec "); Task.WaitAll(tasks.ToArray(), 20000); if (tasks[tasks.IndexOf(xmlReadtask)].IsCompleted && !tasks[tasks.IndexOf(xmlReadtask)].IsFaulted) { hotelResponse.Hotels = translateHotel.XMLHotel(xmlReadtask.Result); } if (tasks[tasks.IndexOf(jsonReadtask)].IsCompleted && !tasks[tasks.IndexOf(jsonReadtask)].IsFaulted) { hotelResponse.Hotels.AddRange(translateHotel.JSONProviderTwoHotel(jsonReadtask.Result)); } return(hotelResponse); }
public void HotelFilterByRatingTests() { HotelSearchByCityName hotelSearchByCity = new HotelSearchByCityName(); hotelSearchByCity.CityName = "goa"; HotelResponse hotelResponse = hotelSearchByCity.GetHotels(); int count = hotelResponse.Hotels.Count; HotelFilters hotelFilter = new HotelFilters(); hotelFilter.FilterByRating(hotelResponse.Hotels, "4"); Assert.AreNotEqual(hotelResponse.Hotels.Count, count); }
public void When_MapHotelResponse() { // Arrange var subject = Mocker.CreateInstance <Mapper>(); var hotel = AutoFixture.Create <Hotel>(); var airlineResponse = new HotelResponse { Id = hotel.Id, Name = hotel.Name, Code = hotel.Code, Country = hotel.Country }; // Act var result = subject.Map(hotel); // Assert result.Should().BeEquivalentTo(airlineResponse); }
private void ReceiveHotelResponse(HotelResponse response) { PutResult(response); }