public void CheckOrderLocationReference()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Order    testOrder = new Order();
            Location testLoc   = new Location();

            String locName = "Testville";

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                //StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testLoc.LocationName    = locName;
                testOrder.orderLocation = testLoc;

                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal(locName, testOrder.orderLocation.LocationName);
            }
        }
        public void CheckAddLocation()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Location testLoc = new Location();

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                //StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testLoc.LocationName = "Kroger";

                context.Add(testLoc);
                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal("Kroger", testLoc.LocationName);
            }
        }
        public void TestInvalidQuantity(int value)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Product   testProd = new Product();
            Inventory testInv  = new Inventory();
            String    prodName = "Corn";
            bool      canCheckout;

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testProd.Description     = prodName;
                testInv.inventoryProduct = testProd;

                canCheckout = repo.CheckIfQuantityAvailable(testInv, value);

                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.False(canCheckout);
            }
        }
        public void TestTakeFromInventory()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Product   testProd  = new Product();
            Inventory testInv   = new Inventory();
            Order     testOrder = new Order();
            String    prodName  = "Device";
            int       num       = 9;

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testProd.Description     = prodName;
                testInv.inventoryProduct = testProd;

                repo.TakeFromInventoryAddToOrder(testInv, num, testOrder);

                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal(num, testOrder.orderQuantity);
            }
        }
        public void CheckAddProduct()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Product testProd = new Product();

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                //StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testProd.UnitPrice = 4.50m;

                context.Add(testProd);
                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal(4.50m, testProd.UnitPrice);
            }
        }
        public void CheckInventoryProductReference()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Product   testProd = new Product();
            Inventory testInv  = new Inventory();
            String    prodName = "Device";

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                //StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testProd.Description     = prodName;
                testInv.inventoryProduct = testProd;

                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal(prodName, testInv.inventoryProduct.Description);
            }
        }
        public void AddCustomerToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddCustomerToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new Customer
                {
                    FirstName    = "Test",
                    LastName     = "Name",
                    AddressLine1 = "Test",
                    AddressLine2 = "Address",
                    City         = "City",
                    State        = "TX",
                    ZipCode      = "75024",
                    Phone        = "(555)555-5555",
                    Email        = "*****@*****.**"
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.Customers);
            }
        }
        public void CheckUserName()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Customer testCust = new Customer();

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                //StoreRepositoryLayer repo = new StoreRepositoryLayer(context);
                testCust.UserName = "******";

                context.Add(testCust);
                context.SaveChanges();
            }

            //Assert
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal("jr", testCust.UserName);
            }
        }//UserName
        public void AddLocationToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddLocationToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new Location
                {
                    Name = "Test Location"
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.Locations);
            }
        }
        public void AddProductToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddProductToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new Product
                {
                    ProductName        = "Test Product",
                    ProductDescription = "Test description",
                    Price = Convert.ToDecimal(199.99)
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.Products);
            }
        }
        public void AddInventoryToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddInventoryToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new Inventory
                {
                    Location = new Location(),
                    Product  = new Product(),
                    Quantity = 10
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.Inventory);
            }
        }
        public void AddOrderProductToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddOrderProductToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new OrderProduct
                {
                    Order    = new Order(),
                    Product  = new Product(),
                    Quantity = 10
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.OrderProducts);
                Assert.Single(db.Orders);
                Assert.Single(db.Products);
            }
        }
        public void AddOrderToDatabase()
        {
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "AddOrderToDatabase")
                          .Options;

            using (var db = new Store_DbContext(options))
            {
                db.Add(new Order
                {
                    Customer          = new Customer(),
                    Location          = new Location(),
                    OrderCompleteTime = DateTime.Now
                });
                db.SaveChanges();
            }
            using (var db = new Store_DbContext(options))
            {
                Assert.Single(db.Orders);
                Assert.Single(db.Customers);
                Assert.Single(db.Locations);
            }
        }
        public void CheckAddInventory()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Inventory testInventory = new Inventory();

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Add(testInventory);
                context.SaveChanges();
            }
            //Arrange
            using (var context = new Store_DbContext(options))
            {
                Assert.Equal(100, testInventory.inventoryQuantity);
            }
        }
        public void CheckAddOrder()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Store_DbContext>()
                          .UseInMemoryDatabase(databaseName: "TestStore")
                          .Options;

            Order testOrder = new Order();

            //Act
            using (var context = new Store_DbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Add(testOrder);
                context.SaveChanges();
            }
            //Arrange
            using (var context = new Store_DbContext(options))
            {
                Assert.NotNull(testOrder.timeCreated);
            }
        }