public Task <RepairCreateResponse> CreateRepairAsync(NewRepairRequest request) { _logger.LogInformation($"HackneyRepairsService/CreateRepairAsync(): Sent request to upstream RepairServiceClient (Request ref: {request.RepairRequest.RequestReference})"); var response = _client.CreateRepairRequestAsync(request); _logger.LogInformation($"HackneyRepairsService/CreateRepairAsync(): Received response from upstream RepairServiceClient (Request ref: {request.RepairRequest.RequestReference})"); return(response); }
public async Task create_repair_returns_a_created_repair_response_object() { var mockLogger = new Mock <ILoggerAdapter <RepairsActions> >(); var request = new RepairRequest { ProblemDescription = "tap leaking", Priority = "N", PropertyReference = "123456", Contact = new RepairRequestContact { Name = "Test", TelephoneNumber = "0123456789" } }; var repairRequest = new NewRepairRequest { RepairRequest = new RepairRequestInfo { PropertyRef = request.PropertyReference, Priority = request.Priority, Problem = request.ProblemDescription } }; var fakeRepairService = new Mock <IHackneyRepairsService>(); var response = new RepairCreateResponse { Success = true, RepairRequest = new RepairRequestDto { Reference = "123", Problem = "tap leaking", PropertyReference = "123456", PriorityCode = "N", LocationCode = "1", Name = "Test" } }; fakeRepairService.Setup(service => service.CreateRepairAsync(repairRequest)) .ReturnsAsync(response); fakeRepairService.Setup(service => service.UpdateRequestStatus("123")).ReturnsAsync(true); var fakeRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>(); fakeRequestBuilder.Setup(builder => builder.BuildNewRepairRequest(request)).Returns(repairRequest); var repairsActions = new RepairsActions(fakeRepairService.Object, fakeRequestBuilder.Object, mockLogger.Object); var result = await repairsActions.CreateRepair(request); var response1 = new { repairRequestReference = "123", problemDescription = "tap leaking", priority = "N", propertyReference = "123456", contact = new { name = "Test", telephoneNumber = "0123456789" } }; Assert.Equal(response1, result); }
public async Task create_repair_raises_an_exception_if_the_repair_request_is_missing() { var mockLogger = new Mock <ILoggerAdapter <RepairsActions> >(); var request = new RepairRequest(); var repairRequest = new NewRepairRequest(); var response = new RepairCreateResponse { Success = true, RepairRequest = null }; var fakeService = new Mock <IHackneyRepairsService>(); fakeService.Setup(service => service.CreateRepairAsync(It.IsAny <NewRepairRequest>())) .ReturnsAsync(response); var fakeRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>(); fakeRequestBuilder.Setup(builder => builder.BuildNewRepairRequest(request)).Returns(repairRequest); var repairsActions = new RepairsActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object); await Assert.ThrowsAsync <MissingRepairRequestException>(async() => await repairsActions.CreateRepair(request)); }
public Task <RepairCreateResponse> CreateRepairAsync(NewRepairRequest request) { var response = new RepairCreateResponse { Success = true, RepairRequest = new RepairRequestDto { Reference = "123 ", Problem = "tap leaking ", PriorityCode = "N", PropertyReference = "00000320", LocationCode = "1 ", Name = "Al Smith" } }; switch (request.RepairRequest.PropertyRef) { case "01234568": return(Task.Run(() => new RepairCreateResponse { Success = false, RepairRequest = new RepairRequestDto() })); case "00000320": return(Task.Run(() => response)); default: return(Task.Run(() => new RepairCreateResponse { Success = true, RepairRequest = new RepairRequestDto() })); } }
public async Task create_repair_raises_an_exception_if_the_service_responds_with_an_error() { var mockLogger = new Mock <ILoggerAdapter <RepairsActions> >(); var request = new RepairRequest { ProblemDescription = "tap leaking", Priority = "N", PropertyReference = "123456890" }; var repairRequest = new NewRepairRequest(); var response = new RepairCreateResponse { Success = false, RepairRequest = null }; var fakeService = new Mock <IHackneyRepairsService>(); fakeService.Setup(service => service.CreateRepairAsync(repairRequest)) .ReturnsAsync(response); var fakeRequestBuilder = new Mock <IHackneyRepairsServiceRequestBuilder>(); fakeRequestBuilder.Setup(builder => builder.BuildNewRepairRequest(request)).Returns(repairRequest); var repairActions = new RepairsActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object); await Assert.ThrowsAsync <RepairsServiceException>(async() => await repairActions.CreateRepair(request)); }