コード例 #1
0
        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));
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        public Task <RepairGetResponse> GetRepairRequestByReferenceAsync(RepairRefRequest request)
        {
            var response = new RepairGetResponse
            {
                Success       = true,
                RepairRequest = new RepairRequestDto
                {
                    Reference         = "43453543  ",
                    Problem           = "tap leaking ",
                    PriorityCode      = "N",
                    PropertyReference = "123456890",
                    Name = "Al Smith"
                }
            };

            switch (request.RequestReference)
            {
            case "123456890":
                return(Task.Run(() => new RepairGetResponse
                {
                    Success = false,
                    RepairRequest = new RepairRequestDto()
                }));

            case "123456899":
                return(Task.Run(() => new RepairGetResponse
                {
                    Success = true
                }));

            case "123456":
                return(Task.Run(() => response));

            case "ABCXYZ":
                throw new Exception();

            default:
                return(Task.Run(() => new RepairGetResponse
                {
                    Success = true,
                    RepairRequest = new RepairRequestDto()
                }));
            }
        }