public async Task <IActionResult> Get(long id) { var query = new ProductByIdQuery(id); var result = await DispatchAsync(query); return(result != null?Ok(result) : NotFound($"ProductId doesn't exist: {id}")); }
public async Task <IActionResult> ProductByIdQuery() { var query = new ProductByIdQuery { Id = 1 }; var plastico = await _mediator.Send(query); return(Json(plastico)); }
public ProductsEndpoint(ProductByIdQuery byIdQuery, ILoggerFactory loggerFactory) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (byIdQuery == null) { throw new ArgumentNullException(nameof(byIdQuery)); } _byIdQuery = byIdQuery; _logger = loggerFactory.CreateLogger <ProductsEndpoint>(); }
public void ShouldThrowProductNotFoundException() { // Arrange // Product By Id Query var productByIdQuery = new ProductByIdQuery() { // random product Id ProductId = Guid.NewGuid().ToString() }; // Act var results = FluentActions.Invoking(() => SendAsync(productByIdQuery)); // Assert results.Should().Throw <ProductNotFoundException>(); }
public async Task ShouldGetProductById() { // Arrange // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create product var createProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var productId = await SendAsync(createProductCommand); var productByIdQuery = new ProductByIdQuery { ProductId = productId }; var product = await SendAsync(productByIdQuery); product.Should().NotBeNull(); product.Id.Should().Be(productId); }
public async Task <IActionResult> GetProductByIdAsync([FromQuery] ProductByIdQuery product) { var queryProduct = await _mediator.Send(product); return(Json(queryProduct)); }
public async Task <IActionResult> GetById([FromRoute] ProductByIdQuery query) { var result = await Mediator.Send(query); return(Ok(result)); }