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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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)); }
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)); }
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)); }
// 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)); }
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)); }
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 })); }
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 })); }
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 })); }
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 })); }
//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)); } }
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 })); }
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")); }
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); } }
// GET: api/ComputerCases public ComputerCasesController(ComputerRepo _repo) { repo = _repo; }
public PowerSupplysController(ComputerRepo _repo) { repo = _repo; }
public CustomersController(ComputerRepo _repo) { repo = _repo; }