コード例 #1
0
        public async void GetRamByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetRamByNameDatabase")
                          .Options;
            var ram1 = new Rams {
                Name = "test name1", Speed = "1700 Mghrtz", Size = "8GB", Price = 110.99M
            };
            var ram2 = new Rams {
                Name = "test name2", Speed = "1900 Mghrtz", Size = "16GB", Price = 150.99M
            };

            Ram ram = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(ram1);
                context.Add(ram2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                ram = await service.GetRamByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal("1700 Mghrtz", ram.Speed);
                Assert.Equal("8GB", ram.Size);
                Assert.Equal(110.99M, ram.Price);
            }
        }
コード例 #2
0
        public async void GetGraphicsCardsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetGraphicscardsFromDatabase")
                          .Options;
            var graphicscard = new GraphicsCards {
                Name = "test name", Speed = "1700 Mghz", Size = "8GB", Price = 300.99M
            };
            List <GraphicsCard> listofgraphicscards = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(graphicscard);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofgraphicscards = await service.GetGraphicsCards();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofgraphicscards);
                Assert.Equal("test name", context.GraphicsCards.Single().Name);
            }
        }
コード例 #3
0
        public async void GetHardDrivesFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetHardDrivesFromDatabase")
                          .Options;
            var harddrive = new HardDrives {
                Name = "test name", Category = "SSD", Size = "500GB", Speed = "7200RPM", Price = 100.99M
            };
            List <HardDrive> listofharddrives = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(harddrive);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofharddrives = await service.GetHardDrives();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofharddrives);
                Assert.Equal("test name", context.HardDrives.Single().Name);
            }
        }
コード例 #4
0
        public async void GetCustomersFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetCustomersFromDatabase")
                          .Options;
            var customer = new Customers {
                CustomerName = "test name", Address = "test address", UserName = "******"
            };
            List <Customer> listofcustomers = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(customer);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofcustomers = await service.GetCustomers();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofcustomers);
                Assert.Equal("test name", context.Customers.Single().CustomerName);
            }
        }
コード例 #5
0
        public async void GetCpusByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCaseByNameDatabase")
                          .Options;
            var cpu1 = new Cpus {
                Name = "test name1", Cores = 4, Speed = "3.4Ghz", Price = 90.99M
            };
            var cpu2 = new Cpus {
                Name = "test name2", Cores = 4, Speed = "3.6Ghz", Price = 100.99M
            };


            Cpu cpu = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(cpu1);
                context.Add(cpu2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                cpu = await service.GetCpuByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal(4, cpu.Cores);
                Assert.Equal("3.4Ghz", cpu.Speed);
                Assert.Equal(90.99M, cpu.Price);
            }
        }
コード例 #6
0
        public async void GetRAMsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetRamsFromDatabase")
                          .Options;
            var ram = new Rams {
                Name = "test name", Speed = "2600Mhrtz", Size = "16GB", Price = 300.99M
            };
            List <Ram> listoframs = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(ram);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listoframs = await service.GetRams();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listoframs);
                Assert.Equal("test name", context.Rams.Single().Name);
            }
        }
コード例 #7
0
        public async void GetCPUsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetCpusFromDatabase")
                          .Options;
            var cpu = new Cpus {
                Name = "test name", Speed = "3.6 Ghtz", Cores = 6, Price = 413.99M
            };
            List <Cpu> listofcpus = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(cpu);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofcpus = await service.GetCpus();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofcpus);
                Assert.Equal("test name", context.Cpus.Single().Name);
            }
        }
コード例 #8
0
        public async void GetComputerCaseByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCaseByNameDatabase")
                          .Options;
            var computercase1 = new ComputerCases {
                Name = "test name1", Size = "Mid Tower", Price = 90.99M
            };
            var computercase2 = new ComputerCases {
                Name = "test name2", Size = "Full Tower", Price = 105.99M
            };

            ComputerCase computercase = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(computercase1);
                context.Add(computercase2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                computercase = await service.GetComputerCaseByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal("Mid Tower", computercase.Size);
                Assert.Equal(90.99M, computercase.Price);
            }
        }
コード例 #9
0
        public async void GetComputerCasesFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCasesFromDatabase")
                          .Options;
            var computercase = new ComputerCases {
                Name = "test name", Size = "Mid Tower", Price = 79.99M
            };
            List <ComputerCase> listofcomputercases = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(computercase);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofcomputercases = await service.GetComputerCases();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofcomputercases);
                Assert.Equal("test name", context.ComputerCases.Single().Name);
            }
        }
コード例 #10
0
        public async void GetInventorysFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetCustomersFromDatabase")
                          .Options;
            var inventory = new Inventorys {
                Name = "test product", Quantity = 30, Category = "CPUs", Price = 139.99M
            };
            List <Inventory> listofinventorys = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(inventory);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofinventorys = await service.GetInventory();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofinventorys);
                Assert.Equal("test product", context.Inventorys.Single().Name);
            }
        }
コード例 #11
0
        public async void GetPowerSupplysFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetPowerSupplysFromDatabase")
                          .Options;
            var powersupply = new PowerSupplys {
                Name = "test name", Modular = false, Price = 129.99M
            };
            List <PowerSupply> listofpowersupplys = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(powersupply);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofpowersupplys = await service.GetPowerSupplys();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofpowersupplys);
                Assert.Equal("test name", context.PowerSupplys.Single().Name);
            }
        }
コード例 #12
0
        public async void GetInventoryByCategoryTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetInventoryByCategoryDatabase")
                          .Options;
            var inventory1 = new Inventorys {
                Name = "test name1", Quantity = 30, Category = "CPU", Price = 129.99M
            };
            var inventory2 = new Inventorys {
                Name = "test name2", Quantity = 50, Category = "HardDrive", Price = 129.99M
            };

            List <Inventory> listofinventorys = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(inventory1);
                context.Add(inventory2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofinventorys = await service.GetInventoryByCategory("CPU");
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofinventorys);
                Assert.Equal("test name1", listofinventorys.First().Name);
            }
        }
コード例 #13
0
        public async void GetMotherBoardsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetMotherBoardsFromDatabase")
                          .Options;
            var motherboard = new MotherBoards {
                Name = "test name", FormFactor = "ATX", Pcislots = 4, Ramslots = 4, Price = 150.99M
            };
            List <MotherBoard> listofmotherboards = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(motherboard);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofmotherboards = await service.GetMotherBoards();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofmotherboards);
                Assert.Equal("test name", context.MotherBoards.Single().Name);
            }
        }
コード例 #14
0
        public async void GetCustomerByUserNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCaseByNameDatabase")
                          .Options;
            var Cust1 = new Customers {
                CustomerName = "test name1", Address = "Test address1", UserName = "******"
            };
            var Cust2 = new Customers {
                CustomerName = "test name2", Address = "Test address2", UserName = "******"
            };


            Customer cust = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(Cust1);
                context.Add(Cust2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                cust = await service.GetCustomerByUserName("testusername1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal("test name1", cust.CustomerName);
                Assert.Equal("Test address1", cust.Address);
            }
        }
コード例 #15
0
        public ActionResult Storage(int computerId)
        {
            var cr  = new ComputerRepo(new ComputerMssql());
            var mr  = new StorageRepo(new StorageMssql());
            var svm = new StorageViewModel(cr.GetById(computerId), mr.GetAll());

            return(View(svm));
        }
コード例 #16
0
        public ActionResult Memory(int computerId)
        {
            var cr  = new ComputerRepo(new ComputerMssql());
            var mr  = new MemoryRepo(new MemoryMssql());
            var mvm = new MemoryViewModel(cr.GetById(computerId), mr.GetAll());

            return(View(mvm));
        }
コード例 #17
0
        public ActionResult Motherboard(int computerId)
        {
            var cr  = new ComputerRepo(new ComputerMssql());
            var mb  = new MotherboardRepo(new MotherboardMssql());
            var mvm = new MotherboardViewModel(cr.GetById(computerId), mb.GetAll());

            return(View(mvm));
        }
コード例 #18
0
        // GET: Part
        public ActionResult Cpu(int computerId)
        {
            var cr  = new ComputerRepo(new ComputerMssql());
            var cp  = new CpuRepo(new CpuMssql());
            var cvm = new CpuViewModel(cr.GetById(computerId), cp.GetAll());

            return(View(cvm));
        }
コード例 #19
0
        public ActionResult Gpu(int computerId, int selectedGpu)
        {
            var cr  = new ComputerRepo(new ComputerMssql());
            var gr  = new GpuRepo(new GpuMssql());
            var gvm = new GpuViewModel(cr.GetById(computerId), gr.GetAll(), selectedGpu);

            return(View(gvm));
        }
コード例 #20
0
        public ActionResult EditCpu(int computerId, int cpuId)
        {
            var cr       = new ComputerRepo(new ComputerMssql());
            var cp       = new CpuRepo(new CpuMssql());
            var editedPc = cr.GetById(computerId);

            editedPc.Cpu = cp.GetById(cpuId);
            cr.Update(editedPc);
            return(RedirectToAction("EditBuild", "Build", new { computerId }));
        }
コード例 #21
0
        public ActionResult EditStorage(int computerId, int storageId)
        {
            var cr       = new ComputerRepo(new ComputerMssql());
            var sr       = new StorageRepo(new StorageMssql());
            var editedPc = cr.GetById(computerId);

            editedPc.Storage = sr.GetById(storageId);
            cr.Update(editedPc);
            return(RedirectToAction("EditBuild", "Build", new { computerId }));
        }
コード例 #22
0
        public ActionResult EditMemory(int computerId, int memoryId)
        {
            var cr       = new ComputerRepo(new ComputerMssql());
            var mr       = new MemoryRepo(new MemoryMssql());
            var editedPc = cr.GetById(computerId);

            editedPc.Memory = mr.GetById(memoryId);
            cr.Update(editedPc);
            return(RedirectToAction("EditBuild", "Build", new { computerId }));
        }
コード例 #23
0
        public ActionResult EditMotherBoard(int computerId, int motherboardId)
        {
            var cr       = new ComputerRepo(new ComputerMssql());
            var mb       = new MotherboardRepo(new MotherboardMssql());
            var editedPc = cr.GetById(computerId);

            editedPc.Motherboard = mb.GetById(motherboardId);
            cr.Update(editedPc);
            return(RedirectToAction("EditBuild", "Build", new { computerId }));
        }
コード例 #24
0
ファイル: User.cs プロジェクト: dandeman111/PcPartPicker
        //constructor
        public User(string username, string password, string email, List <int> computers)
        {
            Computers = new List <Computer>();
            var cr = new ComputerRepo(new ComputerMssql());

            Username = username;
            Password = password;
            Email    = email;
            foreach (var x in computers)
            {
                Computers.Add(cr.GetById(x));
            }
        }
コード例 #25
0
        public ActionResult EditGpu(int computerId, int gpuId, int currentGpu)
        {
            var cr       = new ComputerRepo(new ComputerMssql());
            var gr       = new GpuRepo(new GpuMssql());
            var editedPc = cr.GetById(computerId);

            for (var i = 0; i < editedPc.Gpus.Count; i++)
            {
                if (editedPc.Gpus[i].GpuId == currentGpu)
                {
                    editedPc.Gpus[i] = gr.GetById(gpuId);
                }
            }
            cr.Update(editedPc);
            return(RedirectToAction("EditBuild", "Build", new { computerId }));
        }
コード例 #26
0
        public ActionResult SaveBuild()
        {
            var pc = (Computer)Session["CurrentBuild"];
            var cr = new ComputerRepo(new ComputerMssql());

            try
            {
                cr.Add(pc, Session["Username"].ToString());
                Session["CurrentBuild"] = new Computer();
            }
            catch (NullReferenceException x)
            {
                return(RedirectToAction("MissingParts", "Error"));
            }

            return(RedirectToAction("NewBuild", "Build"));
        }
コード例 #27
0
        public async void AddCustomerToDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "AddCustomersFromDatabase")
                          .Options;


            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                service.AddCustomer(new Customer {
                    CustomerName = "test name", Address = "test address", UserName = "******"
                });
                await service.Save();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Equal(1, context.Customers.Count());
                Assert.Equal("test name", context.Customers.Single().CustomerName);
            }
        }
コード例 #28
0
 // GET: api/ComputerCases
 public ComputerCasesController(ComputerRepo _repo)
 {
     repo = _repo;
 }
コード例 #29
0
 public PowerSupplysController(ComputerRepo _repo)
 {
     repo = _repo;
 }
コード例 #30
0
 public CustomersController(ComputerRepo _repo)
 {
     repo = _repo;
 }