Пример #1
0
 public void cannotCreateItemWithNegativePrice()
 {
     Assert.Catch(() =>
     {
         var x = new SportsItem("Basketball", "1556-SPAL-89", "Spalding", -39.99m, Currency.USD);
     });
 }
Пример #2
0
        static void Main(string[] args)
        {
            /* referencing first the variable. Item2 have to be declared in first place,
             * because it get initialized in the try block, this meens the variable is not visible outside that block */
            SportsItem item1;
            SportsItem item2;

            try
            {
                item2 = new SportsItem("", "Adidas", 29.95, "B787 56333");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                /* initializing correctly, but first output the error message
                 *  how can be forced a reentry of ther correct value? If this part get skipped, item2 would be uninitialized*/
                item2 = new SportsItem("Football", "Adidas", 29.95, "B787 56333");
            }
            item1 = new SportsItem("Touren Ski", "Hagan", 295.95, "A45 670087");

            /* CallInfo the print item method, to avoid write twice the same lines of code */
            item1.printItem();
            item2.printItem();

            /* Change the Price of the Ski */
            Console.WriteLine("New Price: ");
            /* update price is a public class method to update the private _price field*/
            item1.updatePrice(195.95);

            item1.printItem();
        }
Пример #3
0
        public void canUpdatePrice()
        {
            var x = new SportsItem("Volleyball", "14879-Han-32", "Hannahwald", 39.99m, Currency.JPY);

            x.UpdatePrice(25.75m, Currency.JPY);
            Assert.IsTrue(x.Price.Amount == 25.75m);
            Assert.IsTrue(x.Price.Unit == Currency.JPY);
        }
Пример #4
0
        public void canCreateNewEquipment()
        {
            var x = new SportsItem("Basketball", "1556-SPAL-89", "Spalding", 39.99m, Currency.EUR);

            Assert.IsTrue(x.Description == "Basketball");
            Assert.IsTrue(x.Brand == "Spalding");
            Assert.IsTrue(x.Price.Amount == 39.99m);
            Assert.IsTrue(x.Price.Unit == Currency.EUR);
            Assert.IsTrue(x.ArticleNumber == "1556-SPAL-89");
        }
Пример #5
0
        //保存
        protected void Button1_Click(object sender, EventArgs e)
        {
            //表示编辑功能
            if (Request.QueryString["type"] != null)
            {
                //编号
                int id         = Convert.ToInt32(Request.QueryString["id"].ToString());
                var sportsItem = Entity.SportsItem.FirstOrDefault(a => a.Id == id);//获取对象
                sportsItem.Name      = Name.Text;
                sportsItem.Type      = Type.Text;
                sportsItem.RefereeId = Convert.ToInt32(RefereeId.Text);
                sportsItem.FirstTime = Convert.ToDateTime(Request["FirstTime"]);
                sportsItem.FinalTime = Convert.ToDateTime(Request["FinalTime"]);
                sportsItem.Limit     = Limit.Text;
                sportsItem.Rule      = Rule.Text;
                sportsItem.Num       = Convert.ToInt32(Num.Text);
                //保存数据
                Entity.Entry(sportsItem).State = EntityState.Modified;
                Entity.SaveChanges();
                Message("Manage.aspx", "保存成功");
            }
            else
            {
                //表示添加功能
                SportsItem sportsItem = new SportsItem();
                sportsItem.Name      = Name.Text;
                sportsItem.Type      = Type.Text;
                sportsItem.RefereeId = Convert.ToInt32(RefereeId.Text);
                sportsItem.FirstTime = Convert.ToDateTime(Request["FirstTime"]);
                sportsItem.FinalTime = Convert.ToDateTime(Request["FinalTime"]);
                sportsItem.Limit     = Limit.Text;
                sportsItem.OperTime  = DateTime.Now;
                sportsItem.Num       = Convert.ToInt32(Num.Text);
                sportsItem.Rule      = Rule.Text;

                //插入数据
                Entity.SportsItem.Add(sportsItem);
                Entity.SaveChanges();
                Message("保存成功");
            }
        }
Пример #6
0
        public void canSerializeToDisk()
        {
            var x = new SportsItem("Volleyball", "14879-Han-32", "Hannahwald", 39.99m, Currency.JPY);

            IPrint[] xColl    = { x };
            var      filename = "test.json";

            Serialize.serializeToDisk(xColl, filename);

            IPrint[] g = Serialize.deserializeFromFilename(filename);
            Console.WriteLine("{0}, g");

            SportsItem gSpo = (SportsItem)g[0];

            Assert.IsTrue(gSpo.Description == "Volleyball");
            Assert.IsTrue(gSpo.Price.Amount == 39.99m);
            Assert.IsTrue(gSpo.Price.Unit == Currency.JPY);

            // Delete file after use
            Serialize.deleteFile(filename);
        }