/// <summary>
 /// 删除请求的新闻
 /// </summary>
 public void deleteRequestNews()
 {
     int id = int.Parse(Request.QueryString["newsId"]);
     News news = NewsHandler.getNewsById(id);
     NewsHandler newsHandler = new NewsHandler(news);
     newsHandler.Delete();
 }
 /// <summary>
 /// 插入新闻 
 /// </summary>
 public void insertNews()
 {
     News news = new News();
     news.content = content.Value;
     news.title = txtTitle.Text;
     news.type = int.Parse(typeRadioButtonList.SelectedItem.Value);
     news.publishTime = DateTime.Now;
     NewsHandler newsHandler = new NewsHandler(news);
     newsHandler.Insert();
 }
        public void DeleteTest()
        {
            News n = new News { title = "test", publishTime = DateTime.Parse("2011/1/1 0:00:00"), type = 0 };
            NewsHandler.DataClassesDataContext.News.InsertOnSubmit(n);
            NewsHandler.DataClassesDataContext.SubmitChanges();
            NewsHandler nh = new NewsHandler(n);
            nh.Delete();

            Assert.IsFalse(NewsHandler.DataClassesDataContext.News.Any(news => news.title == "test"));

            if (NewsHandler.DataClassesDataContext.News.Any(news => news.title == "test"))
            {
                NewsHandler.DataClassesDataContext.News.DeleteOnSubmit(n);
                NewsHandler.DataClassesDataContext.SubmitChanges();
            }
        }
 public void SubmitTest()
 {
     News n = new News { title="test", publishTime=DateTime.Parse("2011/1/1 0:00:00"), type=0};
     NewsHandler.DataClassesDataContext.News.InsertOnSubmit(n);
     NewsHandler nh = new NewsHandler(n);
     nh.Submit();
     try
     {
         Assert.IsTrue(NewsHandler.DataClassesDataContext.News.First(news => news.title == "test").Equals(n));
     }
     finally
     {
         NewsHandler.DataClassesDataContext.News.DeleteOnSubmit(n);
         NewsHandler.DataClassesDataContext.SubmitChanges();
     }
 }
 public void NewsHandlerConstructorTest()
 {
     News news = new News();
     NewsHandler newsHandler = new NewsHandler(news);
     Assert.AreSame(news, newsHandler.CurrentNews);
 }