public void GetPatientNextBooking_GetsNextActiveBooking() { //arrange var booking = _fixture.Build <Order>() .With(o => o.Status, 0) .Create(); _context.Add(booking); _context.SaveChanges(); var expected = new GetNextBookingResponse { Id = booking.Id, StartTime = booking.StartTime, EndTime = booking.EndTime, DoctorId = booking.DoctorId }; //act var result = _bookingService.GetPatientNextBooking(booking.PatientId); //assert using (new AssertionScope()) { result.Should().BeEquivalentTo(expected); } }
public GetNextBookingResponse GetPatientNextBooking(long patientId) { if (!_context.Patient.Any(o => o.Id == patientId)) { throw new ArgumentException("Wrong patient id"); } if (!_context.Order.Any(o => o.PatientId == patientId) || !_context.Order.Any(o => o.PatientId == patientId && o.Status == 0)) { return(null); } var order = _context.Order .Where(o => o.PatientId == patientId && o.Status == 0) .OrderByDescending(x => x.StartTime) .FirstOrDefault(); var result = new GetNextBookingResponse() { Id = order.Id, StartTime = order.StartTime, EndTime = order.EndTime, DoctorId = order.DoctorId, Status = (OrderStatus)order.Status, }; return(result); }