Пример #1
0
        public void DeletingCategoryShouldDeleteProductMapping()
        {
            //build
            var category = new CategoryBuilder().Build();

            _documentService.AddDocument(category);
            var product = new ProductBuilder().Build();

            _documentService.AddDocument(product);

            //test
            _productService.AddCategory(product, category.Id);
            product.Categories.Count.Should().Be(1);
            _documentService.DeleteDocument(category);
            product.Categories.Count.Should().Be(0);
        }
        private void add_Click(object sender, EventArgs e)
        {
            String             categoryName = categoryNameTxt.Text;
            DataUtilityService dservice     = new DataUtilityService();

            if (!dservice.checkEmpty(categoryName))
            {
                bool flagAdded = pService.AddCategory(categoryName);
                if (flagAdded)
                {
                    //  msglabel.Text = "Category Successfully Added";
                    categoryNameTxt.Text = "";
                    // msglabel.ForeColor = Color.Green;
                    // msglabel.Visible = true;
                    MessageBox.Show("Category Successfully Added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //  msglabel.Text = "Category failed to add";
                    //  msglabel.ForeColor = Color.Red;
                    //  msglabel.Visible = true;
                    MessageBox.Show("Category failed to add", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                // msglabel.Text = "Empty category cannot be added";
                // msglabel.ForeColor = Color.Red;
                // msglabel.Visible = true;
                MessageBox.Show("Empty category cannot be added", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        public async Task <ActionResult <ProductCategoryAddDto> > AddCategory([FromBody] ProductCategoryAddDto model)
        {
            if (UserResolverService.IsUserAdmin())
            {
                var category = await ProductService.AddCategory(model);

                if (category != null)
                {
                    return(Ok(category));
                }
            }
            return(Forbid());
        }
        public async Task Test_AddProduct()
        {
            // mock the logger
            Mock <ILogger <ProductService> > mock   = new Mock <ILogger <ProductService> >();
            ILogger <ProductService>         logger = mock.Object;

            DbContextOptions options = GetConnectionDetails();

            using (CatalogueUnitOfWork catalogueUnitOfWork = new CatalogueUnitOfWork(new AppDataContext(options)))
            {
                IProductService productService = new ProductService(logger, catalogueUnitOfWork);

                Category category = await productService.AddCategory($"New Category {DateTime.Now.Ticks}");

                await catalogueUnitOfWork.CommitAsync();

                System.Diagnostics.Debug.WriteLine($"{category.CategoryId} {category.CategoryName}");
            }
        }