示例#1
0
        /*
         *
         * METODOS STATICOS DE AYUDA
         *
         */

        public static void LoadStock(MechanicalKeyboard m, Thinkpad t)
        {
            for (int i = 0; i < 10; i++)
            {
                Factory.LoadMoreStock(t);
                Factory.LoadMoreStock(m);
            }
        }
示例#2
0
        public void IsProductDuplicated_False()
        {
            // arrange
            Random             random = new Random();
            List <Product>     list   = new List <Product>();
            MechanicalKeyboard p1     = new MechanicalKeyboard("Poker 3", 1500, EKeyboardSize.FullSize);

            p1.Serial_Number = 10;
            list.Add(p1);
            MechanicalKeyboard p2 = new MechanicalKeyboard("Poker 3", 1600, EKeyboardSize.Small);

            p2.Serial_Number = 12;
            bool exit;

            // act
            exit = (list == p2);
            // assert
            Assert.IsFalse(exit);
        }
示例#3
0
        static void Main(string[] args)
        {
            // ATENCION - LA MAYORIA DE LA PRUEBAS QUE RESULTAN SIN STOCK ES DEBIDO A LOS TECLADOS QUE CONSUMEN
            // MUCHAS KEYCAPS Y MUCHOS SWTICHES, TENER EN CUENTA Y AGREGAR STOCK CONTINUO PARA PROBAR
            bool sinStock = false;
            // creamos una lista con 2 objetos.
            List <Product>     list = new List <Product>();
            MechanicalKeyboard p1   = new MechanicalKeyboard("Poker3", 1500, EKeyboardSize.Tenkeyless, true, ESwitchColor.CherryBlue);
            Thinkpad           p2   = new Thinkpad("T420", 2000, EScreenSize.LargeScreen, 1, true);

            list.Add(p1);
            list.Add(p2);
            // Cargamos el diccionario de materiales (de la clase Materials) con los nombres de los
            // atributos de c/tipo de objeto y un valor random
            Factory.stock.LoadMaterialsNeeded(p1);
            Factory.stock.LoadMaterialsNeeded(p2);
            // Aumentamos el stock que se necesita para crear c/producto
            Factory.LoadMoreStock(p1);
            Factory.LoadMoreStock(p2);
            // Mostramos Stock Inicial
            Console.WriteLine("Consulto Stock (1) \n\n" + Factory.StockInfo());
            try
            {
                // Intentamos agregar 2 productos
                // Cuando se testea agregar productos ESTAR atentos al LoadMoreStock y su random interno
                // si es muy chico habra que llamarlo varias veces
                // A modo de prueba se puede cambiar su random a uno mayor
                Factory.Create = new Thinkpad("T420", 2500, EScreenSize.MediumScreen, 1, true);
                Factory.Create = new MechanicalKeyboard("Poker3", 1500, EKeyboardSize.Tenkeyless, false, ESwitchColor.CherryBlue);
                Console.WriteLine("Primeros 2 productos (1) \n\n" + Factory.ProductsInfo() + "\n\n");
            }
            catch (OutOfStockException ex)
            {
                Console.WriteLine($"No hay stock suficiente (1) ", ex.Message);
            }
            try
            {
                Factory.Create = new MechanicalKeyboard("Qisan Magicforce", 1150, EKeyboardSize.Small, true, ESwitchColor.GateronClear);
                Factory.Create = new MechanicalKeyboard("Das Keyboard 100", 1790, EKeyboardSize.Small, false, ESwitchColor.GateronBrown);
                Console.WriteLine("Se agregan 2 productos mas (2) \n\n" + Factory.ProductsInfo() + "\n\n");
            }
            catch (OutOfStockException ex)
            {
                Console.WriteLine("No hay stock suficiente (2) ", ex.Message);
                sinStock = true;
            }

            if (sinStock)
            {
                Factory.LoadMoreStock(p1);
            }
            try
            {
                Factory.Create = new MechanicalKeyboard("Das Keyboard 100", 2655, EKeyboardSize.FullSize, false, ESwitchColor.CherryRed);
                Factory.Create = new Thinkpad("T430", 2500, EScreenSize.LargeScreen, 1, true);
                Console.WriteLine("Se agregan mas productos (3) \n\n" + Factory.ProductsInfo() + "\n\n");
            }
            catch (OutOfStockException ex)
            {
                Console.WriteLine("Te quedaste sin stock (3) ", ex.Message);
            }

            Console.WriteLine("Consulto Stock (2) \n\n" + Factory.StockInfo());

            //PROBAMOS SERIALIZACION
            try
            {
                // Corroboramos que la lista de productos sea mayor a 0
                // Si no lo es, lanzamos excepcion
                if (!(Factory.listaProductos.Count > 0))
                {
                    throw new NoProductCreatedException("Stock is empty, nothing to be serialized\nGo build some");
                }
                string path = AppDomain.CurrentDomain.BaseDirectory + "ProductsList.xml";
                Serializator <List <Product> > toXml = new Serializator <List <Product> >();
                toXml.Save(path, Factory.listaProductos);
                Console.WriteLine($"XML file created successfully at {AppDomain.CurrentDomain.BaseDirectory}");
            }
            catch (NoProductCreatedException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            /*
             *
             *
             *              PROBAMOS CREACION DE PRODUCTOS Y EXCEPCIONES
             *
             *
             */

            // ATENCION - LA MAYORIA DE LA PRUEBAS QUE RESULTAN SIN STOCK ES DEBIDO A LOS TECLADOS QUE CONSUMEN
            // MUCHAS KEYCAPS Y MUCHOS SWTICHES, TENER EN CUENTA Y AGREGAR STOCK CONTINUO PARA PROBAR
            bool sinStock = false;
            // creamos 2 objetos.
            MechanicalKeyboard p1 = new MechanicalKeyboard("Poker3", 1500, EKeyboardSize.Tenkeyless, true, ESwitchColor.CherryBlue);
            Thinkpad           p2 = new Thinkpad("Thinkpad T420", 2000, EScreenSize.LargeScreen, 1, true);

            // Cargamos el diccionario de materiales (de la clase Materials) con los nombres de los
            // atributos de c/tipo de objeto y un valor random
            Factory.stock.LoadMaterialsNeeded(p1);
            Factory.stock.LoadMaterialsNeeded(p2);
            // Aumentamos el stock que se necesita para crear c/producto
            LoadStock(p1, p2);
            // Mostramos Stock Inicial
            CheckStock(1);
            try
            {
                // Intentamos agregar 2 productos
                // Cuando se testea agregar productos ESTAR atentos al LoadMoreStock y su random interno
                // si es muy chico habra que llamarlo varias veces
                // A modo de prueba se puede cambiar su random a uno mayor
                Factory.Create = new Thinkpad("Thinkpad T420", 2500, EScreenSize.MediumScreen, 1, true);
                Factory.Create = new MechanicalKeyboard("Poker3", 1500, EKeyboardSize.Tenkeyless, false, ESwitchColor.CherryBlue);
                Console.WriteLine("Se agregan 2 productos (1)" + Factory.ProductsInfo());
            }
            catch (OutOfStockException ex)
            {
                sinStock = true;
                Console.WriteLine($"No hay stock suficiente (1) ", ex.Message);
            }
            try
            {
                Factory.Create = new MechanicalKeyboard("Qisan Magicforce", 1150, EKeyboardSize.Small, true, ESwitchColor.GateronClear);
                Factory.Create = new MechanicalKeyboard("Das Keyboard 100", 1790, EKeyboardSize.Small, false, ESwitchColor.GateronBrown);
                Console.WriteLine("Se agregan 2 productos (2)" + Factory.ProductsInfo());
            }
            catch (OutOfStockException ex)
            {
                sinStock = true;
                Console.WriteLine("No hay stock suficiente (2) ", ex.Message);
            }

            if (sinStock)
            {
                LoadStock(p1, p2);
                sinStock = false;
            }
            CheckStock(2);
            try
            {
                Factory.Create = new MechanicalKeyboard("Das Keyboard 100", 2655, EKeyboardSize.FullSize, false, ESwitchColor.CherryRed);
                Factory.Create = new Thinkpad("Thinkpad T430", 2500, EScreenSize.LargeScreen, 1, true);
                Console.WriteLine("Se agregan 2 productos (3)" + Factory.ProductsInfo());
            }
            catch (OutOfStockException ex)
            {
                Console.WriteLine("Te quedaste sin stock (3) ", ex.Message);
            }
            CheckStock(3);

            /*
             *
             *
             *              PROBAMOS SERIALIZACION
             *
             *
             */
            Console.WriteLine("\n@@@@@@ SE PRUEBA SERIALIZACION @@@@@\n");
            try
            {
                // Corroboramos que la lista de productos sea mayor a 0
                // Si no lo es, lanzamos excepcion
                DateTime currentDate = new DateTime();
                currentDate = DateTime.Now;
                if (!(Factory.listaProductos.Count > 0))
                {
                    throw new NoProductCreatedException("Stock is empty, nothing to be serialized\nGo build some");
                }
                string path = AppDomain.CurrentDomain.BaseDirectory + "ProductsList - " + currentDate.ToString("-MMddyyyy_HHmmss") + ".xml";
                Serializator <List <Product> > toXml = new Serializator <List <Product> >();
                toXml.SaveXML(path, Factory.listaProductos);
                Console.WriteLine($"XML file created successfully at {AppDomain.CurrentDomain.BaseDirectory}");
            }
            catch (NoProductCreatedException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if (sinStock)
            {
                LoadStock(p1, p2);
                sinStock = false;
            }
            CheckStock(4);
            try
            {
                Factory.Create = new MechanicalKeyboard("Das Keyboard 100", 2655, EKeyboardSize.FullSize, false, ESwitchColor.CherryRed);
                Factory.Create = new Thinkpad("Thinkpad T430", 2500, EScreenSize.LargeScreen, 1, true);
                Factory.Create = new Thinkpad("Thinkpad T450", 3500, EScreenSize.LargeScreen, 1, true);
                Console.WriteLine("Se agregan 2 productos (4)" + Factory.ProductsInfo());
            }
            catch (OutOfStockException ex)
            {
                sinStock = true;
                Console.WriteLine("Te quedaste sin stock (4) ", ex.Message);
            }
            CheckStock(5);

            /*
             *
             *
             *              PROBAMOS GUARDAR EN DB
             *
             *
             */
            Console.WriteLine("\n@@@@@@ SE PRUEBA BASE DATOS @@@@@\n");
            string        notebookQuery      = null;
            string        keyboardQuery      = null;
            List <string> thinkpadProperties = null;
            List <string> keyboardProperties = null;

            if (Factory.listaProductos.Count > 0)
            {
                if (Factory.listaProductos.ContainsType("Thinkpad")) // metodo de extension
                {
                    thinkpadProperties = Factory.GetProperties(Factory.listaProductos, "Thinkpad");
                    notebookQuery      = SQL <Thinkpad> .BuildInsertQuery(thinkpadProperties, "Notebooks");
                }
                if (Factory.listaProductos.ContainsType("MechanicalKeyboard")) // metodo de extension
                {
                    keyboardProperties = Factory.GetProperties(Factory.listaProductos, "MechanicalKeyboard");
                    keyboardQuery      = SQL <MechanicalKeyboard> .BuildInsertQuery(keyboardProperties, "Keyboards");
                }
                try
                {
                    List <Product> temp = new List <Product>(Factory.listaProductos);
                    foreach (Product item in temp)
                    {
                        if (item is Thinkpad)
                        {
                            SQL <Thinkpad> .Insert(notebookQuery, thinkpadProperties, (Thinkpad)item);
                        }
                        if (item is MechanicalKeyboard)
                        {
                            SQL <MechanicalKeyboard> .Insert(keyboardQuery, keyboardProperties, (MechanicalKeyboard)item);
                        }
                        Factory.listaProductos.Remove(item);
                    }
                    Console.WriteLine("Product/s successfully save to DB. Stock emptied");
                }
                catch (InvalidQueryException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                Console.WriteLine("Stock is empty, nothing to save on DB\nGo build some");
            }

            /*
             *
             *
             *              PROBAMOS CONSULTAS BD
             *
             *
             */

            Console.WriteLine("\n@@@@@@ SE PRUEBA CONSULTAS A DATOS @@@@@\n");
            List <Product> listN = null;
            List <Product> listK = null;

            try
            {
                listN = SQL <Product> .QueryBD("SELECT * from Notebooks");

                listK = SQL <Product> .QueryBD("SELECT * from Keyboards");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                Console.WriteLine("\n@@@@@@ TABLA: NOTEBOOKS @@@@@\n");
                if (listN != null && listN.Count > 0)
                {
                    foreach (Product item in listN)
                    {
                        Console.WriteLine(item.ToString());
                    }
                }

                Console.WriteLine("\n@@@@@@ TABLA: TECLADOS @@@@@\n");
                if (listK != null && listK.Count > 0)
                {
                    foreach (Product item in listK)
                    {
                        Console.WriteLine(item.ToString());
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine("OJO, LISTA NULA. CHEQUEAR" + ex.Message);
            }


            Console.WriteLine("FINAL DE LA CLASE TEST");
            Console.ReadKey();
        }
示例#5
0
    //sementara masih gagal
    #region Custom Binary Files
    //public static void SaveProject(MechanicalKeyboard mechanicalKeyboard, string projectName)
    public static void SaveProject(MechanicalKeyboard mechanicalKeyboard, string filepath)
    {
        BinaryFormatter bf = new BinaryFormatter();
        //FileStream stream = new FileStream(Application.persistentDataPath + "/" + projectName + ".sav", FileMode.Create);
        //FileStream stream = new FileStream(Application.persistentDataPath + "/MechanicalKeyboard.sav", FileMode.Create);
        FileStream stream = new FileStream(filepath, FileMode.Create);

        MechanicalKeyboardData data = new MechanicalKeyboardData(mechanicalKeyboard);

        //int keySwitch = int.Parse(mechanicalKeyboard.checkLayout().ToString());

        // keycaps
        //data.materials[0] = new string[keySwitch][];

        // 0 = keyboard's name; 1 = keycap's name; 2 = keycaps; 3 = cases; 4 = switches;

        //data.materials[0] = new string[1][];
        //data.materials[0][0] = new string[1];
        //data.materials[0][0][0] = mechanicalKeyboard.keyboardName;

        //data.materials[1] = new string[1][];
        //data.materials[1][0] = new string[1];
        //data.materials[1][0][0] = mechanicalKeyboard.keycapsProfile;

        ////for (int i = 0; i < keySwitch; i++)
        //for (int i = 0; i < mechanicalKeyboard.keycapsMaterial.Length; i++)
        //{
        //    //data.materials[0][i] = new string[2];
        //    //data.materials[0][i][0] = mechanicalKeyboard.keycapsMaterial[i][0];
        //    //data.materials[0][i][1] = null;

        //    //if (mechanicalKeyboard.keycapsMaterial[i][1] != null)
        //    //{
        //    //    data.materials[0][i][1] = mechanicalKeyboard.keycapsMaterial[i][1];
        //    //}
        //    data.materials[2] = new string[mechanicalKeyboard.keycapsMaterial.Length][];

        //    for (int j = 0; j < mechanicalKeyboard.keycapsMaterial[i].Length; j++)
        //    {
        //        data.materials[2][i] = new string[mechanicalKeyboard.keycapsMaterial[i].Length];
        //        data.materials[2][i][j] = mechanicalKeyboard.keycapsMaterial[i][j].name;
        //    }
        //}

        //// cases
        ////data.materials[1] = new string[1][];
        ////data.materials[1][0] = new string[1];
        ////data.materials[1][0][1] = mechanicalKeyboard.casesMaterial;
        //data.materials[3] = new string[1][];
        //data.materials[3][0] = new string[1];
        //data.materials[3][0][0] = mechanicalKeyboard.caseMaterial.name;

        //// switches
        ////data.materials[2] = new string[keySwitch][];
        //data.materials[4] = new string[mechanicalKeyboard.switchesMaterial.Length][];

        ////for (int i = 0; i < keySwitch; i++)
        //for (int i = 0; i < mechanicalKeyboard.switchesMaterial.Length; i++)
        //{
        //    //data.materials[2][i] = new string[3];
        //    //data.materials[2][i][0] = mechanicalKeyboard.switchesMaterial[i][0];
        //    //data.materials[2][i][1] = mechanicalKeyboard.switchesMaterial[i][1];
        //    //data.materials[2][i][2] = mechanicalKeyboard.switchesMaterial[i][2];
        //    data.materials[4][i] = new string[mechanicalKeyboard.switchesMaterial[i].Length];

        //    for (int j = 0; j < mechanicalKeyboard.switchesMaterial[i].Length; j++)
        //    {
        //        data.materials[4][i][j] = mechanicalKeyboard.switchesMaterial[i][j].name;
        //    }
        //}

        bf.Serialize(stream, data);
        stream.Close();
    }
示例#6
0
    public MechanicalKeyboardData(MechanicalKeyboard mechanicalKeyboard)
    {
        //materials = new string[3][][];
        //materials = new string[4][][];
        materials = new string[5][][];

        // ARRAY PERTAMA
        //for (int i = 0; i <= materials.GetLength(0); i++) // 0 = keycaps; 1 = cases; 2 = switches;
        for (int i = 0; i <= materials.Length; i++) // 0 = keyboard's name; 1 = keycap's profile; 2 = keycaps; 3 = cases; 4 = switches;
        {
            // U/ Nama Keyboard
            if (i == 0)
            {
                materials[i]       = new string[1][];
                materials[i][0]    = new string[1];
                materials[i][0][0] = mechanicalKeyboard.keyboardName;
            }

            // U/ Keycaps Profile
            else if (i == 1)
            {
                materials[i]       = new string[1][];
                materials[i][0]    = new string[1];
                materials[i][0][0] = mechanicalKeyboard.keycapsProfile;
            }

            // U/ CASES
            //if (i == 1)
            else if (i == 3)
            {
                materials[i]    = new string[1][];
                materials[i][0] = new string[1];
                //materials[i][0][0] = mechanicalKeyboard.caseMaterial.name;
                materials[i][0][0] = mechanicalKeyboard.caseMaterial;
            }

            //else if (i == 0 || i == 2)
            else if (i == 2 || i == 4)
            {
                // ARRAY KEDUA U/ KEYCAPS (0) & SWITCHES (2)
                //Debug.Log(materials.GetLength(0));
                //for (int j = 0; j <= materials.GetLength(1); j++) // ERROR: array index is out of range
                //Debug.Log(mechanicalKeyboard.checkLayout());
                //if (i == 0) // KEYCAPS (0)
                if (i == 2) // KEYCAPS (2)
                {
                    //materials[i] = new string[mechanicalKeyboard.checkLayout()][];
                    materials[i] = new string[mechanicalKeyboard.keycapsMaterial.Length][];
                    for (int j = 0; j < mechanicalKeyboard.keycapsMaterial.Length; j++)
                    {
                        //Debug.Log(mechanicalKeyboard.keycapsMaterial[j].Length); // JALAN
                        materials[i][j] = new string[mechanicalKeyboard.keycapsMaterial[j].Length];
                        for (int k = 0; k < mechanicalKeyboard.keycapsMaterial[j].Length; k++)
                        {
                            //materials[i][j][k] = mechanicalKeyboard.keycapsMaterial[j][k].name;
                            materials[i][j][k] = mechanicalKeyboard.keycapsMaterial[j][k];
                        }
                    }
                }
                else if (i == 4) // SWITCHES (4)
                {
                    //Debug.Log(mechanicalKeyboard.switchesMaterial.Length); // JALAN
                    materials[i] = new string[mechanicalKeyboard.switchesMaterial.Length][]; // ERROR: Array index is out of range
                    for (int j = 0; j < mechanicalKeyboard.switchesMaterial.Length; j++)
                    {
                        materials[i][j] = new string[mechanicalKeyboard.switchesMaterial[j].Length];
                        for (int k = 0; k < mechanicalKeyboard.switchesMaterial[j].Length; k++)
                        {
                            //materials[i][j][k] = mechanicalKeyboard.switchesMaterial[j][k].name;
                            materials[i][j][k] = mechanicalKeyboard.switchesMaterial[j][k];
                        }
                    }
                }

                //for (int j = 0; j <= materials[i].Length; j++)
                //{
                //    //materials[i] = new string[mechanicalKeyboard.checkLayout()][];

                //    //if (i == 0) // KEYCAPS (0)
                //    if (i == 2) // KEYCAPS (2)
                //    {
                //        //materials[i][j] = new string[2];
                //        //Debug.Log(mechanicalKeyboard.keycapsMaterial[i]);
                //        //materials[i][j][0] = mechanicalKeyboard.keycapsMaterial[i][0]; // Object reference not set to an instance of an object
                //        //materials[i][j][1] = null;
                //        //if (mechanicalKeyboard.keycapsMaterial[i][1] != null)
                //        //{
                //        //    materials[i][j][1] = mechanicalKeyboard.keycapsMaterial[i][1];
                //        //}
                //        materials[i][j] = new string[mechanicalKeyboard.keycapsMaterial[j].Length]; // object is not set to an instance of an object
                //        for (int k = 0; k < mechanicalKeyboard.keycapsMaterial[j].Length; k++)
                //        {
                //            materials[i][j][k] = mechanicalKeyboard.keycapsMaterial[j][k].name;
                //        }
                //    }

                //    //else if (i == 2) // SWITCHES (2)
                //    else if (i == 4) // SWITCHES (4)
                //    {
                //        //materials[i][j] = new string[3];
                //        //materials[i][j][0] = mechanicalKeyboard.switchesMaterial[i][0];
                //        //materials[i][j][1] = mechanicalKeyboard.switchesMaterial[i][1];
                //        //materials[i][j][2] = mechanicalKeyboard.switchesMaterial[i][2];
                //        materials[i][j] = new string[mechanicalKeyboard.switchesMaterial[j].Length];
                //        for (int k = 0; k < mechanicalKeyboard.switchesMaterial[j].Length; k++)
                //        {
                //            materials[i][j][k] = mechanicalKeyboard.switchesMaterial[j][k].name;
                //        }
                //    }
                //}
            }
        }
    }