示例#1
0
        public void Initialize()
        {
            // Initialize a new transaction scope. This automatically begins the transaction.
            tran = new TransactionScope();

            if (_categoryId == BaseItem.InvalidId)
            {
                // Add category item
                _categoryId = _db.AddCategoryItem(
                    new CategoryItem()
                {
                    Name  = "TestCategory",
                    Noise = "CategoryNoise"
                });
                Assert.AreNotEqual(0, _categoryId);
            }

            if (_productId == BaseItem.InvalidId)
            {
                // Add product item
                _productId = _db.AddProductItem(
                    new ProductItem()
                {
                    Name       = "TestProduct",
                    Price      = 0.50,
                    CategoryId = _categoryId
                });
                Assert.AreNotEqual(0, _productId);
            }

            if (_inventoryId == BaseItem.InvalidId)
            {
                // Add inventory item
                _inventoryId = _db.AddInventoryItem(
                    new InventoryItem()
                {
                    Row       = 1,
                    Column    = 1,
                    Qty       = 4,
                    ProductId = _productId
                });
                Assert.AreNotEqual(0, _inventoryId);
            }

            if (_vendingTransactionId == BaseItem.InvalidId)
            {
                // Add vending transaction
                _vendingTransactionId = _db.AddVendingTransaction(
                    new VendingTransaction()
                {
                    Date = DateTime.UtcNow
                });
                Assert.AreNotEqual(0, _vendingTransactionId);
            }
        }
示例#2
0
        public ActionResult <int> Post([FromBody] InventoryItemViewModel value)
        {
            InventoryItem item = new InventoryItem();

            item.Column    = value.Column;
            item.ProductId = value.ProductId;
            item.Qty       = value.Qty;
            item.Row       = value.Row;
            return(_db.AddInventoryItem(item));
        }
        public void TestInventory()
        {
            // Test add inventory
            InventoryItem item = new InventoryItem();

            item.Column    = 2;
            item.Row       = 3;
            item.Qty       = 4;
            item.ProductId = _productId;
            int id = _db.AddInventoryItem(item);

            Assert.AreNotEqual(0, id);

            InventoryItem itemGet = _db.GetInventoryItem(id);

            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.Column, itemGet.Column);
            Assert.AreEqual(item.Row, itemGet.Row);
            Assert.AreEqual(item.Qty, itemGet.Qty);
            Assert.AreEqual(item.ProductId, itemGet.ProductId);

            // Test update inventory
            item.Column = 3;
            item.Row    = 4;
            item.Qty    = 6;
            Assert.IsTrue(_db.UpdateInventoryItem(item));

            itemGet = _db.GetInventoryItem(id);
            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.Column, itemGet.Column);
            Assert.AreEqual(item.Row, itemGet.Row);
            Assert.AreEqual(item.Qty, itemGet.Qty);
            Assert.AreEqual(item.ProductId, itemGet.ProductId);

            // Test delete inventory
            _db.DeleteInventoryItem(id);
            var inventoryItems = _db.GetInventoryItems();

            foreach (var inventoryItem in inventoryItems)
            {
                Assert.AreNotEqual(id, inventoryItem.Id);
            }
        }
        /// <summary>
        /// Creates the products, inventory, and categories to support a 4x3 vending machine
        /// </summary>
        /// <param name="db">Database interface used to create the data</param>
        public static void PopulateDatabaseWithInventory(IVendingService db)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CategoryItem categoryItem = new CategoryItem()
                {
                    Name  = "Chips",
                    Noise = "Crunch, Crunch, Crunch, Yum!"
                };
                categoryItem.Id = db.AddCategoryItem(categoryItem);

                // Add Product 1
                ProductItem productItem = new ProductItem()
                {
                    Name       = "Lays",
                    Price      = 0.50,
                    Image      = "https://image.flaticon.com/icons/svg/305/305385.svg",
                    CategoryId = categoryItem.Id
                };
                productItem.Id = db.AddProductItem(productItem);

                InventoryItem inventoryItem = new InventoryItem()
                {
                    Column    = 1,
                    Row       = 1,
                    Qty       = 5,
                    ProductId = productItem.Id
                };
                inventoryItem.Id = db.AddInventoryItem(inventoryItem);

                // Add Product 2
                productItem.Name  = "Pringles";
                productItem.Image = "https://image.flaticon.com/icons/svg/1228/1228383.svg";
                productItem.Price = 0.65;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 3
                productItem.Name  = "Ruffles";
                productItem.Image = "https://image.flaticon.com/icons/svg/1046/1046758.svg";
                productItem.Price = 0.75;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 4
                categoryItem.Name  = "Candy";
                categoryItem.Noise = "Lick, Lick, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "M&Ms Plain";
                productItem.Image      = "https://image.flaticon.com/icons/svg/1296/1296913.svg";
                productItem.Price      = 0.55;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 2;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 5
                productItem.Name  = "M&Ms Peanut";
                productItem.Image = "https://image.flaticon.com/icons/svg/1296/1296944.svg";
                productItem.Price = 0.55;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 6
                productItem.Name  = "Gummy Bears";
                productItem.Image = "https://image.flaticon.com/icons/svg/119/119497.svg";
                productItem.Price = 1.00;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 7
                categoryItem.Name  = "Nuts";
                categoryItem.Noise = "Munch, Munch, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "Peanuts";
                productItem.Image      = "https://image.flaticon.com/icons/svg/811/811455.svg";
                productItem.Price      = 1.00;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 3;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 8
                productItem.Name  = "Cashews";
                productItem.Image = "https://image.flaticon.com/icons/svg/1256/1256949.svg";
                productItem.Price = 1.50;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 9
                productItem.Name  = "Sunflower Seeds";
                productItem.Image = "https://image.flaticon.com/icons/svg/188/188352.svg";
                productItem.Price = 1.25;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 10
                categoryItem.Name  = "Gum";
                categoryItem.Noise = "Chew, Chew, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "Hubba Bubba";
                productItem.Image      = "https://image.flaticon.com/icons/svg/287/287062.svg";
                productItem.Price      = 0.75;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 4;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 11
                productItem.Name  = "Bubble Yum";
                productItem.Image = "https://image.flaticon.com/icons/svg/1331/1331714.svg";
                productItem.Price = 0.75;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 12
                productItem.Name  = "Trident";
                productItem.Image = "https://image.flaticon.com/icons/svg/524/524402.svg";
                productItem.Price = 0.65;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);
                scope.Complete();
            }
        }
示例#5
0
        public static void PopulateDatabaseWithInventory(IVendingService db)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CategoryItem categoryItem = new CategoryItem()
                {
                    Name  = "Chips",
                    Noise = "Crunch, Crunch, Crunch, Yum!"
                };
                categoryItem.Id = db.AddCategoryItem(categoryItem);

                // Add Product 1
                ProductItem productItem = new ProductItem()
                {
                    Name       = "Lays Regular",
                    Price      = 0.50,
                    CategoryId = categoryItem.Id
                };
                productItem.Id = db.AddProductItem(productItem);

                InventoryItem inventoryItem = new InventoryItem()
                {
                    Column    = 1,
                    Row       = 1,
                    Qty       = 5,
                    ProductId = productItem.Id
                };
                inventoryItem.Id = db.AddInventoryItem(inventoryItem);

                // Add Product 2
                productItem.Name  = "Pringles Barbeque";
                productItem.Price = 0.65;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 3
                productItem.Name  = "Ruffles Sour Cream and Chives";
                productItem.Price = 0.75;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 4
                categoryItem.Name  = "Candy";
                categoryItem.Noise = "Lick, Lick, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "M&Ms Plain";
                productItem.Price      = 0.55;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 2;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 5
                productItem.Name  = "M&Ms Peanut";
                productItem.Price = 0.55;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 6
                productItem.Name  = "Gummy Bears";
                productItem.Price = 1.00;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 7
                categoryItem.Name  = "Nuts";
                categoryItem.Noise = "Munch, Munch, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "Peanuts";
                productItem.Price      = 1.00;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 3;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 8
                productItem.Name  = "Cashews";
                productItem.Price = 1.50;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 9
                productItem.Name  = "Sunflower Seeds";
                productItem.Price = 1.25;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 10
                categoryItem.Name  = "Gum";
                categoryItem.Noise = "Chew, Chew, Yum!";
                categoryItem.Id    = db.AddCategoryItem(categoryItem);

                productItem.Name       = "Hubba Bubba";
                productItem.Price      = 0.75;
                productItem.CategoryId = categoryItem.Id;
                productItem.Id         = db.AddProductItem(productItem);

                inventoryItem.Row       = 4;
                inventoryItem.Column    = 1;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 11
                productItem.Name  = "Bubble Yum";
                productItem.Price = 0.75;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 2;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);

                // Add Product 12
                productItem.Name  = "Trident";
                productItem.Price = 0.65;
                productItem.Id    = db.AddProductItem(productItem);

                inventoryItem.Column    = 3;
                inventoryItem.ProductId = productItem.Id;
                inventoryItem.Id        = db.AddInventoryItem(inventoryItem);
                scope.Complete();
            }
        }
        public void Initialize()
        {
            _db = new VendingDBService(_connectionString);
            //_db = new MockVendingDBService();

            // Initialize a new transaction scope. This automatically begins the transaction.
            _tran = new TransactionScope();

            PasswordManager passHelper = new PasswordManager("Abcd!234");

            if (_userId1 == BaseItem.InvalidId)
            {
                var temp = new UserItem()
                {
                    Id = BaseItem.InvalidId
                };
                temp.FirstName = "Amy";
                temp.LastName  = "Rupp";
                temp.Username  = "******";
                temp.Hash      = passHelper.Hash;
                temp.Salt      = passHelper.Salt;
                temp.Email     = "*****@*****.**";
                temp.RoleId    = (int)RoleManager.eRole.Customer;

                // Add user item
                _userId1 = _db.AddUserItem(temp);
                Assert.AreNotEqual(0, _userId1);
            }

            if (_userId2 == BaseItem.InvalidId)
            {
                var temp = new UserItem()
                {
                    Id = BaseItem.InvalidId
                };
                temp.FirstName = "Chloe";
                temp.LastName  = "Rupp";
                temp.Username  = "******";
                temp.Hash      = passHelper.Hash;
                temp.Salt      = passHelper.Salt;
                temp.Email     = "*****@*****.**";
                temp.RoleId    = (int)RoleManager.eRole.Customer;

                // Add user item
                _userId2 = _db.AddUserItem(temp);
                Assert.AreNotEqual(0, _userId2);
            }

            if (_categoryId == BaseItem.InvalidId)
            {
                var temp = new CategoryItem()
                {
                    Id = BaseItem.InvalidId
                };
                temp.Name  = "TestCategory";
                temp.Noise = "CategoryNoise";

                // Add category item
                _categoryId = _db.AddCategoryItem(temp);
                Assert.AreNotEqual(0, _categoryId);
            }

            if (_productId == BaseItem.InvalidId)
            {
                // Add product item
                _productId = _db.AddProductItem(
                    new ProductItem()
                {
                    Name       = "TestProduct",
                    Price      = 0.50,
                    CategoryId = _categoryId,
                    Image      = "http://localhost:8080/api/food/peanuts.jpg"
                });
                Assert.AreNotEqual(0, _productId);
            }

            if (_inventoryId == BaseItem.InvalidId)
            {
                // Add inventory item
                _inventoryId = _db.AddInventoryItem(
                    new InventoryItem()
                {
                    Row       = 1,
                    Column    = 1,
                    Qty       = 4,
                    ProductId = _productId
                });
                Assert.AreNotEqual(0, _inventoryId);
            }

            if (_vendingTransactionId == BaseItem.InvalidId)
            {
                // Add vending transaction
                _vendingTransactionId = _db.AddVendingTransaction(
                    new VendingTransaction()
                {
                    Date   = DateTime.UtcNow,
                    UserId = _userId1
                });
                Assert.AreNotEqual(0, _vendingTransactionId);
            }
        }