public async Task book_appointment_raises_an_exception_when_drs_service_responds_with_error_when_opening_session() { var scheduleBookingResponse = new scheduleBookingResponse(new xmbScheduleBookingResponse { status = responseStatus.success }); var mockLogger = new Mock <ILoggerAdapter <AppointmentActions> >(); var mockAppointmentsService = new Mock <IHackneyAppointmentsService>(); var openSessionResponse = new openSessionResponse( new xmbOpenSessionResponse { status = responseStatus.error, sessionId = "" } ); var closeSessionResponse = new closeSessionResponse( new xmbCloseSessionResponse { status = responseStatus.success } ); var drsOrder = new DrsOrder { wo_ref = "01550854" }; mockAppointmentsService.Setup(service => service.OpenSessionAsync(It.IsAny <xmbOpenSession>())) .ReturnsAsync(openSessionResponse); mockAppointmentsService.Setup(service => service.CloseSessionAsync(It.IsAny <xmbCloseSession>())) .ReturnsAsync(closeSessionResponse); mockAppointmentsService.Setup(service => service.ScheduleBookingAsync(It.IsAny <xmbScheduleBooking>())) .ReturnsAsync(scheduleBookingResponse); var mockRepairsService = new Mock <IHackneyRepairsService>(); mockRepairsService.Setup(service => service.GetWorkOrderDetails("01550854")).ReturnsAsync(drsOrder); var fakeRequestBuilder = new Mock <IHackneyAppointmentsServiceRequestBuilder>(); fakeRequestBuilder.Setup(service => service.BuildXmbOpenSessionRequest()).Returns(new xmbOpenSession()); fakeRequestBuilder.Setup(service => service.BuildXmbCloseSessionRequest("123456")) .Returns(new xmbCloseSession()); fakeRequestBuilder.Setup(service => service.BuildXmbScheduleBookingRequest("01550854", "123456", new DateTime(2017, 11, 21, 10, 00, 00), new DateTime(2017, 11, 21, 12, 00, 00), drsOrder)) .Returns(new xmbScheduleBooking()); var fakeRepairRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>(); AppointmentActions appointmentActions = new AppointmentActions(mockLogger.Object, mockAppointmentsService.Object, fakeRequestBuilder.Object, mockRepairsService.Object, fakeRepairRequestBuilder.Object); await Assert.ThrowsAsync <AppointmentServiceException>(async() => await appointmentActions.BookAppointment("01550854", new DateTime(2017, 11, 21, 10, 00, 00), new DateTime(2017, 11, 21, 12, 00, 00))); }
public async Task book_appointment_returns_success_result() { var scheduleBookingResponse = new scheduleBookingResponse(new xmbScheduleBookingResponse { status = responseStatus.success }); var mockLogger = new Mock <ILoggerAdapter <AppointmentActions> >(); var mockAppointmentsService = new Mock <IHackneyAppointmentsService>(); var openSessionResponse = new openSessionResponse( new xmbOpenSessionResponse { status = responseStatus.success, sessionId = "123456" } ); var closeSessionResponse = new closeSessionResponse( new xmbCloseSessionResponse { status = responseStatus.success } ); var drsOrder = new DrsOrder { wo_ref = "01550854" }; var xmbScheduleBooking = new xmbScheduleBooking { theBooking = new booking() }; mockAppointmentsService.Setup(service => service.OpenSessionAsync(It.IsAny <xmbOpenSession>())) .ReturnsAsync(openSessionResponse); mockAppointmentsService.Setup(service => service.CloseSessionAsync(It.IsAny <xmbCloseSession>())) .ReturnsAsync(closeSessionResponse); mockAppointmentsService.Setup(service => service.ScheduleBookingAsync(xmbScheduleBooking)) .ReturnsAsync(scheduleBookingResponse); mockAppointmentsService.Setup(service => service.SelectOrderAsync(It.IsAny <xmbSelectOrder>())) .ReturnsAsync(new selectOrderResponse(new xmbSelectOrderResponse { status = responseStatus.success, theOrders = new List <order> { new order { contract = "H01", theBookings = new List <booking> { new booking { bookingId = 123456 } }.ToArray(), theLocation = new location { locationId = "012345", contract = "H01", name = "An address", address1 = "An address", postCode = "Apostcode" } } }.ToArray() })); var mockWorksOrderResponse = new RepairsService.WebResponse { Success = true }; var mockRepairsService = new Mock <IHackneyRepairsService>(); mockRepairsService.Setup(service => service.GetWorkOrderDetails("01550854")).ReturnsAsync(drsOrder); mockRepairsService.Setup(service => service.IssueOrderAsync(It.IsAny <RepairsService.WorksOrderRequest>())) .ReturnsAsync(mockWorksOrderResponse); var fakeRequestBuilder = new Mock <IHackneyAppointmentsServiceRequestBuilder>(); fakeRequestBuilder.Setup(service => service.BuildXmbOpenSessionRequest()).Returns(new xmbOpenSession()); fakeRequestBuilder.Setup(service => service.BuildXmbCloseSessionRequest("123456")) .Returns(new xmbCloseSession()); fakeRequestBuilder.Setup(service => service.BuildXmbScheduleBookingRequest("01550854", "123456", new DateTime(2017, 11, 21, 10, 00, 00), new DateTime(2017, 11, 21, 12, 00, 00), drsOrder)) .Returns(xmbScheduleBooking); var fakeRepairRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>(); AppointmentActions appointmentActions = new AppointmentActions(mockLogger.Object, mockAppointmentsService.Object, fakeRequestBuilder.Object, mockRepairsService.Object, fakeRepairRequestBuilder.Object); var result = await appointmentActions.BookAppointment("01550854", new DateTime(2017, 11, 21, 10, 00, 00), new DateTime(2017, 11, 21, 12, 00, 00)); Assert.Contains("{ beginDate = 2017-11-21T10:00:00Z, endDate = 2017-11-21T12:00:00Z }", result.ToString()); }