public BookDeskResult BookDesk(BookDeskRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var isValid = IsValidRequest(request); var avaiableDesks = _deskRepository.GetAvailableDesks(request.Date); var result = Create <BookDeskResult>(request); if (avaiableDesks.FirstOrDefault() is Desk availableDesk) { var bookDesk = Create <BookDesk>(request); bookDesk.DeskId = availableDesk.Id; var bookingId = _repo.Save(bookDesk); result.ResultCode = DeskBookingResultCode.Success; result.BookingId = bookingId; } else { result.ResultCode = DeskBookingResultCode.NotAvailableDesks; } return(result); }
public void Init() { _request = new BookDeskRequest { FirstName = "Nir", LastName = "Weber", Email = "*****@*****.**", Date = new DateTime(2020, 02, 14) }; _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>(); _availableDesks = new List <Desk> { new Desk { Id = 7 } }; _deskRepositoryMock = new Mock <IDeskRepository>(); _deskRepositoryMock .Setup(t => t.GetAvailableDesks(It.IsAny <DateTime>())) .Returns(_availableDesks); _processor = new BookDeskService( _deskBookingRepositoryMock.Object, _deskRepositoryMock.Object); }
private T Create <T>(BookDeskRequest request) where T : BookDeskAbstract, new() { return(new T { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Date = request.Date }); }
private static T Create <T>(BookDeskRequest request) where T : DeskBookingBase, new() { return(new T { Date = request.Date, Email = request.Email, FirstName = request.FirstName, LastName = request.LastName }); }
public BookDeskRequestResult BookDesk(BookDeskRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var resultCode = DeskBookingResultCode.NoDeskAvailable; if (deskRepository.GetAvailableDesks(request.Date).FirstOrDefault() is Desk desk) { var booking = Create <DeskBooking>(request); booking.DeskId = desk.Id; deskBookingRepository.Save(booking); resultCode = DeskBookingResultCode.Success; } var result = Create <BookDeskRequestResult>(request); result.ResultCode = resultCode; return(result); }
public DeskBookingProcessorTests() { mockDeskBookingRepository = new Mock <IDeskBookingRepository>(); mockDeskRepository = new Mock <IDeskRepository>(); processor = new DeskBookingProcessor(mockDeskBookingRepository.Object, mockDeskRepository.Object); request = new BookDeskRequest() { FirstName = "Emem", LastName = "Isaac", Email = "*****@*****.**", Date = new DateTime(2021, 03, 08) }; availableDesks = new List <Desk> { new Desk { Id = 2 } }; mockDeskRepository.Setup(x => x.GetAvailableDesks(request.Date)).Returns(availableDesks); }
private bool IsValidRequest(BookDeskRequest request) => request.Email.Contains("@tipranks.com");