Пример #1
0
 public ActionResult Index(CustomerOrderItemMaster c)
 {
     obj.CreateOrder(c);
     ViewBag.CustomerId = new SelectList(obj.GetCustomers(), "CustomerId", "CustomerName");
     ViewBag.ItemId     = new SelectList(obj.GetItems(), "ItemId", "ItemName");
     return(View(c));
 }
        public void TestSubmitEmptyOrder()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <BaB_DbContext>()
                          .UseInMemoryDatabase(databaseName: "Test8Db")
                          .Options;

            //Act
            Customer testCustomer;

            #region Test database seeding
            using (var context = new BaB_DbContext(options))
            {
                #region Customers
                //Add customers to database for sampling from
                Customer testCustomer1 = new Customer
                {
                    CustFirstName = "Annie",
                    CustLastName  = "Admin",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                Customer testCustomer2 = new Customer
                {
                    CustFirstName = "Becky",
                    CustLastName  = "Boss",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                context.Add(testCustomer1);
                context.Add(testCustomer2);
                #endregion

                #region LocationCountry
                //Add Location Country to the test database
                LocationCountry testLocationCountry = new LocationCountry
                {
                    Country = "USA"
                };

                context.Add(testLocationCountry);
                #endregion

                #region LocationState
                //Add Location State to the test database
                LocationState testLocationState = new LocationState
                {
                    State = "Illinois"
                };

                context.Add(testLocationState);
                #endregion

                #region Locations
                //Add locations to the test database
                Location testLocation1 = new Location
                {
                    LocationAddress = "1 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                Location testLocation2 = new Location
                {
                    LocationAddress = "2 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                context.Add(testLocation1);
                context.Add(testLocation2);
                #endregion

                testCustomer = testCustomer1;

                context.SaveChanges();
            }
            #endregion

            PlaceOrder testPlaceOrder = new PlaceOrder();

            using (var context = new BaB_DbContext(options))
            {
                testPlaceOrder.CreateOrder(new UnitTest8Inputs(), context, testCustomer);
            }

            //Assert
            using (var context = new BaB_DbContext(options))
            {
                Assert.Equal(0, context.OrderLineItemsDB.Count());
            }
        }
        public void TestRemoveItemFromOrder()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <BaB_DbContext>()
                          .UseInMemoryDatabase(databaseName: "Test10Db")
                          .Options;

            //Act
            Customer testCustomer;

            #region Test database seeding
            using (var context = new BaB_DbContext(options))
            {
                #region Customers
                //Add customers to database for sampling from
                Customer testCustomer1 = new Customer
                {
                    CustFirstName = "Annie",
                    CustLastName  = "Admin",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                Customer testCustomer2 = new Customer
                {
                    CustFirstName = "Becky",
                    CustLastName  = "Boss",
                    CustUsername  = "******",
                    CustPassword  = "******"
                };

                context.Add(testCustomer1);
                context.Add(testCustomer2);
                #endregion

                #region LocationCountry
                //Add Location Country to the test database
                LocationCountry testLocationCountry = new LocationCountry
                {
                    Country = "USA"
                };

                context.Add(testLocationCountry);
                #endregion

                #region LocationState
                //Add Location State to the test database
                LocationState testLocationState = new LocationState
                {
                    State = "Illinois"
                };

                context.Add(testLocationState);
                #endregion

                #region Products
                //Add a product to the database for building with
                Product testProduct1 = new Product
                {
                    ProductName  = "Test product 1",
                    ProductPrice = 1
                };

                Product testProduct2 = new Product
                {
                    ProductName  = "Test product 2",
                    ProductPrice = 1
                };

                Product testProduct3 = new Product
                {
                    ProductName  = "Test product 3",
                    ProductPrice = 1
                };

                context.Add(testProduct1);
                context.Add(testProduct2);
                context.Add(testProduct3);
                #endregion

                #region Locations
                //Add locations to the test database
                Location testLocation1 = new Location
                {
                    LocationAddress = "1 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                Location testLocation2 = new Location
                {
                    LocationAddress = "2 Street",
                    LocationState   = testLocationState,
                    LocationCountry = testLocationCountry
                };

                context.Add(testLocation1);
                context.Add(testLocation2);
                #endregion

                #region Inventory
                //Add inventory to locations
                Inventory testInventory1 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct1,
                    QuantityAvailable = 15
                };

                Inventory testInventory2 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct2,
                    QuantityAvailable = 15
                };

                Inventory testInventory3 = new Inventory
                {
                    InventoryLocation = testLocation1,
                    InventoryProduct  = testProduct3,
                    QuantityAvailable = 15
                };

                Inventory testInventory4 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct1,
                    QuantityAvailable = 15
                };

                Inventory testInventory5 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct2,
                    QuantityAvailable = 15
                };

                Inventory testInventory6 = new Inventory
                {
                    InventoryLocation = testLocation2,
                    InventoryProduct  = testProduct3,
                    QuantityAvailable = 15
                };

                context.Add(testInventory1);
                context.Add(testInventory2);
                context.Add(testInventory3);
                context.Add(testInventory4);
                context.Add(testInventory5);
                context.Add(testInventory6);
                #endregion

                testCustomer = testCustomer1;

                context.SaveChanges();
            }
            #endregion

            PlaceOrder testPlaceOrder = new PlaceOrder();

            using (var context = new BaB_DbContext(options))
            {
                testPlaceOrder.CreateOrder(new UnitTest11Inputs(), context, testCustomer);
            }

            //Assert
            using (var context = new BaB_DbContext(options))
            {
                Assert.Equal(0, context.OrderLineItemsDB.Count());
                Assert.Equal(0, context.OrdersDB.Count());
            }
        }