Exemplo n.º 1
0
        /// <summary>
        /// Test of the ExistsPendriveTest function
        /// </summary>
        static public void ExistsPendriveTest()
        {
            StoreBL storeBL = new StoreBL();
            Store   store   = new Store();

            store.Name = "PenStore1";
            store.ID   = "1";

            PenDrive pendrive1 = new PenDrive();

            pendrive1.Brand = "brand1";
            pendrive1.Model = "model1";
            PenDrive pendrive2 = new PenDrive();
            PenDrive pendrive3 = new PenDrive();

            storeBL.AddPenDrive(store, pendrive1);
            storeBL.AddPenDrive(store, pendrive2);
            storeBL.AddPenDrive(store, pendrive3);

            if (storeBL.ExistPenDrive(store, "brand1", "model"))
            {
                Console.WriteLine("The pen exist");
            }
            else
            {
                Console.WriteLine("The pen doesn't exist");
            }
        }
Exemplo n.º 2
0
        // TODO: 11. This class must implement the IStore interface (Interfaces.IStoreBL).
        //           Methods must be implemented by priority:
        //
        //           bool AddPenDrive(Store store, PenDrive penDrive);
        //           bool ExistPenDrive(Store store, string brand, string model);
        //           bool ExistPenDrive(Store store, PenDrive penDrive);
        //           string ShowAllProducts(Store store);
        //           IEnumerable<Product> GetAllProducts(Store store);
        //           bool CalculateTotalPrice(Store store, List<PenDrive> penDrives, out decimal? total);
        //           bool CalculateTotalPrice(Store store, List<Phone> phones, out decimal? total);
        //           bool CalculateTotalPrice(Store store, List<Refrigerator> refrigerators, out decimal? total);
        //           bool CalculateTotalPrice(Store store, List<Product> items, out decimal? total);
        //           bool CalculateTotalPrice<T>(Store store, List<T> items, out decimal? total);

        /// <summary>
        /// Add a pen drive to the store products.
        /// </summary>
        /// <remarks>
        /// No duplicity allowed (in order to brand and model). This method validates it.
        /// </remarks>
        /// <param name="store">Store.</param>
        /// <param name="penDrive">Pen drive.</param>
        /// <returns>True if the item was added.</returns>
        public bool AddPenDrive(Store store, PenDrive penDrive)
        {
            bool added = false;

            if (!ExistPenDrive(store, penDrive.Brand, penDrive.Model))
            {
                store.Products.Pendrives.Add(penDrive);
                added = true;
            }

            return(added);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Test of the GetAllProductsTest function.
        /// </summary>
        static public void GetAllProductsTest()
        {
            StoreBL storeBL = new StoreBL();
            Store   store   = new Store();

            PenDrive pen1 = new PenDrive();

            pen1.Memory = 500;
            pen1.Model  = "Kingston";
            pen1.Price  = 20;

            PenDrive pen2 = new PenDrive();

            pen2.Memory = 300;
            pen2.Model  = "HP";
            pen2.Price  = 17;

            Phone pho1 = new Phone();

            pho1.Inches = 30;
            pho1.Model  = "HP";
            pho1.Price  = 17;

            Phone pho2 = new Phone();

            pho2.Inches = 30;
            pho2.Model  = "HP";
            pho2.Price  = 17;

            Refrigerator ref1 = new Refrigerator();

            ref1.Brand    = "Samsung";
            ref1.Capacity = 50;
            ref1.Price    = 430;

            Refrigerator ref2 = new Refrigerator();

            ref2.Brand    = "Fujitsu";
            ref2.Capacity = 100;
            ref2.Price    = 600;

            store.Products.Pendrives.Add(pen1);
            store.Products.Pendrives.Add(pen2);
            store.Products.Phones.Add(pho1);
            store.Products.Phones.Add(pho1);
            store.Products.Refrigerators.Add(ref1);
            store.Products.Refrigerators.Add(ref2);


            Console.WriteLine(storeBL.GetAllProducts(store));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Test of the CalculateTotalPriceTest function.
        /// </summary>
        static public void CalculateTotalPriceTest()
        {
            StoreBL storeBL = new StoreBL();
            Store   store   = new Store();

            decimal?sum = 0;

            store.Name = "PenStore1";
            store.ID   = "1";

            PenDrive pendrive1 = new PenDrive();

            pendrive1.Brand = "brand1";
            pendrive1.Model = "model1";
            pendrive1.Price = 34;
            PenDrive pendrive2 = new PenDrive();

            pendrive2.Brand = "Brand2";
            pendrive2.Price = 26;
            PenDrive pendrive3 = new PenDrive();

            pendrive3.Brand = "Brand3";
            pendrive3.Price = 40;
            PenDrive pendrive4 = new PenDrive();

            pendrive4.Brand = "Brand4";
            pendrive4.Price = 76;

            storeBL.AddPenDrive(store, pendrive1);
            storeBL.AddPenDrive(store, pendrive2);
            storeBL.AddPenDrive(store, pendrive3);
            storeBL.AddPenDrive(store, pendrive4);


            if (storeBL.CalculateTotalPrice(store, store.Products.Pendrives, out sum))
            {
                Console.WriteLine("Successfully Calculated.");
            }
            else
            {
                Console.WriteLine("Not so successfully calculated.");
            }


            Console.WriteLine("Suma:" + sum.ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Validate if a pen drive exists in the store (in order to brand and model).
        /// </summary>
        /// <param name="store">Store.</param>
        /// <param name="penDrive">Pen drive.</param>
        /// <returns>True if the item already exists.</returns>
        public bool ExistPenDrive(Store store, PenDrive penDrive)
        {
            bool exists = false;

            if (store != null && penDrive != null)
            {
                var brandQuery = store.Products.Pendrives.Where(pen => pen.Brand == penDrive.Brand);

                var modelQuery = store.Products.Pendrives.Where(pen => pen.Model == penDrive.Model);

                if (brandQuery.Count() > 0 && modelQuery.Count() > 0)
                {
                    exists = true;
                }
            }

            return(exists);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Test of the AddPenDrive function
        /// </summary>
        static public void AddPendriveTest()
        {
            StoreBL storeBL = new StoreBL();
            Store   store   = new Store();

            store.Name = "PenStore1";
            store.ID   = "1";

            PenDrive pendrive1 = new PenDrive();

            if (storeBL.AddPenDrive(store, pendrive1))
            {
                Console.WriteLine("Pendrive added.");
            }
            else
            {
                Console.WriteLine("There was a problem adding the pendrive.");
            }

            storeBL.AddPenDrive(store, pendrive1);
        }