コード例 #1
0
        public async Task <IActionResult> EditProductCategory(
            [FromRoute] int supplierId,
            [FromRoute] int categoryId,
            EditProductCategoryCommandDto dto)
        {
            var command = new EditProductCategoryCommand(supplierId, categoryId, new ProductCategoryName(dto.Name));
            await _mediator.Send(command);

            return(Ok());
        }
コード例 #2
0
        public async Task EditProductCategoryCommandHandler_EditExistingProductCategory()
        {
            //Arange
            AllMarktContextIM.Shops.Add(new AllMarkt.Entities.Shop
            {
                Address           = "Address1",
                Comments          = null,
                CUI               = "CUI1",
                IBAN              = "IBAN",
                Orders            = null,
                PhoneNumber       = "0123654789",
                ProductCategories = null,
                ShopCategoryLink  = null,
                SocialCapital     = 3
            });

            AllMarktContextIM.SaveChanges();
            var shop = AllMarktContextIM.Shops.FirstOrDefault();

            AllMarktContextIM.ProductCategories.Add(new AllMarkt.Entities.ProductCategory
            {
                Name        = "firstName",
                Description = "FirstDec",
                Shop        = shop
            });
            AllMarktContextIM.SaveChanges();

            var existedProductCategory = AllMarktContextIM.ProductCategories.FirstOrDefault();
            var newProductCategory     = new EditProductCategoryCommand
            {
                Id          = existedProductCategory.Id,
                Name        = "editedName",
                Description = "editedDesc",
            };

            //Act
            await _editProductCategoryCommandHandler.Handle(newProductCategory, CancellationToken.None);

            //Assert
            AllMarktContextIM.ProductCategories
            .Should()
            .Contain(x => x.Id == newProductCategory.Id &&
                     x.Name == newProductCategory.Name &&
                     x.Description == newProductCategory.Description);
        }