Example #1
0
        public void CanCreateProduct()
        {
            const string productname      = "produit1";
            const int    quantiteMinimale = 15;
            var          marque           = new RepositoryMarque().FindAll().First();
            var          category         = new RepositoryCategory().FindAll().First();
            var          fournisseur      = new RepositoryFournisseur().FindAll().First();
            var          product          = FactoryProduct.CreateProduct(productname, quantiteMinimale, category, marque, fournisseur);

            Assert.AreEqual(product.Name, "produit1");
            Assert.AreEqual(product.QuantiteMin, 15);

            new RepositoryProduct().Save(product);

            var rp = new RepositoryMarque().FindBy(product.Marque.id);

            Assert.AreEqual(product.Marque.id, rp.id);
            Assert.AreEqual(product.Marque.Name, rp.Name);

            var rc = new RepositoryCategory().FindBy(product.Category.id);

            Assert.AreEqual(product.Category.id, rc.id);
            Assert.AreEqual(product.Category.Name, rc.Name);
            Assert.AreEqual(product.Category.Description, rc.Description);

            new RepositoryProduct().Remove(product);
        }
Example #2
0
        public void GetProductminimal()
        {
            const string productname       = "HP Desktop I3";
            const int    quantiteMinimale  = 10;
            const string productname1      = "HP Desktop I5";
            const int    quantiteMinimale1 = 10;
            var          marque            = new RepositoryMarque().FindAll().First();
            var          category          = new RepositoryCategory().FindAll().First();
            var          fournisseur       = new RepositoryFournisseur().FindAll().First();
            var          product           = FactoryProduct.CreateProduct(productname, quantiteMinimale, category, marque, fournisseur);
            var          product1          = FactoryProduct.CreateProduct(productname1, quantiteMinimale1, category, marque, fournisseur);

            Assert.AreEqual(product.Name, productname);
            Assert.AreEqual(product.QuantiteMin, quantiteMinimale);
            Assert.AreEqual(product1.Name, productname1);
            Assert.AreEqual(product1.QuantiteMin, quantiteMinimale1);
            new RepositoryProduct().Save(product);
            new RepositoryProduct().Save(product1);
            var rp = new RepositoryMarque().FindBy(product.Marque.id);

            Assert.AreEqual(product.Marque.id, rp.id);
            Assert.AreEqual(product.Marque.Name, rp.Name);
            var rc = new RepositoryCategory().FindBy(product.Category.id);

            Assert.AreEqual(product.Category.id, rc.id);
            Assert.AreEqual(product.Category.Name, rc.Name);
            Assert.AreEqual(product.Category.Description, rc.Description);

            const string stockname = "Stock Tlemcen";
            var          wilaya    = new RepositoryWilaya().FindAll().First(w => w.Name == "Tlemcen");
            var          commune   = new RepositoryWilaya().FindAll().First(w => w.Name == "Tlemcen").Communes.First(com => com.Name == "Tlemcen");
            const string adresse   = "S3 lot Sekkal el Kiffane";
            var          stock     = FactoryStock.CreateStock(stockname, wilaya, commune, adresse);

            Assert.AreEqual(stock.Name, stockname);

            var lineStock  = FactoryStock.CreateProductLine(stock, product, 5);
            var lineStock1 = FactoryStock.CreateProductLine(stock, product1, 20);

            Assert.AreEqual(lineStock.Product, product);
            Assert.AreEqual(lineStock.Quantity, 5);
            Assert.AreEqual(lineStock1.Product, product1);
            Assert.AreEqual(lineStock1.Quantity, 20);

            new RepositoryStock().Save(stock);

            var listProduct = stock.GetProductMinimale();

            Assert.AreEqual(listProduct.Count, 1);
            new RepositoryStock().Remove(stock);
            new RepositoryProduct().Remove(product);
            new RepositoryProduct().Remove(product1);
        }
        public FrmEditProduct(ModelViewProduct product, bool newProduct)
        {
            InitializeComponent();

            var repositoryCategory    = new RepositoryCategory();
            var repositoryMarque      = new RepositoryMarque();
            var repositoryFournisseur = new RepositoryFournisseur();
            var repositoryProduit     = new RepositoryProduct();

            _editProductPresenter = new EditProductPresenterPage(this, repositoryCategory, repositoryMarque, repositoryFournisseur, repositoryProduit);
            _editProductPresenter.Display();

            comboBoxCategory.DataSource       = Categories;
            comboBoxCategory.DisplayMember    = "Name";
            comboBoxCategory.ValueMember      = "Name";
            comboBoxFournisseur.DataSource    = Fournisseurs;
            comboBoxFournisseur.DisplayMember = "Name";
            comboBoxFournisseur.ValueMember   = "Name";
            comboBoxMarque.DataSource         = Marques;
            comboBoxMarque.DisplayMember      = "Name";
            comboBoxMarque.ValueMember        = "Name";
            comboBoxTypeGestion.DataSource    = Enum.GetValues(typeof(GestionProduit));

            if (!newProduct)
            {
                IdProduct = product.Id;
                textEditNameProduct.Text          = product.Nom;
                comboBoxCategory.SelectedValue    = product.Categorie;
                comboBoxMarque.SelectedValue      = product.Marque;
                comboBoxFournisseur.SelectedValue = product.Fournisseur;
                textEditQuantité.Text             = product.QuantiteMin.ToString(CultureInfo.InvariantCulture);
                dateEditEntree.Text = product.DateEntree.ToShortDateString();
                comboBoxTypeGestion.SelectedItem = product.TypeGestion;
            }

            IsProductModified = false;
            _newProduct       = newProduct;
        }