public async Task <ActionResult <BookingsResponse> > GetHearingsByTypes([FromQuery(Name = "types")] List <int> types, [FromQuery] string cursor = DefaultCursor, [FromQuery] int limit = DefaultLimit, [FromQuery] DateTime?fromDate = null) { fromDate = fromDate ?? DateTime.UtcNow.Date; types = types ?? new List <int>(); if (!await ValidateCaseTypes(types)) { ModelState.AddModelError("Hearing types", "Invalid value for hearing types"); return(BadRequest(ModelState)); } var query = new GetBookingsByCaseTypesQuery(types) { Cursor = cursor == DefaultCursor ? null : cursor, Limit = limit, FromDate = fromDate.Value }; var result = await _queryHandler.Handle <GetBookingsByCaseTypesQuery, CursorPagedResult <VideoHearing, string> >(query); var mapper = new VideoHearingsToBookingsResponseMapper(); var response = new BookingsResponse { PrevPageUrl = BuildCursorPageUrl(cursor, limit, types), NextPageUrl = BuildCursorPageUrl(result.NextCursor, limit, types), NextCursor = result.NextCursor, Limit = limit, Hearings = mapper.MapHearingResponses(result) }; return(Ok(response)); }
public IActionResult Process(IFormFile file) { var bookings = String.Empty; using (var reader = new StreamReader(file.OpenReadStream())) { bookings = reader.ReadToEnd(); } Bookings bookingsResult = (Bookings)_bookingProcessor.ProcessBookingString(bookings); BookingsResponse response = (BookingsResponse)_bookingProcessor.ProcessBooking(bookingsResult); return(View(response)); }
private BookingsHearingResponse HearingInResponse(BookingsResponse response) { foreach (var pageInHearingsResponse in response.Hearings) { foreach (var hearing in pageInHearingsResponse.Hearings) { if (hearing.HearingId.Equals(_context.TestData.Hearing.Id)) { return(hearing); } } } throw new DataException("Expected hearing not found in the response."); }
public void ProcessRequestData_FiveRequestsThreeBookingsProcessed_Processed() { // Arrange string testData = "0900 1730\r\n2011-03-17 10:17:06\r\nEMP001\r\n2011-03-21 09:00 2\r\n2011-" + "03-16 12:34:56\r\nEMP002\r\n2011-03-21 09:00 2\r\n2011-03-16 09:28:23\r\nEMP003\r\n2011" + "-03-22 14:00 2\r\n2011-03-17 11:23:45\r\nEMP004\r\n2011-03-22 16:00 1\r\n2011-03-" + "15 17:29:12\r\nEMP005\r\n2011-03-21 16:00 3"; BookingProcessor bp = new BookingProcessor(); // Act Bookings bookingsResult = (Bookings)bp.ProcessBookingString(testData); BookingsResponse response = (BookingsResponse)bp.ProcessBooking(bookingsResult); // Assert List <BookingRequest> totalBookings = bookingsResult.BookingRequests as List <BookingRequest>; Assert.AreEqual(5, totalBookings.Count); Assert.AreEqual(3, response.Bookings.Count); }
public async Task Should_return_all_hearings_by_default_case_type() { var bookingDetailsResponse = CreateBookingDetailsResponse(); var bookingDetailsResponses = new List <BookingsHearingResponse> { bookingDetailsResponse }; var bookingsByDateResponses = new List <BookingsByDateResponse>() { new BookingsByDateResponse() { Hearings = bookingDetailsResponses, ScheduledDate = DateTime.UtcNow } }; const int LIMIT = HearingData.GET_HEARINGS_LIMIT; var bookingResponse = new BookingsResponse() { Hearings = bookingsByDateResponses, Limit = LIMIT }; BookingsApiClient .Setup( x => x.GetHearingsByTypesAsync(It.IsAny <IEnumerable <int> >(), It.IsAny <string>(), It.IsAny <int>())) .ReturnsAsync(bookingResponse); var response = await Controller.GetAllHearings(); response.Should().NotBeNull(); var result = (OkObjectResult)response; result.StatusCode.Should().Be((int)HttpStatusCode.OK); var responses = (List <BookingsHearingResponse>)result.Value; responses.Should().NotBeEmpty(); responses.Any(x => x.HearingName.Equals(bookingDetailsResponse.HearingName)).Should().BeTrue(); }
public Response ProcessBooking(Request request) { BookingsResponse processedBookings = null; Bookings bookings = request as Bookings; // Helper Dictionary used locally to check conflicts with other bookings List <Tuple <DateTime, DateTime> > bookingsReview = new List <Tuple <DateTime, DateTime> >(); // Timespan to help determine the opening time for a specified date TimeSpan tsOpening = new TimeSpan ( int.Parse(bookings.OpeningHour.Substring(0, 2)), int.Parse(bookings.OpeningHour.Substring(3, 2)), 0); // Timespan to help determine the closing time for a specified date TimeSpan tsClosing = new TimeSpan ( int.Parse(bookings.ClosingHour.Substring(0, 2)), int.Parse(bookings.ClosingHour.Substring(3, 2)), 0); // Filtering out bookings that are outside of business hours and ordering by // RequestTime and BookingTime List <BookingRequest> requests = bookings.BookingRequests .Where ( r => // Check BookingTime is >= to office opening time. r.BookingTime >= (r.BookingTime.Date.AddSeconds(1) + tsOpening).Subtract(new TimeSpan(0, 0, 1)) && // Check BookingTime is <= to office closing time. r.BookingTime <= (r.BookingTime.Date.AddSeconds(1) + tsClosing).Subtract(new TimeSpan(0, 0, 1)) && // Check booking finisth time is <= to office closing time. r.BookingTime.AddHours(r.NumberHours) <= (r.BookingTime.Date.AddSeconds(1) + tsClosing).Subtract(new TimeSpan(0, 0, 1)) ) .OrderBy(r => r.BookingTime) .ThenBy(r => r.RequestTime) .ToList(); processedBookings = new BookingsResponse { Bookings = new List <BookingEmployee>() }; // Eliminating bookings overlapping other bookings foreach (var req in requests) { bool acceptableBooking = true; BookingEmployee be = new BookingEmployee { Date = req.BookingTime.Date, EmployeeId = req.EmployeeId, StartTime = req.BookingTime, EndTime = req.BookingTime.AddHours(req.NumberHours) }; foreach (var br in bookingsReview) { if ( (be.Date == br.Item1.Date) && (be.StartTime >= br.Item1 && be.StartTime < br.Item2) ) { acceptableBooking = false; break; } } if (acceptableBooking) { bookingsReview.Add(new Tuple <DateTime, DateTime>(be.StartTime, be.EndTime)); processedBookings.Bookings.Add(be); } } return(processedBookings); }