コード例 #1
0
        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}"));
        }
コード例 #2
0
        public async Task <IActionResult> ProductByIdQuery()
        {
            var query = new ProductByIdQuery {
                Id = 1
            };
            var plastico = await _mediator.Send(query);

            return(Json(plastico));
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
        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>();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
    public async Task <IActionResult> GetProductByIdAsync([FromQuery] ProductByIdQuery product)
    {
        var queryProduct = await _mediator.Send(product);

        return(Json(queryProduct));
    }
コード例 #7
0
        public async Task <IActionResult> GetById([FromRoute] ProductByIdQuery query)
        {
            var result = await Mediator.Send(query);

            return(Ok(result));
        }