public Task <scheduleBookingResponse> ScheduleBookingAsync(xmbScheduleBooking scheduleBooking)
        {
            _logger.LogInformation($"HackneyAppointmentsService/ScheduleBookingAsync(): Sent request to upstream AppointmentServiceClient (Order Id: {scheduleBooking.theBooking.orderId})");
            var response = _client.scheduleBookingAsync(scheduleBooking);

            _logger.LogInformation($"HackneyAppointmentsService/ScheduleBookingAsync(): Received response from upstream PropertyServiceClient (Order Id: {scheduleBooking.theBooking.orderId})");
            return(response);
        }
Exemple #2
0
        public xmbScheduleBooking BuildXmbScheduleBookingRequest(string workOrderReference, string sessionId, DateTime beginDate,
                                                                 DateTime endDate, DrsOrder drsOrder)
        {
            var bookingCodes = drsOrder.Tasks.Select((bookingCode, i) => new bookingCode
            {
                bookingCodeDescription = bookingCode.comments.Trim(),
                bookingCodeSORCode     = bookingCode.job_code.Trim(),
                itemValue          = bookingCode.itemValue.ToString().Trim(),
                primaryOrderNumber = workOrderReference.Trim(),
                trade = bookingCode.trade.Trim(),
                standardMinuteValue     = bookingCode.smv.ToString().Trim(),
                quantity                = bookingCode.itemqty.ToString().Trim(),
                itemNumberWithinBooking = i.ToString().Trim()
            })
                               .ToArray();
            var order = new order
            {
                primaryOrderNumber = workOrderReference.Trim(),
                contract           = drsOrder.contract.Trim(),
                locationID         = drsOrder.prop_ref.Trim(),
                userId             = drsOrder.userid,
                theBookingCodes    = bookingCodes,
                priority           = drsOrder.priority,
                contactName        = drsOrder.contactName,
                orderComments      = drsOrder.comments,
                phone      = drsOrder.phone,
                message    = drsOrder.txtMessage,
                targetDate = drsOrder.dueDate
            };
            var xmbSchedulebooking = new xmbScheduleBooking
            {
                theBooking = new booking
                {
                    primaryOrderNumber  = workOrderReference.Trim(),
                    contract            = drsOrder.contract.Trim(),
                    locationID          = drsOrder.prop_ref.Trim(),
                    userId              = drsOrder.userid,
                    theBookingCodes     = bookingCodes,
                    theOrder            = order,
                    planningWindowStart = beginDate,
                    planningWindowEnd   = endDate,
                    isEmergency         = false
                },
                sessionId = sessionId,
                force     = false,
                userId    = drsOrder.userid,
            };

            return(xmbSchedulebooking);
        }
        public Task <scheduleBookingResponse> ScheduleBookingAsync(xmbScheduleBooking scheduleBooking)
        {
            switch (scheduleBooking.theBooking.primaryOrderNumber)
            {
            case "01550853":
                return(Task.Run(() =>
                                new scheduleBookingResponse(new xmbScheduleBookingResponse {
                    status = responseStatus.error
                })));

            default:
                return(Task.Run(() =>
                                new scheduleBookingResponse(new xmbScheduleBookingResponse {
                    status = responseStatus.success
                })));
            }
        }
        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());
        }