public async Task <QueryResponseDto <ProductOptionResponseDto> > GetById(Guid id) { try { var productOption = await _mediator.Send(new GetProductOptionQuery(id)); return(QueryResponseDto <ProductOptionResponseDto> .Success(_mapper.Map <ProductOptionResponseDto>(productOption))); } catch (Exception ex) { return(QueryResponseDto <ProductOptionResponseDto> .Fail(GetErrorMessage(ex))); } }
public async Task GetProductShouldReturnProductResponseDto() { // Arrange var responseDto = new QueryResponseDto <ProductResponseDto>(new ProductResponseDto()); _productInterface.Setup(x => x.GetById(It.IsAny <Guid>())).ReturnsAsync(responseDto); var controller = new ProductsController(_productInterface.Object); // Act var response = await controller.GetProduct(Guid.NewGuid()); // Assert Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <ProductResponseDto>)); }
public async Task GetProductShouldReturnBadRequestWhenFail() { // Arrange var responseDto = new QueryResponseDto <ProductResponseDto>("Error!"); _productInterface.Setup(x => x.GetById(It.IsAny <Guid>())).ReturnsAsync(responseDto); var controller = new ProductsController(_productInterface.Object); // Act var response = await controller.GetProduct(Guid.NewGuid()); // Assert Assert.IsInstanceOfType(response, typeof(BadRequestErrorMessageResult)); Assert.AreEqual(((BadRequestErrorMessageResult)response).Message, "Error!"); }
public async Task <QueryResponseDto <ProductOptionsResponseDto> > GetAllByProductId(Guid productId) { try { var productOptions = await _mediator.Send(new GetAllProductOptionsQuery(productId)); var response = new ProductOptionsResponseDto() { Items = productOptions.ProjectTo <ProductOptionResponseDto>(_mapper.ConfigurationProvider) }; return(QueryResponseDto <ProductOptionsResponseDto> .Success(response)); } catch (Exception ex) { return(QueryResponseDto <ProductOptionsResponseDto> .Fail(GetErrorMessage(ex))); } }
public async Task <QueryResponseDto <ProductsResponseDto> > SearchByName(string name) { try { var products = await _mediator.Send(new SearchProductByNameQuery(name)); var response = new ProductsResponseDto() { Items = products.ProjectTo <ProductResponseDto>(_mapper.ConfigurationProvider) }; return(QueryResponseDto <ProductsResponseDto> .Success(response)); } catch (Exception ex) { return(QueryResponseDto <ProductsResponseDto> .Fail(GetErrorMessage(ex))); } }