public async Task <IActionResult> PutInspectionComplete( Guid id, [FromBody] InspectionCompleteDto completionDto, CancellationToken cancellationToken) { if (completionDto == null) { return(InvalidRequestBodyJson(nameof(InspectionCompleteDto))); } var results = await _inspectionService .CompleteInspectionAsync(id, completionDto.FinishTime, cancellationToken); var descriptors = results.Select(r => Mapper.Map <PluginResultDescriptorDto>(r)); return(Ok(new InspectionCompleteResponseDto { PluginResults = descriptors.ToArray() })); }
private async Task <InspectionCompleteResponseDto> UploadInspectionData(RusHydroInspectionData data) { var inspectionId = await _apiClient.PostInspectionAsync(data.Inspection); data.SvmrTest.InspectionId = data.HrvTest.InspectionId = inspectionId.ToString(); var hrvTestId = await _apiClient.PostTestAsync(data.SvmrTest); var svmrTestId = await _apiClient.PostTestAsync(data.HrvTest); var completeDto = new InspectionCompleteDto { Id = inspectionId, FinishTime = data.SvmrTest.FinishTime > data.HrvTest.FinishTime ? data.SvmrTest.FinishTime : data.HrvTest.FinishTime }; return(await _apiClient.CompleteInspectionAsync(completeDto)); }
public async Task <InspectionCompleteResponseDto> CompleteInspectionAsync(InspectionCompleteDto completeDto) { var response = await ExecuteWithAuthentication(() => { var url = inspectionsEndpoint + "/" + completeDto.Id.ToString() + "/complete"; return(_httpClient.PutAsJsonAsync(BaseAddress + url, completeDto)); }); var dto = await response.Content.ReadAsJsonAsync <InspectionCompleteResponseDto>(); var baseLength = BaseAddress.Length; var pluginResults = dto.PluginResults.Select(r => new PluginResultDescriptorDto { PluginType = r.PluginType, ResultsUrl = r.ResultsUrl.StartsWith(BaseAddress) ? r.ResultsUrl.Remove(0, baseLength) : r.ResultsUrl }).ToArray(); return(new InspectionCompleteResponseDto { PluginResults = pluginResults }); }
public async Task CompleteInspection_Should_Call_CompleteInspectionAsync_And_Return_NoContent() { // Given var controller = new InspectionController(_inspectionService, _tenantIdProvider); var completionDto = new InspectionCompleteDto { Id = _incompleteInspection.Id, FinishTime = DateTimeOffset.Now }; // When // user tries to mark inspection as completed var response = (OkObjectResult)await controller.PutInspectionComplete(completionDto.Id, completionDto, default(CancellationToken)); // Then // The controller calls service with proper arguments await _inspectionService.Received().CompleteInspectionAsync( Arg.Is <Guid>(g => g == completionDto.Id), Arg.Is <DateTimeOffset>(t => t == completionDto.FinishTime), Arg.Any <CancellationToken>()); response.StatusCode.ShouldBe((int)HttpStatusCode.OK); }