Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //实例化上下文类
            TeaContext db = new TeaContext();

            //将上下文类 装载到服务中
            services.AddSingleton <TeaContext>(db);

            /*
             * 配置跨域处理
             */
            // 获取appsettings.json配置信息


            //配置跨域处理
            services.AddCors(options =>
            {
                options.AddPolicy("cors", builder =>
                {
                    builder.WithOrigins("http://localhost:6321") //允许指定域名访问
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();//指定处理cookie
                });
            });

            services.AddControllers();
        }
        public void CreateNewBasketShouldCreateNewBasket()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("CreateNewBasketShouldCreateNewBasket").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };

            OrderModel order = new OrderModel()
            {
                locationId = 1,
                customerId = 1,
                totalPrice = Convert.ToDecimal(0.00),
                complete   = false
            };

            //Act
            repo.CreateNewBasket(order);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.NotNull(assertContext.Orders.First(h => h.Locationid == 1 && h.Customerid == 1));
        }
        public void DecreaseStockShouldDecreaseStock()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("DecreaseStockShouldDecreaseStock").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            InventoryModel invenotry = new InventoryModel()
            {
                locationId = 1,
                productId  = 1,
                stock      = 1
            };

            //Act
            repo.DecreaseStock(invenotry);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.True(assertContext.Inventory.First(h => h.Locationid == 1 && h.Productid == 1).Stock == 1);
        }
 private void Seed(TeaContext testcontext)
 {
     testcontext.Products.AddRange(testProducts);
     testcontext.Customers.AddRange(testCustomers);
     testcontext.Locations.AddRange(testLocations);
     testcontext.Locations.AddRange(testLocations2);
     testcontext.Orders.AddRange(testOrders);
     testcontext.Orders.AddRange(testOrderHistory1);
     testcontext.Orders.AddRange(testOrderHistory1);
     testcontext.Orderitems.AddRange(testOrderItems);
     testcontext.Inventory.AddRange(testInventory);
     testcontext.SaveChanges();
 }
        public void GetCustomerOrdersFromMostToLeastShouldGetCustomerOrders()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetCustomerOrdersFromMostToLeastShouldGetCustomerOrders").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetCustomerOrderMostToLeast(1);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.True(result.Count == 1);
        }
        public void GetLocationOrderHistoryMostToLeastShouldGetLocationOrder()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetLocationOrderHistoryMostToLeastShouldGetLocationOrder").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetOrderHistoryLocationByMostExpensive(1);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.True(result.Count == 1);
        }
        public void NewOrderItemShouldCreateNewOrderItem()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("NewOrderItemShouldCreateNewOrderItem").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };

            //Act
            repo.AddToBasket(testOrderItemModel);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.NotNull(assertContext.Orderitems.First(h => h.Orderid == testOrderItemModel.orderId));
        }
        public void GetOrderIdShouldGetOrderId()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetOrderIdShouldGetOrderId").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetCurrentOrder(testCustomerModel.id, 1);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.Equal(result.customerId, testCustomerModel.id);
        }
        public void CreateNewProductShouldCreateNewProduct()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("CreateNewProductShouldCreateNewProduct").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };

            //Act
            repo.CreateNewProduct(productModel);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.NotNull(assertContext.Products.First(p => p.Productname == productModel.name));
        }
        public void GetProductShouldGetProduct()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetProductShouldGetProduct").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetProduct(1);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.Equal(result.id, testProducts.Productid);
        }
        public void GetItemsInBasketShouldGetItemsInBasket()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetItemsInBasketShouldGetItemsInBasket").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetCurrentOrder(1, 1);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.Equal(result.orderItems.Count, 1);
        }
        public void GetAllProductsShouldGetAllProducts()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetAllProductsShouldGetAllProducts").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetAllProducts();

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.True(result.Count == 1);
        }
        public void GetCustomerShouldGetCustomer()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("GetCustomerShouldGetCustomer").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            var result = repo.GetCustomerInfo("*****@*****.**");

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.Equal(result.email, "*****@*****.**");
        }
        public void IncreaseTotalPriceShouldIncreaseTotalPrice()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("IncreaseTotalPriceShouldIncreaseTotalPrice").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            Seed(testContext);
            //Act
            repo.IncreaseTotalPrice(1, Convert.ToDecimal(1.00));

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.True(assertContext.Orders.First(h => h.Orderid == 1).Totalprice == Convert.ToDecimal(5.99));
        }
        public void NewCustomerShouldAddCustomer()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("NewCustomerShouldAddCustomer").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };

            //Act
            repo.NewCustomer(testCustomerModel);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.NotNull(assertContext.Customers.Single(h => h.Customeremail == testCustomerModel.email));
        }
        public void AddItemToInventoryShouldAddItemToInventory()
        {
            var options = new DbContextOptionsBuilder <TeaContext>().UseInMemoryDatabase("AddItemToInventoryShouldAddItemToInventory").Options;

            using var testContext = new TeaContext(options);
            repo = new DBRepo()
            {
                context = testContext,
                mapper  = mapper
            };
            InventoryModel inventory = new InventoryModel()
            {
                locationId = 1,
                productId  = 1,
                stock      = 1
            };

            //Act
            repo.AddItemToInventory(inventory);

            //Assert
            using var assertContext = new TeaContext(options);
            Assert.NotNull(assertContext.Inventory.First(i => i.Locationid == 1));
        }
Esempio n. 17
0
 public GoodsController(TeaContext db)
 {
     this.db = db;
 }
 public HomeController(TeaContext context) => this.context = context;
 public static void Initialize(TeaContext context)
 {
     if (!context.Products.Any() || !context.Employees.Any())
     {
         context.Employees.AddRange(
             new Employee {
             Login    = "******",
             Password = "******"
         }
             );
         context.Products.AddRange(
             new Product {
             Title       = "Ассам FBOP",
             Description = "fbop.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 5,
             Price       = 75,
             Image       = "fbop.jpg"
         },
             new Product {
             Title       = "Те Гуань Инь в.к.",
             Description = "teguan.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 3 x 2",
             Quantity    = 3,
             Price       = 350,
             Image       = "teguan.jpg"
         },
             new Product {
             Title       = "Хун Му Дань",
             Description = "hunmudan.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 4 x 5",
             Quantity    = 0,
             Price       = 200,
             Image       = "hunmudan.jpg"
         },
             new Product {
             Title       = "Кения FOP",
             Description = "fop.txt",
             Weight      = 0.05,
             Dimensions  = "10 x 7 x 3",
             Quantity    = 9,
             Price       = 150,
             Image       = "fop.jpg"
         },
             new Product {
             Title       = "Лун Цзин в.к.",
             Description = "lunzin.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 42,
             Price       = 200,
             Image       = "lunzin.jpg"
         },
             new Product {
             Title       = "Бай Хуа Сянь Цзы",
             Description = "buyhia.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 22,
             Price       = 467,
             Image       = "buyhia.jpg"
         },
             new Product {
             Title       = "Дянь Хун Мао Фэн",
             Description = "dyanhun.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 15,
             Price       = 210,
             Image       = "dyanhun.jpg"
         },
             new Product {
             Title       = "Шу Сян Люй",
             Description = "shusyan.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 11,
             Price       = 100,
             Image       = "shusyan.jpg"
         },
             new Product {
             Title       = "Дарджилинг FTGFOP1",
             Description = "dardzhil.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 43,
             Price       = 7530,
             Image       = "dardzhil.jpg"
         },
             new Product {
             Title       = "Цзинь Ло",
             Description = "zinlo.txt",
             Weight      = 0.05,
             Dimensions  = "12 x 5 x 3",
             Quantity    = 228,
             Price       = 10,
             Image       = "zinlo.jpg"
         }
             );
         context.SaveChanges();
     }
 }
Esempio n. 20
0
 public UsersController(TeaContext db)
 {
     this.db = db;
 }
Esempio n. 21
0
 public DataStore(TeaContext context, IPasswordHasher passwordHasher, ILogger <DataStore> log)
 {
     _context        = context;
     _passwordHasher = passwordHasher;
     _log            = log;
 }
Esempio n. 22
0
 public AccountController(TeaContext context) => this.context = context;
Esempio n. 23
0
 public DataStore(TeaContext context)
 {
     _context = context;
 }
Esempio n. 24
0
 public ClientController(TeaContext db)
 {
     this.db = db;
 }