public async Task <HotelRoomSummary> GetHotelRoomById(long id) { var responseStream = await client.GetStreamAsync($"HotelRooms/{id}"); HotelRoomSummary result = await JsonSerializer.DeserializeAsync <HotelRoomSummary>(responseStream); return(result); }
public async Task <HotelRoomSummary> CreateHotelRoom(HotelRoomSummary hotelRoom) { using (var content = new StringContent(JsonSerializer.Serialize(hotelRoom), System.Text.Encoding.UTF8, "application/json")) { var response = await client.PostAsync("Hotel", content); if (response.StatusCode == System.Net.HttpStatusCode.Created) { var responseStream = await response.Content.ReadAsStreamAsync(); HotelRoomSummary result = await JsonSerializer.DeserializeAsync <HotelRoomSummary>(responseStream); return(result); } throw new Exception($"Failed to POST data: ({response.StatusCode})"); } }
public void Hotels_must_have_rooms_else_they_are_not_hotels() { var id = Guid.NewGuid(); var availability = new HotelAvailability(null, null, null); try { var rooms = new HotelRoomSummary(0, 0, 0); new Hotel(id, availability, rooms); } catch (HotelsMustHaveRooms hmr) { // if exception is thrown test passes return; } Assert.Fail("Hotels must have rooms invariant not enforced"); }