コード例 #1
0
        public void Test_CreateOrder()
        {
            var options = new DbContextOptionsBuilder <OrderContext>()
                          .UseInMemoryDatabase(databaseName: "TestDb21")
                          .Options;
            var options1 = new DbContextOptionsBuilder <StoreContext>()
                           .UseInMemoryDatabase(databaseName: "TestDb21")
                           .Options;
            var options2 = new DbContextOptionsBuilder <CustomerContext>()
                           .UseInMemoryDatabase(databaseName: "TestDb21")
                           .Options;

            using (var context = new OrderContext(options))
            {
                using (var context1 = new StoreContext(options1))
                {
                    using (var context2 = new CustomerContext(options2))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                        context1.Database.EnsureDeleted();
                        context1.Database.EnsureCreated();
                        context2.Database.EnsureDeleted();
                        context2.Database.EnsureCreated();

                        OrderRepository    orderRepo = new OrderRepository(context);
                        StoreRepository    storeRepo = new StoreRepository(context1);
                        CustomerRepository custRepo  = new CustomerRepository(context2);
                        OrderLogic         ol        = new OrderLogic(orderRepo, storeRepo, custRepo);

                        AStore          store       = new AStore();
                        Customer        newCust     = new Customer();
                        ItemType        item        = new ItemType("toppings");
                        APizzaComponent testCrust   = new APizzaComponent("testcrust", item);
                        APizzaComponent testTopping = new APizzaComponent("testtopping", item);
                        APizzaComponent testSize    = new APizzaComponent("testsize", item);
                        Crust           tempCrust   = new Crust(store, 0, 1, testCrust);
                        Topping         tempTopping = new Topping(store, 0, 1, testTopping);
                        Size            tempSize    = new Size(store, 0, 1, testSize);

                        context1.Add <AStore>(store);
                        context2.Add <Customer>(newCust);
                        context1.Add <ItemType>(item);
                        context1.Add <APizzaComponent>(testCrust);
                        context1.Add <APizzaComponent>(testTopping);
                        context1.Add <APizzaComponent>(testSize);
                        context1.Add <Crust>(tempCrust);
                        context1.Add <Topping>(tempTopping);
                        context1.Add <Size>(tempSize);
                        context.SaveChanges();
                        context1.SaveChanges();
                        context2.SaveChanges();

                        RawPizza rawTest = new RawPizza();
                        rawTest.Name     = "Test Pizza";
                        rawTest.Price    = 0;
                        rawTest.Crust    = "testcrust";
                        rawTest.Size     = "testsize";
                        rawTest.Toppings = new List <string>();
                        rawTest.Toppings.Add("testtopping");

                        RawOrder newOrder = new RawOrder();
                        newOrder.PizzaList  = new List <RawPizza>();
                        newOrder.StoreID    = store.StoreID;
                        newOrder.CustomerID = newCust.CustomerID;
                        newOrder.Total      = 0;
                        newOrder.PizzaList.Add(rawTest);

                        Order createOrder = ol.CreateOrder(newOrder);
                        Assert.NotNull(createOrder);
                    }
                }
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("SellerID,ProductIDsText,ProductQuantityText")] CreateSaleViewModel sv)
        {
            if (string.IsNullOrEmpty(sv.ProductIDsText) || !sv.CastVariables())
            {
                return(View("GeneralError", new GeneralErrorViewModel {
                    Text = "დაფიქსირდა შეცდომა მონაცემების დამუშავებისას!"
                }));
            }

            if (sv.ProductIDs is null || sv.ProductIDs.Count == 0)
            {
                return(View("GeneralError", new GeneralErrorViewModel {
                    Text = "თქვენ არ გაქვთ არჩეული პროდუქტი!"
                }));
            }

            Sale sale = new Sale();

            var consultant = _context.Consultants.FirstOrDefault(c => c.ID == sv.SellerID);

            if (consultant == null)
            {
                return(View("GeneralError", new GeneralErrorViewModel {
                    Text = "კონსულტანტი ვერ მოიძებნა!"
                }));
            }



            List <SaleItem> saleItems = new List <SaleItem>();



            var   products   = _context.Products.Where(p => sv.ProductIDs.Contains(p.ID)).ToList();
            float totalPrice = 0;

            for (int i = 0; i < sv.ProductIDs.Count; i++)
            {
                var prod = products.FirstOrDefault(p => p.ID == sv.ProductIDs[i]);

                saleItems.Add(new SaleItem()
                {
                    Code     = prod.Code,
                    Price    = prod.Price,
                    Title    = prod.Title,
                    Quantity = sv.ProductQuantity[i]
                });

                totalPrice += prod.Price * sv.ProductQuantity[i];
            }

            sale.TotalPrice = totalPrice;

            var sellerInfo = new
            {
                PID      = consultant.PID,
                FullName = consultant.GetFullName()
            };

            sale.SellerInfo  = JsonConvert.SerializeObject(sellerInfo);
            sale.Description = JsonConvert.SerializeObject(saleItems);
            sale.SaleDate    = DateTime.Now;

            if (ModelState.IsValid)
            {
                _context.Add(sale);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sale));
        }
コード例 #3
0
        public void PlacesOrderWithMultipleLineItems()
        {
            var options = TestUtil.GetMemDbOptions("PlacesOrderWithMultipleLineItems");

            Guid product1Id, product2Id;
            Guid customerId;
            Guid orderId;

            using (var db = new StoreContext(options))
            {
                var customer = new Customer(Guid.NewGuid().ToString());
                var location = new Location(Guid.NewGuid().ToString());
                db.Add(customer);
                db.Add(location);
                customerId = customer.CustomerId;

                var product1   = new Product(Guid.NewGuid().ToString(), 1.0);
                var inventory1 = new LocationInventory(product1, location, 10);
                db.Add(product1);
                db.Add(inventory1);
                product1Id = product1.ProductId;

                var product2   = new Product(Guid.NewGuid().ToString(), 1.0);
                var inventory2 = new LocationInventory(product2, location, 20);
                db.Add(product2);
                db.Add(inventory2);
                product2Id = product2.ProductId;

                var order = new Order(customer, location);
                orderId = order.OrderId;
                var orderLine1 = new OrderLineItem(order, product1);
                orderLine1.Quantity = 5;
                var orderLine2 = new OrderLineItem(order, product2);
                orderLine2.Quantity = 7;
                order.OrderLineItems.Add(orderLine1);
                order.OrderLineItems.Add(orderLine2);

                db.Add(order);
                db.SaveChanges();
            }

            using (var db = new StoreContext(options))
            {
                var customer = (from c in db.Customers where c.CustomerId == customerId select c).First();

                var order =
                    (from o in db.Orders
                     where o.Customer.CustomerId == customer.CustomerId
                     select o).First();

                Assert.Equal(2, order.OrderLineItems.Count());
            }

            Assert.Equal(PlaceOrderResult.Ok, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var invProduct1 =
                    (from i in db.LocationInventories where i.Product.ProductId == product1Id select i).First();
                Assert.Equal(5, invProduct1.Quantity);

                var invProduct2 =
                    (from i in db.LocationInventories where i.Product.ProductId == product2Id select i).First();
                Assert.Equal(13, invProduct2.Quantity);
            }
        }
コード例 #4
0
        public void RejectsOrderWhenNotEnoughInventory()
        {
            var options = TestUtil.GetMemDbOptions("RejectsOrderWhenNotEnoughInventory");

            String product1Name, product2Name;
            Guid   customerId;
            Guid   orderId;

            using (var db = new StoreContext(options))
            {
                var(customer, location, product1, inventory) = SimplePopulate(db);
                customerId = customer.CustomerId;
                var product2 = new Product(Guid.NewGuid().ToString(), 2.0);
                db.Add(product2);
                var inventory2 = new LocationInventory(product2, location, 20);
                db.Add(inventory2);

                product1Name = product1.Name;
                product2Name = product2.Name;

                var order = new Order(customer, location);
                orderId = order.OrderId;

                var orderLine1 = new OrderLineItem(order, product1);
                orderLine1.Quantity = 9;
                order.OrderLineItems.Add(orderLine1);

                var orderLine2 = new OrderLineItem(order, product2);
                orderLine2.Quantity = 10;
                order.OrderLineItems.Add(orderLine2);

                var orderLine3 = new OrderLineItem(order, product2);
                orderLine3.Quantity = 11;
                order.OrderLineItems.Add(orderLine3);

                db.Add(order);
                db.SaveChanges();
            }

            using (var db = new StoreContext(options))
            {
                var customer = (from c in db.Customers where c.CustomerId == customerId select c).First();

                var order = (from o in db.Orders
                             where o.Customer.CustomerId == customer.CustomerId
                             select o).First();

                Assert.Equal(customer.CustomerId, order.Customer.CustomerId);
            }

            Assert.Equal(PlaceOrderResult.OutOfStock, options.PlaceOrder(orderId, StoreDbUtil.Config.MAX_ORDER_QUANTITY));

            using (var db = new StoreContext(options))
            {
                var inventoryP1 = (from i in db.LocationInventories where i.Product.Name == product1Name select i).First();
                Assert.Equal(10, inventoryP1.Quantity);

                var inventoryP2 = (from i in db.LocationInventories where i.Product.Name == product2Name select i).First();
                Assert.Equal(20, inventoryP2.Quantity);
            }
        }
コード例 #5
0
        public void BasicTest()
        {
            using (StoreContext storeContext = new StoreContext())
            {
                Assert.AreEqual(0, storeContext.PayloadRecords.Count());
                Assert.AreEqual(0, storeContext.Destinations.Count());

                Destination destination = new Destination()
                {
                    AccessToken = "token1",
                    Endpoint    = "http://endpoint.com"
                };
                Assert.AreNotEqual(Guid.Empty, destination.ID);

                destination.PayloadRecords.Add(new PayloadRecord()
                {
                    PayloadJson = "payload1", Timestamp = DateTime.UtcNow,
                });

                storeContext.Add(destination);
                storeContext.SaveChanges();
            }

            using (StoreContext storeContext = new StoreContext())
            {
                Assert.AreEqual(1, storeContext.Destinations.Count());
                Assert.AreEqual(1, storeContext.PayloadRecords.Count());
            }

            using (StoreContext storeContext = new StoreContext())
            {
                Destination destination = storeContext.Destinations.FirstOrDefault(d => d.AccessToken == "token1");
                Assert.IsNotNull(destination);
                Assert.AreEqual("token1", destination.AccessToken);

                destination.PayloadRecords.Add(new PayloadRecord()
                {
                    PayloadJson = "payload2", Timestamp = DateTime.UtcNow,
                });
                storeContext.Add(
                    new PayloadRecord()
                {
                    PayloadJson = "payload3", Timestamp = DateTime.UtcNow, Destination = destination
                }
                    );
                storeContext.PayloadRecords.Add(
                    new PayloadRecord()
                {
                    PayloadJson = "payload4", Timestamp = DateTime.UtcNow, Destination = destination
                }
                    );

                destination = new Destination()
                {
                    AccessToken = "token2",
                    Endpoint    = "http://endpoint.com"
                };
                Assert.AreNotEqual(Guid.Empty, destination.ID);

                destination.PayloadRecords.Add(new PayloadRecord()
                {
                    PayloadJson = "payload5", Timestamp = DateTime.UtcNow,
                });
                storeContext.Add(
                    new PayloadRecord()
                {
                    PayloadJson = "payload6", Timestamp = DateTime.UtcNow, Destination = destination
                }
                    );
                storeContext.PayloadRecords.Add(
                    new PayloadRecord()
                {
                    PayloadJson = "payload7", Timestamp = DateTime.UtcNow, Destination = destination
                }
                    );

                storeContext.Add(destination);
                storeContext.SaveChanges();
            }

            using (StoreContext storeContext = new StoreContext())
            {
                Assert.AreEqual(2, storeContext.Destinations.Count());
                Assert.AreEqual(7, storeContext.PayloadRecords.Count());

                Assert.AreEqual(4,
                                storeContext.Destinations
                                .Where(d => d.AccessToken == "token1")
                                .Include(d => d.PayloadRecords)
                                .First()
                                .PayloadRecords
                                .Count()
                                );
                Assert.AreEqual(3,
                                storeContext.Destinations
                                .Where(d => d.AccessToken == "token2")
                                .Include(d => d.PayloadRecords)
                                .First()
                                .PayloadRecords
                                .Count()
                                );
            }
        }
コード例 #6
0
ファイル: Bootstrapper.cs プロジェクト: sabihoshi/NPCStore
        public Bootstrapper()
        {
            return;

            var gpus = (
                new[]
            {
                2, 4, 8, 4, 8, 8, 8, 6, 6, 6, 8, 6, 6, 6, 4, 4, 6, 6, 2, 4, 6, 4, 6, 6, 8, 8, 8, 4, 8, 8, 2, 4,
                8, 6, 8, 2, 4, 8, 8, 6, 6, 2, 2, 8, 8, 8, 8, 6, 8, 8, 8, 8, 8, 11, 11, 6, 6, 3, 4, 6, 8, 11, 2,
                4, 4, 6, 6, 6, 8, 8, 1, 2, 6, 4, 6, 6, 8
            },
                new[]
            {
                "MSI GT1030 Aero ITX 2gb ddr5", "MSI GTX1050TI OCV1 Dual 4gb ddr5",
                "MSI GTX1650 (GamingX-8100)(Aero-8050)", "MSI GTX1650 Super Aero 4gb ddr6",
                "MSI GTX1660 Ventus XS 6gb ddr5", "MSI GTX1660 Gaming X 6gb ddr5",
                "MSI 1660 Super(Aero-14200)(Ventus-15450)", "MSI GTX1660Ti Ventus XS 6gb ddr5",
                "MSI RTX2060 Gaming Z 6gb ddr6", "MSI RTX2060 Super Ventus 8gb ddr6",
                "MSI RTX2060 Super GamingX 8gb ddr6", "MSI 2070 Super (Ventus-30750)(X Trio-34900)",
                "MSI RTX2080 Super Gaming X Trio 8gb", "MSI 2080Ti(GamingX/Z-77000)(Lightning-87550)",
                "MSI RX570 Armor OC (4gb-6950)", "MSI RX5500XT Mech(4gb-10150)",
                "MSI RX5600XT Mech OC 6gb ddr6", "MSI 5700XT (Evoke-24750) (GamingX-27600)",
                "Gigabyte GT1030 OC 2gb ddr5", "Gigabyte GTX1050TI Single fan 4gb",
                "Gigabyte GTX1650(OC-8850)(Gaming-9000)", "Gigabyte GTX1650 Super OC 4gb",
                "Gigabyte 1660 (OC-12200) (Super OC-14100)", "G.byte 1660Ti (OC-15500)(Windforce-16100)",
                "Giga 2060Super (W.Force-24200)(Gaming-25600) OC 8gb", "Giga RTX2070 Super Gaming OC 8gb",
                "Giga RTX2080 Super Gaming OC 8gb", "Giga RX570 Gaming (4gb-6900) (8gb-8300)",
                "Giga RX580 Gaming Windforce OC 8gb", "Giga RX5700XT Gaming OC 8gb ddr6",
                "PC RX550 Red Dragon 2gb ddr5 128bit", "PC RX570 Red Dragon 4gb ddr5 256bit",
                "PowerColor RX5500XT OC 8gb ddr6", "PowerColor RX5600XT Red Devil 6gb",
                "PowerColor RX5700XT Red Devil 8gb d6", "Palit GT1030 2gb (ddr4-4150) (ddr5-4650) LP",
                "Palit GTX1050Ti StormX 4gb ddr5", "Palit GTX1650 Super(StormX-9300)(OC-9550)",
                "Palit 1660 Super(StormX-13300)(Pro-13700)", "Palit GTX1660Ti Storm X 6gb ddr6",
                "Palit RTX2060 StormX OC 6gb", "Asus GT710 2gb ddr5", "Asus GT1030SL 2gb ddr5",
                "Asus GTX1650 (Phoenix-8100) (Dual-8850)", "Asus GTX1650 Super Strix O4G ddr6",
                "Asus GTX1660 (Phoenix-12150)(TUF-13900)", "Asus 1660 Super(Phoenix-14400)(TUF-15150)",
                "Asus GTX1660Ti Phoenix O6G 6gb ddr6", "Asus RTX2060 (TUF-22300) (Strix-22900)",
                "Asus RTX2060 Super Strix A8G 8gb", "Asus RTX2070 Dual OC 8gb",
                "Asus 2070 Super (O8G-39950) (A8G-38300)", "Asus RTX2080 Super Gaming 8gb",
                "Asus RTX2080Ti Strix OC 11gb ddr6", "Asus RX5500XT ROG Strix O8G 128b",
                "Asus RX5600XT TUF Evo 6gb 192b", "Asus RX5700XT (TUF-28250) (Strix-31600)",
                "Zotac GTX1060 Mini 3gb", "Zotac GTX1650 Super Twin 4gb ddr5", "Zotac RTX2060 Amp Ed 6gb ddr6",
                "Zotac 2070 Amp Extreme 8gb ddr6", "Zotac RTX2080Ti AMP Ed.11gb ddr6", "Galax GT1030 2gb ddr4",
                "Galax GTX1050Ti OC 4gb ddr5", "Galax GTX1650 Super EX OC 4gb ddr5",
                "Galax GTX1660 EXWhite OC 6gb ddr5", "Galax RTX2060 White Mini OC 6gb",
                "Galax RTX2060 Super EXWhite OC 6gb", "Galax RTX2070 Super HOF 10th Anniversary",
                "Sapphire 5700XT(Pulse-24750)(Nitro+-26700)", "Inno3D GT730 (1gb F-2250) (2gb K-3000)",
                "Inno3D GT1030 0DB 2gb ddr5 64bit", "Inno3D (1050-5650) (1050Ti-6500) TwinX2",
                "Inno3D GTX1650 TwinX2 OC 4gb ddr5", "Inno3D GTX1660 Twin X2 6gb ddr5",
                "Inno3D GTX1660Ti Twin X2 6gb ddr6", "Inno3D RTX2060 Super 8gb ddr6"
            },
                new[]
            {
                4200, 7050, 7050, 9300, 13200, 14100, 14100, 15750, 21450, 24900, 25900, 25900, 46950, 46950,
                46950, 46950, 8700, 8700, 4700, 6850, 6850, 9995, 9995, 9995, 9995, 31800, 45100, 45100, 10750,
                24800, 3950, 6550, 12150, 20550, 27000, 27000, 6600, 6600, 6600, 15950, 19700, 2400, 4100, 4100,
                12000, 12000, 12000, 16000, 16000, 28200, 26850, 26850, 54900, 80500, 15500, 21550, 21550, 7100,
                9400, 17800, 30200, 73150, 3950, 6100, 9800, 13850, 17400, 25400, 42000, 42000, 3750, 3750,
                7750, 12250, 15200, 22600, 27100
            });
            var memories = (new[] { 2, 4, 8, 4, 4, 4, 8, 8, 8, 8, 8, 16, 16, 16, 32, 8, 8, 16, 16, 16, 32 },
                            new[]
            {
                "2GB Eudar 800 ddr2", "4GB Kingston Dimm/Sodimm ddr3 1600",
                "8GB Kingston Dimm/Sodimm ddr3 1600", "4GB Kingston Value Ram Dimm ddr4",
                "4GB Transcend/Crucial/Team Sodimm ddr4", "4GB Kingston Sodimm ddr4",
                "8GB Crucial/Klevv Dimm ddr4", "8GB Kingston Value Ram Dimm ddr4",
                "8GB Transcend/Adata/Crucial Sodimm ddr4", "8GB Kingston Sodimm / Impact ddr4",
                "8GB Kingston/Adata 3200 Sodimm ddr4", "16GB Crucial / Adata Sodimm ddr4",
                "16GB Kingston/Transcend Sodimm ddr4", "16GB Kingston 3200 Sodimm ddr4",
                "32GB Adata Sodimm ddr4", "Fury 1866 ddr3 (4gb-1300) (8gb-2300)",
                "Fury 2400/2666 ddr4 Black / White", "Fury 3200 ddr4 black (8gb-2100) (16gb-3700)",
                "Fury RGB 16gb 2x8 (3200-4750)", "RGB 16gb 1x16 (3000-4000) (3200-4200)",
                "RGB 32gb 2x16 (2666-7800) (3200-8550)"
            },
                            new[]
            {
                650, 1150, 2200, 1150, 1100, 1150, 1850, 1900, 1950, 1950, 2050, 3500, 3500, 3600, 6000, 1900,
                1950, 2050, 3500, 3500, 3600
            });
            var monitors = (
                new[]
            {
                2500, 2500, 2850, 2950, 2995, 3300, 3300, 2950, 3200, 3300, 3600, 3650, 4100, 4100, 4400, 4000,
                4050, 4650, 5100, 5400, 5400, 5750, 5750, 6900, 6900, 8350, 5300, 5300, 5300, 9995, 9995, 9995,
                9995, 9995, 9995, 9995, 8500, 15200, 8300, 9600, 12500
            },
                new[]
            {
                "15.6”", "15.6”", "18.5”", "18.5”", "18.5”", "18.5”", "18.5”", "18.5”", "18.5”", "20”", "20”",
                "20”", "20”", "20”", "21.5”", "21.5”", "21.5”", "21.5”", "21.5”", "21.5”", "21.5”", "21.5”",
                "21.5”", "23”", "23”", "23”", "24”", "24”", "24”", "24”", "24”", "24”", "24”", "24”", "24”",
                "24”", "24”", "24”", "25”", "27”", "27”", "27”"
            },
                new[]
            {
                "AOC E1670SW 1366x768", "Philips 163V5/166V3LSB", "Acer EB192Q", "Lenovo 61E0KAR vga/hdmi",
                "AOC E950/960/970SWN", "Philips 193/196V", "V.sonic (1903/01A-3150) (1903hdmi-3350)",
                "HP V5E94AA/2NK17AA-V190", "LG 19M35/37/38A", "AOpen 20CH1Q", "HP V203P", "Asus VS207DF",
                "AOC M2060SWD 1600x900", "Philips 203V5L/200V4 1600x900", "Lenovo LI2215S", "AOpen 22CH1Q",
                "Huntkey N2271WH/ N2283WH", "Viewsonic VA2261", "HP 22YH", "AOC E2270/80",
                "Philips(223V5-5100) (227E7QD-5950)", "Samsung LS22F350", "VZ229H-7400)", "BenQ VZ2350HM IPS",
                "Asus (VZ239HE-6900)", "Dell S2319H IPS", "Huntkey M2471", "Gamdias (VH238F-5600)(HD236C-7600)",
                "Viewsonic(2407H-6500)(2457MHD-8050)", "Viewsonic VX2458MHD",
                "HP (24F IPS-6950) (N240IPS-7550)", "12150 AOC (M2470S-5900) (E2470SWH-8250)",
                "(GW2480-7400) (XL2411P-13200)", "AVP249QGR-9950)", "(248E9QH Curved FreeSync-8750)",
                "Samsung (LS24F350-6950) Curved (F390-7950) (LC24RG50F-12400) (FG70Fsync-17350)",
                "LG 24MP58VQ/24MK600M IPS", "MSI(G241VC-7450) (G241 IPS-13400) (MAG241C curved-13050)",
                "AOC G2590PX", "Lenovo L27I-28 IPS", "HP 5ZP66AA 27F 4K IPS Freesync", "BenQ RL2755 1MS Gaming"
            });

            var db = new StoreContext();

            for (int i = 0; i < gpus.Item1.Length; i++)
            {
                var product = new Product
                {
                    Name  = gpus.Item2[i],
                    Price = gpus.Item3[i]
                };

                var gpu = new Graphics
                {
                    Product = product,
                    VRamGB  = gpus.Item1[i]
                };

                db.Add(gpu);
            }

            for (int i = 0; i < memories.Item1.Length; i++)
            {
                var product = new Product
                {
                    Name  = memories.Item2[i],
                    Price = memories.Item3[i]
                };

                var gpu = new Memory
                {
                    Product    = product,
                    CapacityGB = gpus.Item1[i]
                };

                db.Add(gpu);
            }

            for (int i = 0; i < monitors.Item1.Length; i++)
            {
                var product = new Product
                {
                    Name  = monitors.Item3[i],
                    Price = monitors.Item1[i]
                };

                var gpu = new Monitor
                {
                    Product = product,
                    Size    = monitors.Item2[i]
                };

                db.Add(gpu);
            }

            db.SaveChanges();
        }