public void JsonHotelInformationResponse() { // Arrange string doc = File.ReadAllText(PathFor("HotelInformationResponse.json")); // Act JsonDeserializer jsonDeserializer = new JsonDeserializer { RootElement = "HotelInformationResponse" }; HotelInformationResponse output = jsonDeserializer.Deserialize <HotelInformationResponse>(new RestResponse { Content = Regex.Replace(doc, "") }); // Assert Assert.NotNull(output); Assert.That(output.HotelSummary.Name == "The Strand Palace"); Assert.NotNull(output.HotelDetails); Assert.That(output.HotelDetails.NumberOfRooms == 785); Assert.That(output.RoomTypes.RoomType.Any(roomType => roomType.RoomAmenities.RoomAmenity.Any(roomAmenity => roomAmenity.Amenity == "In-room safe (laptop compatible) "))); Assert.NotNull(output.HotelImages); Assert.NotNull(output.HotelSummary); Assert.NotNull(output.PropertyAmenities); Assert.NotNull(output.Suppliers); }
/// <summary> /// Fiddler URL Dump /// /// http://api.ean.com/ean-services/rs/hotel/v3/info?hotelId=164989&options=HOTEL_IMAGES&apiKey=ty7wujrv6jc2vbrm2cpnmear&cid=55505&minorRev=20¤cyCode=GBP&locale=en_GB&customerUserAgent=Mozilla%2F5.0%20%28Windows%20NT%206.2%3B%20WOW64%29%20AppleWebKit%2F537.17%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F24.0.1312.57%20Safari%2F537.17&customerSessionId=0ABAA843-0682-2391-3CC2-CF6F03393718&customerIpAddress=%3A%3A1 /// </summary> /// <param name="hotelInformationRequest"></param> /// <returns></returns> public override HotelInformationResponse GetHotelInformation(HotelInformationRequest hotelInformationRequest) { string path = PathFor("HotelInformationResponse.json"); string content = Regex.Replace(File.ReadAllText(path), ""); JsonDeserializer jsonDeserializer = new JsonDeserializer() { RootElement = "HotelInformationResponse" }; HotelInformationResponse hotelInformationResponse = jsonDeserializer.Deserialize <HotelInformationResponse>(new RestResponse() { Content = content }); return(hotelInformationResponse); }
public HotelContentRS MappingHotelInfo(HotelInformationResponse rawRs) { HotelContentRS rs = new HotelContentRS(); //EAN warning and error if (rawRs.EanWsError != null) { //error! something has happened rs.Errors = new List<WarningAndError>(); WarningAndError error = helper.GenerateWarningAndError(9001, rawRs.EanWsError); rs.Errors.Add(error); } else { rs.Hotels = new List<HDSInterfaces.Hotel>(); HDSInterfaces.Hotel hotel = new HDSInterfaces.Hotel(); hotel.HotelInfo = new HotelInformation(); hotel.HotelInfo.Id = rawRs.hotelId; //name and address if (rawRs.HotelSummary != null){ hotel.HotelInfo.Name = rawRs.HotelSummary.name; hotel.HotelInfo.Address = helper.GenerateHotelAddress(rawRs.HotelSummary); //rating if (rawRs.HotelSummary.hotelRatingSpecified) { hotel.HotelInfo.StarRating = rawRs.HotelSummary.hotelRating; } if (rawRs.HotelSummary.tripAdvisorRatingSpecified) { hotel.HotelInfo.TripAdvisorRating = rawRs.HotelSummary.tripAdvisorRating; } } //description and information if (rawRs.HotelDetails != null){ hotel.HotelInfo.HotelDescription = rawRs.HotelDetails.propertyDescription; hotel.HotelInfo.AreaInfo = rawRs.HotelDetails.areaInformation; hotel.HotelInfo.RoomInfo = rawRs.HotelDetails.roomInformation; hotel.HotelInfo.DrivingDirection = rawRs.HotelDetails.drivingDirections; hotel.HotelInfo.AdditionalInfo = rawRs.HotelDetails.propertyInformation; hotel.HotelInfo.PolicyInfo = new HotelPolicy{ PolicyDescription = rawRs.HotelDetails.hotelPolicy, CheckInInstruction = rawRs.HotelDetails.checkInInstructions, CheckInTime = rawRs.HotelDetails.checkInTime, CheckOutTime = rawRs.HotelDetails.checkOutTime, }; } //room info hotel.HotelInfo.RoomInfos = new List<RoomInfo>(); if (rawRs.RoomTypes != null) { if (rawRs.RoomTypes.size > 0){ foreach (Expedia.HotelShoppingServiceReference.RoomType roomType in rawRs.RoomTypes.RoomType){ RoomInfo room = new RoomInfo{ Id = roomType.roomTypeId, Code = roomType.roomCode, Name = roomType.description, Description = roomType.descriptionLong }; hotel.HotelInfo.RoomInfos.Add(room); } } } //amenitity hotel.HotelInfo.Amenities = new List<HDSInterfaces.Amenity>(); if (rawRs.PropertyAmenities != null){ if (rawRs.PropertyAmenities.size > 0){ foreach (PropertyAmenity rawAmenitity in rawRs.PropertyAmenities.PropertyAmenity){ HDSInterfaces.Amenity amenity = new Amenity { Id = rawAmenitity.amenityId, Description = rawAmenitity.amenity.Trim() }; hotel.HotelInfo.Amenities.Add(amenity); } } } //images hotel.HotelInfo.Images = new List<HDSInterfaces.HotelImage>(); if (rawRs.HotelImages != null){ if (rawRs.HotelImages.size > 0){ foreach (Expedia.HotelShoppingServiceReference.HotelImage rawImage in rawRs.HotelImages.HotelImage){ hotel.HotelInfo.Images.Add(helper.GenerateHotelImage(rawImage)); } } } rs.Hotels.Add(hotel); } return rs; }