public NewsViewModel.Preview CreateNews(String title) { YoumotoDbContext context = this.context ?? new YoumotoDbContext(); News newNews = NewsPersister.Create(title); context.News.Add(newNews); context.SaveChanges(); return(new NewsViewModel.Preview(newNews)); }
public void CreateAndSaveNews() { using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient())) { News news = NewsPersister.Create(NewsTests.newsTitle); context.News.Add(news); context.SaveChanges(); Assert.AreEqual(NewsTests.newsTitle, news.Title); } }
//Methods #region CreateTestNews private List <News> CreateTestNews(int newsCount, YoumotoDbContext context) { List <News> testNews = new List <News>(); newsCount.Times(index => { News news = NewsPersister.Create(NewsTests.newsTitle + index.ToString()); news.Date = DateTime.UtcNow.AddDays(newsCount * -1).AddDays(index); testNews.Add(news); context.News.Add(news); }); return(testNews); }
public void CreateNewsPicture() { using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient())) { String url = "https://www.youmoto.com/test.jpg"; News news = NewsPersister.Create("MyTitle"); NewsPicture newsPicture = NewsPersister.CreatePicture(news, url); context.News.Add(news); context.SaveChanges(); Assert.AreEqual(1, context.News.Count()); Assert.AreEqual(1, context.NewsPictures.Count()); Assert.AreEqual(1, context.News.First().NewsPictures.Count()); Assert.AreEqual(url, context.News.First().NewsPictures.First().ImageLink); } }