Ejemplo n.º 1
0
        public Computer Generate()
        {
            var db     = new ComputersDbEntities();
            var cpuIds = db.CPUs
                         .Select(c => c.Id)
                         .ToArray();
            var storageDevices = db.StorageDevices.ToArray();
            var gpus           = db.GPUs.ToArray();

            var computer = new Computer
            {
                Type   = ComputerTypes[random.Next(0, ComputerTypes.Length)],
                Vendor = ComputerVendors[random.Next(0, ComputerVendors.Length)],
                Model  = ComputerModels[random.Next(0, ComputerModels.Length)],
                CPUId  = cpuIds[random.Next(0, cpuIds.Length)],
                RAM    = ComputerRAMList[random.Next(0, ComputerRAMList.Length)],
            };

            db.SaveChanges();
            db.Dispose();

            for (int i = 0; i < 2; i++)
            {
                computer.StorageDevices.Add(storageDevices[random.Next(0, storageDevices.Length)]);
                computer.GPUs.Add(gpus[random.Next(0, gpus.Length)]);
            }

            return(computer);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var gpuGenerator      = new GPUsGenerator();
            var cpuGenerator      = new CPUsGenerator();
            var sdGenerator       = new StorageDevicesGenerator();
            var computerGenerator = new ComputersGenerator();
            var db = new ComputersDbEntities();

            for (int i = 0; i < 15; i++)
            {
                db.GPUs.Add(gpuGenerator.Generate());
                Console.Write(".");
            }
            Console.WriteLine();

            for (int i = 0; i < 10; i++)
            {
                db.CPUs.Add(cpuGenerator.Generate());
                Console.Write(".");
            }
            Console.WriteLine();

            for (int i = 0; i < 30; i++)
            {
                db.StorageDevices.Add(sdGenerator.Generate());
                Console.Write(".");
            }
            Console.WriteLine();

            db.SaveChanges();

            for (int i = 0; i < 50; i++)
            {
                db.Computers.Add(computerGenerator.Generate());
                Console.Write(".");
            }
            Console.WriteLine();

            db.SaveChanges();
        }