예제 #1
0
        public void UpdateWarehouseDb()
        {
            var warehouseDb = new DbWarehouse();
            var prod        = new Product
            {
                Id          = 1,
                Category    = "category",
                Description = "ddeskr",
                Name        = "banan",
                Price       = 10
            };
            var shop = new Shop
            {
                Name        = "ShopName",
                Address     = "new addr",
                OpeningTime = "Manday Never",
                Chain       = new DbChain().GetChain(1),
                Cvr         = "12121212",
                Warehouses  = new List <Warehouse>()
            };
            var shopId = new DbShop().AddShop(shop);

            shop.Id = shopId;
            var warehouseToUpdate = new Warehouse(1, 1, prod, shop, null);
            var id = warehouseDb.AddWarehouse(warehouseToUpdate);

            warehouseToUpdate.Id = id;
            var warehouseNew = new Warehouse(id, 100, 50, prod, shop, 1);

            warehouseDb.UpdateWarehouse(warehouseNew);
            var updatedWarehouse = warehouseDb.GetWarehouse(id);

            Assert.AreEqual(warehouseNew.Stock, updatedWarehouse.Stock);
        }
예제 #2
0
        public void GetShopDb()
        {
            var dbShop = new DbShop();
            var shop   = new Shop()
            {
                Name        = "hello world",
                Address     = "Hello address",
                OpeningTime = "Manday Never",
                Cvr         = "12121212",
                Warehouses  = new List <Warehouse>(),
                Chain       = new Chain
                {
                    Id      = 1,
                    Cvr     = "12121212",
                    Name    = "",
                    Persons = new List <Person>(),
                    Shops   = new List <Shop>()
                }
            };
            var i = dbShop.AddShop(shop);
            var j = dbShop.GetShop(i);

            dbShop.DeleteShop(i);
            Assert.IsNotNull(j);
        }
예제 #3
0
        public ActionResult DoUpload(IFormFile file)
        {
            using (var stream = file.OpenReadStream())
            {
                var xs   = new XmlSerializer(typeof(GunShop.Shop));
                var shop = (GunShop.Shop)xs.Deserialize(stream);

                using (var db = new ShopDbContext())
                {
                    var dbs = new DbShop()
                    {
                        Name     = shop.Name,
                        Address  = shop.Address,
                        Photo    = shop.Photo,
                        Contacts = shop.Contacts,
                    };
                    dbs.Guns = new Collection <DbSpecifications>();
                    foreach (var specifications in shop.Guns)
                    {
                        dbs.Guns.Add(new DbSpecifications()
                        {
                            Name           = specifications.Name,
                            ProductionDate = specifications.ProductionDate,
                            GunType        = specifications.GunType,
                            Caliber        = specifications.Caliber,
                            Price          = specifications.Price,
                            Weight         = specifications.Weight,
                        });
                    }
                    db.Shops.Add(dbs);
                    db.SaveChanges();
                }
                return(View(shop));
            }
        }
예제 #4
0
        public void GetWarehouseDb()
        {
            var warehouseDb = new DbWarehouse();

            var prod = new Product
            {
                Id          = 1,
                Category    = "category",
                Description = "ddeskr",
                Name        = "banan",
                Price       = 10
            };
            var shop = new Shop
            {
                Name        = "ShopName",
                Address     = "new addr",
                OpeningTime = "Manday Never",
                Chain       = new DbChain().GetChain(1),
                Cvr         = "12121212",
                Warehouses  = new List <Warehouse>()
            };
            var shopId = new DbShop().AddShop(shop);

            shop.Id = shopId;
            var warehouse = new Warehouse(10, 5, prod, shop, 1);
            var id        = warehouseDb.AddWarehouse(warehouse);
            var rw        = warehouseDb.GetWarehouse(id);

            Assert.IsNotNull(rw);
        }
예제 #5
0
        public UnitTest1()
        {
            options = new DbContextOptionsBuilder <DbShop>()
                      .UseInMemoryDatabase(databaseName: "InMemoryDatabase")
                      .Options;

            context = new DbShop(options);
        }
        public void TestConcurrencyLessThenMaxAmount()
        {
            var i1 = 0;
            var i2 = 0;

            var prod = new Product("TestProd1", new decimal(10), "TestDescription", "Oste", "TestPath");
            var s    = new Shop("TestShop1", "TestAddress", "12345678", "OpeningTime", new DbChain().GetChain(1), new List <Warehouse>());

            //add product to database
            int prodId = new DbProduct().AddProduct(prod);

            prod.Id = prodId;
            //add shop to database
            var shopId = new DbShop().AddShop(s);

            s.Id = shopId;

            //add warehouse to databse and add it to shop
            var warehouse = new Warehouse(10, 0, prod, s, null);
            var warId     = new DbWarehouse().AddWarehouse(warehouse);

            warehouse.Id = warId;
            s.Warehouses.Add(warehouse);

            //make cart1 with part order
            var cart1 = new Cart();
            var po1   = new PartOrder(prod, 5, 20);

            cart1.PartOrders.Add(po1);
            cart1.PersonId = _cust.Id;
            cart1.ShopId   = s.Id;

            //make cart2 with part order
            var cart2 = new Cart();
            var po2   = new PartOrder(prod, 2, 20);

            cart2.PartOrders.Add(po2);
            cart2.PersonId = _cust1.Id;
            cart2.ShopId   = s.Id;

            //start 2 parallel queries
            var cartDb = new DbCart();

            Parallel.Invoke(() => { i1 = cartDb.AddCartWithPartOrders(cart1); }, () => { i2 = cartDb.AddCartWithPartOrders(cart2); });
            //var antal = new DbWarehouse().GetWarehouse(warId).Stock;
            var flag = 0;

            if (i1 == 0 || i2 == 0)
            {
                flag = 1;
            }
            Assert.AreEqual(1, flag);
        }
예제 #7
0
 public WebShopController(DbShop context)
 {
     _context = context;
 }
예제 #8
0
 public ReviewContentController(DbShop context)
 {
     _context = context;
 }
예제 #9
0
 public MeasuringUnitController(DbShop context)
 {
     _context = context;
 }
예제 #10
0
 public RepositoryUnit(DbShop context)
 {
     _context = context;
 }
예제 #11
0
 public ProductCategoryController(DbShop context)
 {
     _context = context;
 }
예제 #12
0
 public CheckOutController(DbShop contex)
 {
     _context = contex;
     carts    = new List <Cart>();
 }
예제 #13
0
 public HomeController(DbShop context)
 {
     _context = context;
 }
예제 #14
0
 public CategoryController(DbShop context)
 {
     _context = context;
 }
예제 #15
0
 public ModelPaging(DbShop context)
 {
     _context = context;
     Data     = _context.ProductCategory.Include(x => x.Product).Include(x => x.Category).ToList();
     Count    = Data.Count;
 }
예제 #16
0
 public CartController(DbShop dbShop)
 {
     _context = dbShop;
     carts    = new List <Cart>();
 }