public void Validate_should_return_error_when_OrderByDirection_is_a_wrong_value()
        {
            var request = BuildTestRequest();

            request.OrderByDirection = "blah";

            var result = sut.Validate(request);

            Assert.False(result.IsValid);
            Assert.Equal("OrderByDirection can only be asc or desc.", result.ErrorMessage);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <PagedResult <Customer> > > Get([FromQuery] GetCustomersRequest request)
        {
            var validator        = new GetCustomersRequestValidator();
            var validationResult = validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(BadRequest(new { ErrorMessage = validationResult.ErrorMessage }));
            }

            var filter = _mapper.Map <GetCustomersFilter>(request);
            var result = await _customerService.GetCustomersAsync(filter);

            var customers = _mapper.Map <IEnumerable <CustomerEntity>, IEnumerable <Customer> >(result.Result.Items);

            //A pagination result will give frontend flexibility to display data in pages.
            return(Ok(new PagedResult <Customer>()
            {
                Page = result.Result.Page, TotalCount = result.Result.TotalCount, RecordsPerPage = result.Result.RecordsPerPage, Items = customers
            }));
        }