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 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 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);
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }