public async Task HttpRequiredBodyFieldMissing([Values] bool skipClientValidation) { var api = CreateHttpApi(skipClientValidation: skipClientValidation); var result = await api.GetWidgetBatchAsync(new GetWidgetBatchRequestDto()); result.Should().BeFailure(ServiceErrors.CreateRequestFieldRequired("ids")); }
public async Task <ServiceResult <GetWidgetBatchResponseDto> > GetWidgetBatchAsync(GetWidgetBatchRequestDto request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Ids == null) { return(ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("ids"))); } if (request.Ids.Count == 0) { return(ServiceResult.Failure(ExampleApiErrors.CreateInvalidRequestMissingWidgetIds())); } var widgets = await m_repository.GetWidgetBatchAsync(request.Ids, cancellationToken).ConfigureAwait(false); return(ServiceResult.Success(new GetWidgetBatchResponseDto { Results = widgets.Select((x, i) => x != null ? ServiceResult.Success(x) : string.IsNullOrEmpty(request.Ids[i]) ? ServiceResult.Failure(ExampleApiErrors.CreateInvalidRequestMissingWidgetId()) : ServiceResult.Failure(ExampleApiErrors.CreateNotFoundWidget(request.Ids[i]))).ToList() })); }
public async Task HttpRequiredNormalRequestFieldMissing([Values] bool skipClientValidation) { var api = CreateHttpApi(skipClientValidation: skipClientValidation); var dto = CreateRequiredRequest(); dto.Normal = null; var result = await api.RequiredAsync(dto); result.Should().BeFailure(ServiceErrors.CreateRequestFieldRequired("normal")); }
public async Task <ServiceResult <CreateWidgetResponseDto> > CreateWidgetAsync(CreateWidgetRequestDto request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.Widget == null) { return(ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("widget"))); } var newWidget = await m_repository.CreateWidgetAsync(request.Widget, cancellationToken).ConfigureAwait(false); return(ServiceResult.Success(new CreateWidgetResponseDto { Widget = newWidget })); }
public async Task MissingIds_InvalidRequest() { var service = TestUtility.CreateService(m_category); (await service.GetWidgetBatchAsync(ids: null)).Should().BeFailure(ServiceErrors.CreateRequestFieldRequired("ids")); }
public async Task MissingWidget_BadRequest() { var service = TestUtility.CreateService(m_category); (await service.CreateWidgetAsync(widget: null)).Should().BeFailure(ServiceErrors.CreateRequestFieldRequired("widget")); }