public async Task Execute_Should_ReturnError_When_TakeIsLessThenZero() { var request = _fixture.Build <UserGetAll>() .With(x => x.Take, -1) .Create(); var result = await _operation.ExecuteAsync(request, CancellationToken.None); result.IsSuccess.Should().BeFalse(); result.Value.Should().BeNull(); result.Should().BeOfType <ErrorResult>(); result.ErrorCode.Should().Be(Domain.DomainError.GetError.InvalidTake.ErrorCode); result.Description.Should().Be(Domain.DomainError.GetError.InvalidTake.Description); _repository .Received(0) .GetAll(request.Skip, request.Take); _mapper .Received(0) .Map(Arg.Any <Domain.Common.User>()); }
public async Task <IActionResult> GetAllUser([FromQuery] int?skip, [FromQuery] int?take, [FromServices] UserGetAllOperation operation) { var result = await operation.ExecuteAsync(new UserGetAll { Skip = skip ?? 0, Take = take ?? 0 }); if (result is OkResult <IEnumerable <UserResponse> > ok) { return(Ok(ok.Value)); } if (result is ErrorResult error && error.ErrorCode.StartsWith("USR")) { return(UnprocessableEntity(error)); } return(BadRequest(result)); }