public void GetPostsByCategoryIDReturnsDaysWithEnclosure() { //Create Category int blogId = Config.CurrentBlog.Id; int categoryId = UnitTestHelper.CreateCategory(blogId, "Test Category"); //Create some entries. Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); Thread.Sleep(100); Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryThree.DateCreated = DateTime.Now.AddDays(1); //Associate Category entryZero.Categories.Add("Test Category"); entryOne.Categories.Add("Test Category"); entryThree.Categories.Add("Test Category"); //Persist entries. UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); UnitTestHelper.Create(entryTwo); UnitTestHelper.Create(entryThree); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); Enclosures.Create(enc); //Get EntryDay ICollection <EntryDay> entryList = ObjectProvider.Instance().GetBlogPostsByCategoryGroupedByDay(10, categoryId).ToList(); var days = new EntryDay[2]; entryList.CopyTo(days, 0); //Test outcome Assert.AreEqual(2, entryList.Count, "Expected to find two days."); EntryDay entries = days[1]; Assert.AreEqual(2, entries.Count, "Expected to find two entries."); Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure); }
public void GetHomePageEntriesReturnsDaysWithEnclosure() { //Create some entries. Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); entryZero.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); entryZero.IsActive = entryZero.IncludeInMainSyndication = true; Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); entryOne.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); entryOne.IsActive = entryOne.IncludeInMainSyndication = true; Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryTwo.DisplayOnHomePage = false; Thread.Sleep(100); Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryThree.IsActive = entryThree.IncludeInMainSyndication = true; //Persist entries. UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); UnitTestHelper.Create(entryTwo); UnitTestHelper.Create(entryThree); var repository = new DatabaseObjectProvider(); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); repository.Create(enc); //Get EntryDay ICollection <EntryDay> entryList = repository.GetBlogPostsForHomePage(10, PostConfig.DisplayOnHomepage | PostConfig.IsActive).ToList(); var days = new EntryDay[2]; entryList.CopyTo(days, 0); //Test outcome Assert.AreEqual(2, entryList.Count, "Expected to find two days."); EntryDay entries = days[1]; Assert.AreEqual(2, entries.Count, "Expected to find two entries."); Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure); }
public override EntryDay GetEntryDay(DateTime dateTime) { using (IDataReader reader = _procedures.GetEntriesByDayRange(dateTime.Date, dateTime.Date.AddDays(1), (int)PostType.BlogPost, true, BlogId, CurrentDateTime)) { var entryDay = new EntryDay(dateTime); while (reader.Read()) { entryDay.Add(reader.ReadEntry()); } return(entryDay); } }
public void GetSingleDayReturnsDayWithEnclosure() { //Create some entries. var repository = new DatabaseObjectProvider(); Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); //Persist entries. UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); UnitTestHelper.Create(entryTwo); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); repository.Create(enc); //Get EntryDay EntryDay entries = repository.GetEntryDay(DateTime.UtcNow); //Test outcome Assert.AreEqual(3, entries.Count, "Expected to find three entries."); Assert.AreEqual(entries.First().Id, entryTwo.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(1).Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(2).Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure."); Assert.IsNull(entries.ElementAt(1).Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries.ElementAt(2).Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(2).Enclosure); }
public void GetPostsByCategoryIDReturnsDaysWithEnclosure() { //Create Category int blogId = Config.CurrentBlog.Id; int categoryId = UnitTestHelper.CreateCategory(blogId, "Test Category"); //Create four entries. Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); entryZero.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); entryOne.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryTwo.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); Thread.Sleep(100); Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-three", "body-two"); entryThree.DatePublishedUtc = DateTime.UtcNow; //Associate Category entryZero.Categories.Add("Test Category"); entryOne.Categories.Add("Test Category"); entryThree.Categories.Add("Test Category"); //Persist entries. UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); UnitTestHelper.Create(entryTwo); UnitTestHelper.Create(entryThree); var repository = new DatabaseObjectProvider(); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); repository.Create(enc); //Get EntryDay ICollection<EntryDay> entryList = repository.GetBlogPostsByCategoryGroupedByDay(10, categoryId).ToList(); var days = new EntryDay[2]; entryList.CopyTo(days, 0); //Test outcome Assert.AreEqual(2, entryList.Count, "Expected to find two days."); EntryDay entries = days[1]; Assert.AreEqual(2, entries.Count, "Expected to find two entries."); Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure); }
public void GetHomePageEntriesReturnsDaysWithEnclosure() { //Create some entries. Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); entryZero.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); entryZero.IsActive = entryZero.IncludeInMainSyndication = true; Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); entryOne.DatePublishedUtc = DateTime.UtcNow.AddDays(-1); entryOne.IsActive = entryOne.IncludeInMainSyndication = true; Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryTwo.DisplayOnHomePage = false; Thread.Sleep(100); Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryThree.IsActive = entryThree.IncludeInMainSyndication = true; //Persist entries. UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); UnitTestHelper.Create(entryTwo); UnitTestHelper.Create(entryThree); var repository = new DatabaseObjectProvider(); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); repository.Create(enc); //Get EntryDay ICollection<EntryDay> entryList = repository.GetBlogPostsForHomePage(10, PostConfig.DisplayOnHomepage | PostConfig.IsActive).ToList(); var days = new EntryDay[2]; entryList.CopyTo(days, 0); //Test outcome Assert.AreEqual(2, entryList.Count, "Expected to find two days."); EntryDay entries = days[1]; Assert.AreEqual(2, entries.Count, "Expected to find two entries."); Assert.AreEqual(entries.First().Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries.ElementAt(1).Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries.First().Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries.ElementAt(1).Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries.ElementAt(1).Enclosure); }
public static IList<EntryDay> LoadEntryDayCollection(IDataReader reader) { DateTime dt = new DateTime(1900, 1, 1); List<EntryDay> edc = new List<EntryDay>(); EntryDay day = null; while(reader.Read()) { if(IsNewDay(dt, (DateTime)reader["DateAdded"])) { dt = (DateTime)reader["DateAdded"]; day = new EntryDay(dt); edc.Add(day); } day.Add(LoadEntry(reader)); } return edc; }
public override EntryDay GetEntryDay(DateTime dateTime) { using (IDataReader reader = _procedures.GetEntriesByDayRange(dateTime.Date, dateTime.Date.AddDays(1), (int)PostType.BlogPost, true, BlogId, CurrentDateTimeUtc)) { var entryDay = new EntryDay(dateTime); while (reader.Read()) { entryDay.Add(reader.ReadEntry()); } return entryDay; } }
public void GetPostsByMonthReturnsDaysWithEnclosure() { //Create some entries. Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); Thread.Sleep(100); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); Thread.Sleep(100); Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two"); entryThree.DateCreated = DateTime.Now.AddDays(1); //Persist entries. Entries.Create(entryZero); Entries.Create(entryOne); Entries.Create(entryTwo); Entries.Create(entryThree); //Add Enclosure Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); Enclosures.Create(enc); //Get EntryDay IList<EntryDay> entryList = Entries.GetPostsByMonth(DateTime.Now.Month, DateTime.Now.Year); EntryDay[] days = new EntryDay[2]; entryList.CopyTo(days, 0); //Test outcome Assert.AreEqual(2, entryList.Count, "Expected to find two days."); EntryDay entries = days[1]; Assert.AreEqual(3, entries.Count, "Expected to find three entries."); Assert.AreEqual(entries[0].Id, entryTwo.Id, "Ordering is off."); Assert.AreEqual(entries[1].Id, entryOne.Id, "Ordering is off."); Assert.AreEqual(entries[2].Id, entryZero.Id, "Ordering is off."); Assert.IsNull(entries[0].Enclosure, "Entry should not have enclosure."); Assert.IsNull(entries[1].Enclosure, "Entry should not have enclosure."); Assert.IsNotNull(entries[2].Enclosure, "Entry should have enclosure."); UnitTestHelper.AssertEnclosures(enc, entries[2].Enclosure); }
public override EntryDay GetEntryDay(DateTime dt) { IDataReader reader = DbProvider.Instance().GetEntryDayReader(dt); try { EntryDay ed = new EntryDay(dt); while(reader.Read()) { ed.Add(DataHelper.LoadEntry(reader)); } return ed; } finally { reader.Close(); } }
public void CanSetAndGetSimpleEntryDayProperties() { EntryDay day = new EntryDay(); UnitTestHelper.AssertSimpleProperties(day); }