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);
            }
        }
        public void TestProduct()
        {
            // Test add product
            ProductItem item = new ProductItem();

            item.CategoryId = _categoryId;
            item.Name       = "Blah";
            item.Price      = 1.00;
            item.Image      = "Yeah";
            int id = _db.AddProductItem(item);

            Assert.AreNotEqual(0, id);

            ProductItem itemGet = _db.GetProductItem(id);

            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.Name, itemGet.Name);
            Assert.AreEqual(item.Price, itemGet.Price);
            Assert.AreEqual(item.CategoryId, itemGet.CategoryId);
            Assert.AreEqual(item.Image, itemGet.Image);

            // Test update product
            item.Name  = "What";
            item.Price = 1.50;
            Assert.IsTrue(_db.UpdateProductItem(item));

            itemGet = _db.GetProductItem(id);
            Assert.AreEqual(item.Id, itemGet.Id);
            Assert.AreEqual(item.Name, itemGet.Name);
            Assert.AreEqual(item.Price, itemGet.Price);
            Assert.AreEqual(item.CategoryId, itemGet.CategoryId);
            Assert.AreEqual(item.Image, itemGet.Image);

            // Test delete product
            _db.DeleteProductItem(id);
            var products = _db.GetProductItems();

            foreach (var product in products)
            {
                Assert.AreNotEqual(id, product.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();
            }
        }
Beispiel #4
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);
            }
        }