public async Task get_repair_request_by_reference_returns_a_repair_object_for_a_valid_request()
        {
            var mockLogger = new Mock <ILoggerAdapter <RepairsActions> >();
            var request    = new RepairRefRequest();
            var response   = new RepairGetResponse()
            {
                Success       = true,
                RepairRequest = new RepairRequestDto()
                {
                    Reference         = "43453543",
                    Problem           = "tap leaking",
                    PriorityCode      = "N",
                    PropertyReference = "123456890",
                    LocationCode      = "1",
                    Name = "Test"
                }
            };
            var tasksListResponse = new TaskListResponse
            {
                Success  = true,
                TaskList = new List <RepairTaskDto>
                {
                    new RepairTaskDto
                    {
                        WorksOrderReference = "987654",
                        SupplierReference   = "00000127",
                        JobCode             = "12345678"
                    }
                }.ToArray()
            };
            var fakeService = new Mock <IHackneyRepairsService>();

            fakeService.Setup(service => service.GetRepairRequestByReferenceAsync(request))
            .ReturnsAsync(response);
            fakeService.Setup(service => service.GetRepairTasksAsync(It.IsAny <RepairRefRequest>()))
            .ReturnsAsync(tasksListResponse);
            var fakeRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildRepairRequest("43453543")).Returns(request);
            RepairsActions repairsActions = new RepairsActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            var            results        = await repairsActions.GetRepairByReference("43453543");

            var workOrders = new object[1];

            workOrders[0] = new { workOrderReference = "987654", sorCode = "12345678", supplierReference = "00000127" };
            var repairRequest = new
            {
                repairRequestReference = "43453543",
                problemDescription     = "tap leaking",
                priority          = "N",
                propertyReference = "123456890",
                contact           = new { name = "Test" },
                workOrders        = workOrders
            };

            Assert.Equal(JsonConvert.SerializeObject(repairRequest), JsonConvert.SerializeObject(results));
        }
Beispiel #2
0
        public async Task <JsonResult> GetByReference(string reference)
        {
            try
            {
                RepairsActions repairActions = new RepairsActions(_repairsService, _requestBuilder, _loggerAdapter);
                var            json          = Json(await repairActions.GetRepairByReference(reference));
                json.StatusCode = 200;
                return(json);
            }
            catch (MissingRepairException ex)
            {
                //var json = Json(new object());
                //json.StatusCode = 404;
                //return json;

                var errors = new List <ApiErrorMessage>
                {
                    new ApiErrorMessage
                    {
                        developerMessage = ex.Message,
                        userMessage      = @"Cannot find repair."
                    }
                };
                var json = Json(errors);
                json.StatusCode = 404;
                return(json);
            }
            catch (Exception ex)
            {
                var errors = new List <ApiErrorMessage>
                {
                    new ApiErrorMessage
                    {
                        developerMessage = ex.Message,
                        userMessage      = "We had some problems processing your request"
                    }
                };
                var json = Json(errors);
                json.StatusCode = 500;
                return(json);
            }
        }
        public async Task get_repair_by_reference_raises_an_exception_if_the_service_responds_with_an_error()
        {
            var mockLogger = new Mock <ILoggerAdapter <RepairsActions> >();
            var request    = new RepairRefRequest();
            var response   = new RepairGetResponse {
                Success = false, RepairRequest = new RepairRequestDto()
            };
            var fakeService = new Mock <IHackneyRepairsService>();

            fakeService.Setup(service => service.GetRepairRequestByReferenceAsync(It.IsAny <RepairRefRequest>()))
            .ReturnsAsync(response);

            var fakeRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildRepairRequest("52525252534")).Returns(request);
            RepairsActions repairsActions = new RepairsActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            await Assert.ThrowsAsync <HackneyRepairs.Actions.RepairsServiceException>(async() => await repairsActions.GetRepairByReference("52525252534"));
        }