示例#1
0
        public void AddMethodOK()
        {
            //create an instance of the class we want to create
            clsFoodCollection AllFood = new clsFoodCollection();
            //create the item of the test data
            clsFood TestItem = new clsFood();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.FoodID    = "1";
            TestItem.FoodName  = "Steak";
            TestItem.FoodPrice = "£20";
            TestItem.Quantity  = "2";
            //set ThisAddress to the test data
            AllFood.ThisFood = TestItem;
            //add the record
            PrimaryKey = AllFood.Add();
            //set the primary key of the test data
            TestItem.FoodID = PrimaryKey;
            //find the record
            AllFood.ThisFood.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllFood.ThisFood, TestItem);
        }
示例#2
0
        void Add()
        {
            clsFoodCollection Foods = new clsFoodCollection();

            Foods.ThisFood.FoodID = -1;
            if (Foods.ThisFood.FoodID == -1)
            {
                Foods.ThisFood.FoodName  = textBox1.Text;
                Foods.ThisFood.FoodType  = textBox3.Text;
                Foods.ThisFood.SellPrice = Convert.ToDecimal(textBox2.Text);
                Foods.Add();
            }
            else
            {
                lblError.Text = "There were problems with the data entered.";
            }
        }