public void getNewsByIdTest()
        {
            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();

            News expected = NewsHandler.DataClassesDataContext.News.First(news => news.title == "test");
            News actual = NewsHandler.getNewsById(expected.newsId);

            NewsHandler.DataClassesDataContext.News.DeleteOnSubmit(n);
            NewsHandler.DataClassesDataContext.SubmitChanges();
            Assert.AreSame(expected, actual);
        }
        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 NewsHandlerConstructorTest()
 {
     News news = new News();
     NewsHandler newsHandler = new NewsHandler(news);
     Assert.AreSame(news, newsHandler.CurrentNews);
 }
 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();
     }
 }
 partial void DeleteNews(News instance);
 partial void UpdateNews(News instance);
 partial void InsertNews(News instance);
 /// <summary>
 /// 基于一个News对象的构造函数
 /// </summary>
 /// <param name="news">当前关联的News</param>
 public NewsHandler(News news)
 {
     currentNews = news;
 }
 /// <summary>
 /// 将当前关联的News对象从数据库中删除
 /// </summary>
 public void Delete()
 {
     try
     {
         dataClassesDataContext.News.DeleteOnSubmit(currentNews);
         Submit();
         currentNews = null;
     }
     catch (Exception)
     {
         throw new DeleteException();
     }
 }