public void RssHandlerHandlesDatePublishedUtcProperly() { // arrange string hostName = UnitTestHelper.GenerateUniqueHostname(); var repository = new DatabaseObjectProvider(); UnitTestHelper.SetHttpContextWithBlogRequest(hostName, ""); repository.CreateBlog("", "username", "password", hostName, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty); //Create two entries, but only include one in main syndication. Entry entryForSyndication = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test", "Body Rocking"); UnitTestHelper.Create(entryForSyndication); Entry entryTwoForSyndication = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test 2", "Body Rocking Pt 2"); int id = UnitTestHelper.Create(entryTwoForSyndication); Entry entry = UnitTestHelper.GetEntry(id, PostConfig.None, false); DateTime date = entry.DatePublishedUtc; entry.IncludeInMainSyndication = false; entry.Blog = new Blog() { Title = "MyTestBlog" }; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); subtextContext.Setup(c => c.Repository).Returns(repository); UnitTestHelper.Update(entry, subtextContext.Object); Assert.AreEqual(date, entry.DatePublishedUtc); string rssOutput = null; subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s); Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper); urlHelper.Setup(u => u.BlogUrl()).Returns("/"); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever"); XmlNodeList itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput); Assert.AreEqual(1, itemNodes.Count, "expected one item node."); Assert.AreEqual("Title Test", itemNodes[0].SelectSingleNode("title").InnerText, "Not what we expected for the first title."); Assert.AreEqual("Body Rocking", itemNodes[0].SelectSingleNode("description").InnerText.Substring(0, "Body Rocking".Length), "Not what we expected for the first body."); //Include the second entry back in the syndication. entry.IncludeInMainSyndication = true; UnitTestHelper.Update(entry, subtextContext.Object); UnitTestHelper.SetHttpContextWithBlogRequest(hostName, "", ""); BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty); subtextContext = new Mock<ISubtextContext>(); subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s); subtextContext.Setup(c => c.Repository).Returns(repository); urlHelper = Mock.Get(subtextContext.Object.UrlHelper); urlHelper.Setup(u => u.BlogUrl()).Returns("/"); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever"); itemNodes = GetRssHandlerItemNodes(subtextContext.Object, ref rssOutput); Assert.AreEqual(2, itemNodes.Count, "Expected two items in the feed now."); }
public void GetBlogInfoFindsBlogWithUniqueHostAndSubfolder() { var repository = new DatabaseObjectProvider(); string subfolder1 = UnitTestHelper.GenerateUniqueString(); string subfolder2 = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("title", "username", "password", hostName, subfolder1); repository.CreateBlog("title", "username", "password", hostName, subfolder2); Blog info = repository.GetBlog(hostName, subfolder1); Assert.IsNotNull(info, "Could not find the blog with the unique hostName & subfolder combination."); Assert.AreEqual(info.Subfolder, subfolder1, "Oops! Looks like we found the wrong Blog!"); info = repository.GetBlog(hostName, subfolder2); Assert.IsNotNull(info, "Could not find the blog with the unique hostName & subfolder combination."); Assert.AreEqual(info.Subfolder, subfolder2, "Oops! Looks like we found the wrong Blog!"); }
public void CreateTrackbackSetsFeedbackTypeCorrectly() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty, string.Empty); Blog blog = repository.GetBlog(hostname, string.Empty); BlogRequest.Current.Blog = blog; Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "title", "body"); int parentId = UnitTestHelper.Create(entry); var trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Setup(c => c.Cache).Returns(new TestCache()); subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable()); var commentService = new CommentService(subtextContext.Object, null); int id = commentService.Create(trackback, true/*runFilters*/); FeedbackItem loadedTrackback = repository.Get(id); Assert.IsNotNull(loadedTrackback, "Was not able to load trackback from storage."); Assert.AreEqual(FeedbackType.PingTrack, loadedTrackback.FeedbackType, "Feedback should be a PingTrack"); }
public void TrackbackShowsUpInFeedbackList() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, "blog"); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "blog", string.Empty); Blog blog = repository.GetBlog(hostname, "blog"); BlogRequest.Current.Blog = blog; Entry parentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("philsath aeuoa asoeuhtoensth", "sntoehu title aoeuao eu", "snaot hu aensaoehtu body"); int parentId = UnitTestHelper.Create(parentEntry); ICollection<FeedbackItem> entries = repository.GetFeedbackForEntry(parentEntry); Assert.AreEqual(0, entries.Count, "Did not expect any feedback yet."); var trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); Config.CurrentBlog.DuplicateCommentsEnabled = true; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Cache).Returns(new TestCache()); subtextContext.SetupBlog(Config.CurrentBlog); subtextContext.SetupRepository(repository); subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable()); var commentService = new CommentService(subtextContext.Object, null); int trackbackId = commentService.Create(trackback, true/*runFilters*/); new DatabaseObjectProvider().Approve(trackback, null); entries = repository.GetFeedbackForEntry(parentEntry); Assert.AreEqual(1, entries.Count, "Expected a trackback."); Assert.AreEqual(trackbackId, entries.First().Id, "The feedback was not the same one we expected. The IDs do not match."); }
public void SettingDatePublishedUtcToNullRemovesItemFromSyndication() { //arrange var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", _hostName, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(_hostName, string.Empty); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test", "Body Rocking"); UnitTestHelper.Create(entry); Assert.IsTrue(entry.IncludeInMainSyndication, "Failed to setup this test properly. This entry should be included in the main syndication."); Assert.IsFalse(entry.DatePublishedUtc.IsNull(), "Failed to setup this test properly. DateSyndicated should be null."); //act entry.DatePublishedUtc = NullValue.NullDateTime; //assert Assert.IsFalse(entry.IncludeInMainSyndication, "Setting the DateSyndicated to a null date should have reset 'IncludeInMainSyndication'."); //save it var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); subtextContext.Setup(c => c.Repository).Returns(repository); UnitTestHelper.Update(entry, subtextContext.Object); Entry savedEntry = UnitTestHelper.GetEntry(entry.Id, PostConfig.None, false); //assert again Assert.IsFalse(savedEntry.IncludeInMainSyndication, "This item should still not be included in main syndication."); }
public void CanSetAndGetSimpleEntryStatsViewProperties() { string host = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlogInternal("title", "blah", "blah", host, string.Empty, 1); UnitTestHelper.SetHttpContextWithBlogRequest(host, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(host, string.Empty); var view = new EntryStatsView(); UnitTestHelper.AssertSimpleProperties(view); }
public void GetBlogInfoDoesNotFindBlogWithWrongSubfolderInMultiBlogSystem() { var repository = new DatabaseObjectProvider(); string subfolder1 = UnitTestHelper.GenerateUniqueString(); string subfolder2 = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("title", "username", "password", hostName, subfolder1); repository.CreateBlog("title", "username", "password", hostName, subfolder2); Blog info = repository.GetBlog(hostName, string.Empty); Assert.IsNull(info, "Hmm... Looks like found a blog using too generic of search criteria."); }
public void TagDoesNotRetrieveDraftEntry() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlogInternal("", "username", "password", hostname, string.Empty, 1); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); entry.IsActive = false; UnitTestHelper.Create(entry); var tags = new List<string>(new[] { "Tag1", "Tag2" }); new DatabaseObjectProvider().SetEntryTagList(entry.Id, tags); ICollection<Entry> entries = repository.GetEntriesByTag(1, "Tag1"); Assert.AreEqual(0, entries.Count, "Should not retrieve draft entry."); }
public void AtomWriterProducesValidFeedFromDatabase() { string hostName = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("Test", "username", "password", hostName, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostName, ""); BlogRequest.Current.Blog = repository.GetBlog(hostName, string.Empty); Config.CurrentBlog.Email = "*****@*****.**"; Config.CurrentBlog.RFC3229DeltaEncodingEnabled = false; DateTime dateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Author", "testtitle", "testbody", null, dateCreated); UnitTestHelper.Create(entry); //persist to db. var subtextContext = new Mock<ISubtextContext>(); string rssOutput = null; subtextContext.FakeSyndicationContext(Config.CurrentBlog, "/", s => rssOutput = s); subtextContext.Setup(c => c.Repository).Returns(repository); Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper); urlHelper.Setup(u => u.BlogUrl()).Returns("/"); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/2008/01/23/testtitle.aspx"); var handler = new AtomHandler(subtextContext.Object); handler.ProcessRequest(); HttpContext.Current.Response.Flush(); var doc = new XmlDocument(); doc.LoadXml(rssOutput); var nsmanager = new XmlNamespaceManager(doc.NameTable); nsmanager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); XmlNodeList itemNodes = doc.SelectNodes("/atom:feed/atom:entry", nsmanager); Assert.AreEqual(1, itemNodes.Count, "expected one entry node."); Assert.AreEqual("testtitle", itemNodes[0].SelectSingleNode("atom:title", nsmanager).InnerText, "Not what we expected for the title."); string urlFormat = "http://{0}/archive/2008/01/23/{1}.aspx"; string expectedUrl = string.Format(urlFormat, hostName, "testtitle"); Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:id", nsmanager).InnerText, "Not what we expected for the link."); Assert.AreEqual(expectedUrl, itemNodes[0].SelectSingleNode("atom:link/@href", nsmanager).InnerText, "Not what we expected for the link."); }
public void CanDeleteEntry() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", _hostName, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(_hostName, string.Empty); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Haacked", "Title Test", "Body Rocking"); UnitTestHelper.Create(entry); Entry savedEntry = UnitTestHelper.GetEntry(entry.Id, PostConfig.None, false); Assert.IsNotNull(savedEntry); repository.DeleteEntry(entry.Id); savedEntry = UnitTestHelper.GetEntry(entry.Id, PostConfig.None, false); Assert.IsNull(savedEntry, "Entry should now be null."); }
public void GetPreviousAndNextBasedOnSyndicationDateNotEntryId() { var repository = new DatabaseObjectProvider(); string hostname = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty); Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body"); Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body"); Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body"); previousEntry.IsActive = false; currentEntry.IsActive = false; nextEntry.IsActive = false; //Create out of order. int currentId = UnitTestHelper.Create(currentEntry); int nextId = UnitTestHelper.Create(nextEntry); int previousId = UnitTestHelper.Create(previousEntry); //Now syndicate. previousEntry.IsActive = true; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); subtextContext.Setup(c => c.Repository).Returns(repository); UnitTestHelper.Update(previousEntry, subtextContext.Object); Thread.Sleep(100); currentEntry.IsActive = true; UnitTestHelper.Update(currentEntry, subtextContext.Object); Thread.Sleep(100); nextEntry.IsActive = true; UnitTestHelper.Update(nextEntry, subtextContext.Object); Assert.IsTrue(previousId > currentId, "Ids are out of order."); var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost); Assert.AreEqual(2, entries.Count, "Expected both previous and next."); //The first should be next because of descending sort. Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations."); Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations."); }
public void DeleteEntrySetsBlogStats() { var repository = new DatabaseObjectProvider(); Entry entry = SetupBlogForCommentsAndCreateEntry(repository); Blog info = Config.CurrentBlog; CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.PingTrack, FeedbackStatusFlag.Approved); Blog blog = repository.GetBlog(info.Host, info.Subfolder); Assert.AreEqual(1, blog.CommentCount, "Blog CommentCount should be 1"); Assert.AreEqual(1, blog.PingTrackCount, "Blog Ping/Trackback count should be 1"); repository.DeleteEntry(entry.Id); blog = repository.GetBlog(info.Host, info.Subfolder); Assert.AreEqual(0, blog.CommentCount, "Blog CommentCount should be 0"); Assert.AreEqual(0, blog.PingTrackCount, "Blog Ping/Trackback count should be 0"); }
public void CreateFeedbackSetsBlogStatsCorrectly() { var repository = new DatabaseObjectProvider(); Entry entry = SetupBlogForCommentsAndCreateEntry(); Blog info = Config.CurrentBlog; Assert.AreEqual(0, info.CommentCount); Assert.AreEqual(0, info.PingTrackCount); info = repository.GetBlog(info.Host, info.Subfolder); // pull back the updated info from the datastore. Assert.AreEqual(0, info.CommentCount); Assert.AreEqual(0, info.PingTrackCount); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.PingTrack, FeedbackStatusFlag.Approved); info = repository.GetBlog(info.Host, info.Subfolder); Assert.AreEqual(1, info.CommentCount, "Blog CommentCount should be 1"); Assert.AreEqual(1, info.PingTrackCount, "Blog Ping/Trackback count should be 1"); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.PingTrack, FeedbackStatusFlag.Approved); info = repository.GetBlog(info.Host, info.Subfolder); Assert.AreEqual(2, info.CommentCount, "Blog CommentCount should be 2"); Assert.AreEqual(2, info.PingTrackCount, "Blog Ping/Trackback count should be 2"); }
public void CreateEntryDoesNotResetBlogStats() { var repository = new DatabaseObjectProvider(); Entry entry = SetupBlogForCommentsAndCreateEntry(); Blog info = Config.CurrentBlog; CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.PingTrack, FeedbackStatusFlag.Approved); Entry entry2 = UnitTestHelper.CreateEntryInstanceForSyndication("johnny b goode", "foo-bar", "zaa zaa zoo."); UnitTestHelper.Create(entry2); info = repository.GetBlog(info.Host, info.Subfolder); // pull back the updated info from the datastore Assert.AreEqual(1, info.CommentCount, "Blog CommentCount should be 1"); Assert.AreEqual(1, info.PingTrackCount, "Blog Ping/Trackback count should be 1"); }
public void UpdateBlogCannotConflictWithDuplicateHostAndSubfolder() { var repository = new DatabaseObjectProvider(); string secondHost = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("title", "username", "password", _hostName, "MyBlog"); repository.CreateBlog("title", "username2", "password2", secondHost, "MyBlog"); Blog info = repository.GetBlog(secondHost, "MyBlog"); info.Host = _hostName; UnitTestHelper.AssertThrows<BlogDuplicationException>(() => repository.UpdateConfigData(info)); }
public void CannotRenameBlogToHaveSubfolderNameBin() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "blah", "blah", _hostName, "Anything"); Blog info = repository.GetBlog(_hostName, "Anything"); info.Subfolder = "bin"; UnitTestHelper.AssertThrows<InvalidSubfolderNameException>(() => repository.UpdateConfigData(info)); }
public void Setup() { var repository = new DatabaseObjectProvider(); string hostname = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("", "username", "password", hostname, ""); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "", ""); BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty); }
public void CreatingBlogHashesPassword() { const string password = "******"; string hashedPassword = SecurityHelper.HashPassword(password); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", password, _hostName, "MyBlog1"); Blog info = repository.GetBlog(_hostName, "MyBlog1"); Assert.IsNotNull(info, "We tried to get blog at " + _hostName + "/MyBlog1 but it was null"); Config.Settings.UseHashedPasswords = true; Assert.IsTrue(Config.Settings.UseHashedPasswords, "This test is voided because we're not hashing passwords"); Assert.AreEqual(hashedPassword, info.Password, "The password wasn't hashed."); }
public void SettingShowEmailAddressInRssFlagDoesntChangeOtherFlags() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", hostName, string.Empty); Blog info = repository.GetBlog(hostName, string.Empty); bool test = info.IsAggregated; info.ShowEmailAddressInRss = false; repository.UpdateConfigData(info); info = repository.GetBlog(hostName, string.Empty); Assert.AreEqual(test, info.IsAggregated); }
public void UpdatingBlogCannotHideAnotherBlog() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", "www.mydomain.com", string.Empty); Blog info = repository.GetBlog("www.mydomain.com", string.Empty); info.Host = "mydomain.com"; info.Subfolder = "MyBlog"; repository.UpdateConfigData(info); }
public void UpdatingBlogIsFine() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", _hostName, string.Empty); Blog info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), string.Empty); info.Author = "Phil"; repository.UpdateConfigData(info); //Make sure no exception is thrown. }
public void GetRecentPosts_ReturnsRecentPosts() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, ""); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); Blog blog = repository.GetBlog(hostname, ""); BlogRequest.Current.Blog = blog; blog.AllowServiceAccess = true; var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/entry/whatever"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.SetupBlog(blog); subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object); var api = new MetaWeblog(subtextContext.Object); Post[] posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(0, posts.Length); string category1Name = UnitTestHelper.GenerateUniqueString(); string category2Name = UnitTestHelper.GenerateUniqueString(); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name); var entry = new Entry(PostType.BlogPost); entry.Title = "Title 1"; entry.Body = "Blah"; entry.IsActive = true; entry.IncludeInMainSyndication = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category1Name); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.IncludeInMainSyndication = true; entry.Title = "Title 2"; entry.Body = "Blah1"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1976/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category1Name); entry.Categories.Add(category2Name); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 3"; entry.IncludeInMainSyndication = true; entry.Body = "Blah2"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1979/09/16", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); UnitTestHelper.Create(entry); entry = new Entry(PostType.BlogPost); entry.Title = "Title 4"; entry.IncludeInMainSyndication = true; entry.Body = "Blah3"; entry.IsActive = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("2006/01/01", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category2Name); int entryId = UnitTestHelper.Create(entry); string enclosureUrl = "http://perseus.franklins.net/hanselminutes_0107.mp3"; string enclosureMimeType = "audio/mp3"; long enclosureSize = 26707573; FrameworkEnclosure enc = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>", enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true); repository.Create(enc); posts = api.getRecentPosts(Config.CurrentBlog.Id.ToString(), "username", "password", 10); Assert.AreEqual(4, posts.Length, "Expected 4 posts"); Assert.AreEqual(1, posts[3].categories.Length, "Expected our categories to be there."); Assert.AreEqual(2, posts[2].categories.Length, "Expected our categories to be there."); Assert.IsNotNull(posts[1].categories, "Expected our categories to be there."); Assert.AreEqual(1, posts[0].categories.Length, "Expected our categories to be there."); Assert.AreEqual(category1Name, posts[3].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(category2Name, posts[0].categories[0], "The category returned by the MetaBlogApi is wrong."); Assert.AreEqual(enclosureUrl, posts[0].enclosure.Value.url, "Not what we expected for the enclosure url."); Assert.AreEqual(enclosureMimeType, posts[0].enclosure.Value.type, "Not what we expected for the enclosure mimetype."); Assert.AreEqual(enclosureSize, posts[0].enclosure.Value.length, "Not what we expected for the enclosure size."); }
public void GetPost_WithEntryId_ReturnsPostWithCorrectEntryUrl() { //arrange var repository = new DatabaseObjectProvider(); string hostname = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("", "username", "password", hostname, ""); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, ""); BlogRequest.Current.Blog = repository.GetBlog(hostname, ""); Config.CurrentBlog.AllowServiceAccess = true; var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/entry/whatever"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object); subtextContext.Setup(c => c.UrlHelper).Returns(urlHelper.Object); var api = new MetaWeblog(subtextContext.Object); string category1Name = UnitTestHelper.GenerateUniqueString(); string category2Name = UnitTestHelper.GenerateUniqueString(); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name); UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name); var entry = new Entry(PostType.BlogPost); entry.Title = "Title 1"; entry.Body = "Blah"; entry.IsActive = true; entry.IncludeInMainSyndication = true; entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); entry.Categories.Add(category1Name); int entryId = UnitTestHelper.Create(entry); string enclosureUrl = "http://perseus.franklins.net/hanselminutes_0107.mp3"; string enclosureMimeType = "audio/mp3"; long enclosureSize = 26707573; FrameworkEnclosure enc = UnitTestHelper.BuildEnclosure("<Digital Photography Explained (for Geeks) with Aaron Hockley/>", enclosureUrl, enclosureMimeType, entryId, enclosureSize, true, true); repository.Create(enc); //act Post post = api.getPost(entryId.ToString(), "username", "password"); //assert Assert.AreEqual(1, post.categories.Length); Assert.AreEqual("http://" + hostname + "/entry/whatever", post.link); Assert.AreEqual("http://" + hostname + "/entry/whatever", post.permalink); Assert.AreEqual(category1Name, post.categories[0]); Assert.AreEqual(enclosureUrl, post.enclosure.Value.url); Assert.AreEqual(enclosureMimeType, post.enclosure.Value.type); Assert.AreEqual(enclosureSize, post.enclosure.Value.length); }
Entry SetupBlogForCommentsAndCreateEntry(DatabaseObjectProvider repository = null) { repository = repository ?? new DatabaseObjectProvider(); repository.CreateBlog(string.Empty, "username", "password", _hostName, string.Empty); Blog info = repository.GetBlog(_hostName, string.Empty); BlogRequest.Current.Blog = info; info.Email = "*****@*****.**"; info.Title = "You've been haacked"; info.CommentsEnabled = true; info.ModerationEnabled = false; repository.UpdateConfigData(info); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("blah", "blah", "blah"); UnitTestHelper.Create(entry); return entry; }
public void ModifyingBlogShouldNotChangePassword() { var repository = new DatabaseObjectProvider(); Config.Settings.UseHashedPasswords = true; repository.CreateBlog("", "username", "thePassword", _hostName, "MyBlog1"); Blog info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), "MyBlog1"); string password = info.Password; info.LicenseUrl = "http://subtextproject.com/"; repository.UpdateConfigData(info); info = repository.GetBlog(_hostName.ToUpper(CultureInfo.InvariantCulture), "MyBlog1"); Assert.AreEqual(password, info.Password); }
public void GetPreviousAndNextEntriesReturnsPreviousWhenNoNextExists() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty); Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow.AddDays(-1)); Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow); int previousId = UnitTestHelper.Create(previousEntry); int currentId = UnitTestHelper.Create(currentEntry); var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost); Assert.AreEqual(1, entries.Count, "Since there is no next entry, should return only 1"); Assert.AreEqual(previousId, entries.First().Id, "The previous entry does not match expectations."); }
public void CreateBlogCannotCreateBlogWithHostThatIsDuplicateOfAnotherBlogAlias() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", _hostName, string.Empty); var alias = new BlogAlias { Host = "example.com", IsActive = true, BlogId = repository.GetBlog(_hostName, string.Empty).Id }; repository.AddBlogAlias(alias); UnitTestHelper.AssertThrows<BlogDuplicationException>(() => repository.CreateBlog("title", "username2", "password2", "example.com", string.Empty)); }
public void GetPreviousAndNextEntriesReturnsBoth() { var repository = new DatabaseObjectProvider(); string hostname = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty); BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty); Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow.AddDays(-2)); Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow.AddDays(-1)); Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow); int previousId = UnitTestHelper.Create(previousEntry); Thread.Sleep(100); int currentId = UnitTestHelper.Create(currentEntry); Thread.Sleep(100); int nextId = UnitTestHelper.Create(nextEntry); var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost); Assert.AreEqual(2, entries.Count, "Expected both previous and next."); //The more recent one is next because of desceding sort. Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations."); Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations."); }
public void GetBlogInfoLoadsOpenIDSettings() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", hostName, string.Empty); Blog info = repository.GetBlog(hostName, string.Empty); info.OpenIdServer = "http://server.example.com/"; info.OpenIdDelegate = "http://delegate.example.com/"; repository.UpdateConfigData(info); info = repository.GetBlog(hostName, string.Empty); Assert.AreEqual("http://server.example.com/", info.OpenIdServer); Assert.AreEqual("http://delegate.example.com/", info.OpenIdDelegate); }
public void UpdatingBlogWithDuplicateHostNameRequiresSubfolderName() { var repository = new DatabaseObjectProvider(); string anotherHost = UnitTestHelper.GenerateUniqueString(); repository.CreateBlog("title", "username", "password", _hostName, "MyBlog1"); repository.CreateBlog("title", "username", "password", anotherHost, string.Empty); Blog info = repository.GetBlog(anotherHost, string.Empty); info.Host = _hostName; info.Subfolder = string.Empty; UnitTestHelper.AssertThrows<BlogRequiresSubfolderException>(() => repository.UpdateConfigData(info)); }