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"); }
/// <summary> /// Takes all the necessary steps to create a blog and set up the HTTP Context /// with the blog. /// </summary> /// <param name="subfolder">The 'virtualized' subfolder the blog lives in.</param> /// <param name="applicationPath">The name of the IIS virtual directory the blog lives in.</param> /// <param name="port">The port for this blog.</param> /// <param name="page">The page to request.</param> /// <param name="userName">Name of the user.</param> /// <param name="password">The password.</param> /// <returns> /// Returns a reference to a string builder. /// The stringbuilder will end up containing the Response of any simulated /// requests. /// </returns> internal static SimulatedRequestContext SetupBlog(string subfolder, string applicationPath, int port, string page, string userName, string password) { var repository = new DatabaseObjectProvider(); string host = GenerateUniqueString(); HttpContext.Current = null; //I wish this returned the blog it created. repository.CreateBlog("Unit Test Blog", userName, password, host, subfolder); Blog blog = repository.GetBlog(host, subfolder); var sb = new StringBuilder(); TextWriter output = new StringWriter(sb); SimulatedHttpRequest request = SetHttpContextWithBlogRequest(host, port, subfolder, applicationPath, page, output, "GET"); BlogRequest.Current.Blog = blog; if (Config.CurrentBlog != null) { Config.CurrentBlog.AutoFriendlyUrlEnabled = true; } HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(userName), new[] { "Administrators" }); return(new SimulatedRequestContext(request, sb, output, host)); }
public void ProcessRequest_WithGetRequest_SendsRssResponse() { //arrange UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "this is the title", "body"); entry.DateCreatedUtc = entry.DatePublishedUtc = entry.DateModifiedUtc = DateTime.ParseExact("2006/05/25", "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); int id = UnitTestHelper.Create(entry); Blog blog = Config.CurrentBlog; blog.TrackbacksEnabled = true; var subtextContext = new Mock <ISubtextContext>(); StringWriter writer = subtextContext.FakeSubtextContextRequest(blog, "/trackbackhandler", "/", string.Empty); subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Object.RequestContext.RouteData.Values.Add("id", id.ToString()); Mock <BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper); urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny <int>())).Returns("/whatever/trackback"); subtextContext.SetupBlog(blog); var handler = new TrackBackHandler(subtextContext.Object); //act handler.ProcessRequest(); //assert Assert.IsTrue(writer.ToString().Contains("this is the title")); }
public void GetPostsByDayRangeDoesNotIncludeFuturePosts() { // Arrange var repository = new DatabaseObjectProvider(); DateTime now = DateTime.UtcNow.AddMinutes(-5); Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero", null, now); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one", null, now.AddMinutes(1)); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two", null, now.AddMinutes(2)); UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); entryTwo.DatePublishedUtc = DateTime.UtcNow.AddMinutes(20); UnitTestHelper.Create(entryTwo); // Act var beginningOfMonth = new DateTime(now.Year, now.Month, 1); ICollection <Entry> entries = repository.GetPostsByDayRange(beginningOfMonth, beginningOfMonth.AddMonths(1), PostType.BlogPost, true); // Assert 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."); }
public void CanUpdate() { UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); Image image = CreateImageInstance(); Assert.GreaterEqualThan(Config.CurrentBlog.Id, 0); Assert.AreEqual(Config.CurrentBlog.Id, image.BlogId); int imageId = repository.Insert(image, singlePixelBytes); Image saved = repository.GetImage(imageId, true /* activeOnly */); Assert.AreEqual(Config.CurrentBlog.Id, saved.BlogId, "The blog id for the image does not match!"); saved.LocalDirectoryPath = Path.GetFullPath(TestDirectory); Assert.AreEqual("Test Image", saved.Title); saved.Title = "A Better Title"; repository.Update(saved, singlePixelBytes); Image loaded = repository.GetImage(imageId, true /* activeOnly */); Assert.AreEqual(Config.CurrentBlog.Id, loaded.BlogId, "The blog id for the image does not match!"); loaded.LocalDirectoryPath = Path.GetFullPath(TestDirectory); Assert.AreEqual("A Better Title", loaded.Title, "The title was not updated"); }
public void CanUpdateLink() { UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); // Create the categories CreateSomeLinkCategories(repository); int categoryId = repository.CreateLinkCategory(CreateCategory("My Favorite Feeds", "Some of my favorite RSS feeds", CategoryType.LinkCollection, true)); Link link = CreateLink(repository, "Test", categoryId, null); int linkId = link.Id; Link loaded = repository.GetLink(linkId); Assert.AreEqual("Test", loaded.Title); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "test"); //Make changes then update. link.PostId = entry.Id; link.Title = "Another title"; link.NewWindow = true; repository.UpdateLink(link); loaded = repository.GetLink(linkId); Assert.AreEqual("Another title", loaded.Title); Assert.IsTrue(loaded.NewWindow); Assert.AreEqual(entry.Id, loaded.PostId); }
public void GetEntriesByTagDoesNotIncludeFuturePosts() { // Arrange var repository = new DatabaseObjectProvider(); DateTime now = DateTime.UtcNow; Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero", null, now); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one", null, now.AddMinutes(1)); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two", null, now.AddMinutes(2)); UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); entryTwo.DatePublishedUtc = DateTime.UtcNow.AddMinutes(20); UnitTestHelper.Create(entryTwo); var tags = new List <string>(new[] { "Tag1", "Tag2" }); new DatabaseObjectProvider().SetEntryTagList(entryZero.Id, tags); new DatabaseObjectProvider().SetEntryTagList(entryOne.Id, tags); new DatabaseObjectProvider().SetEntryTagList(entryTwo.Id, tags); // Act ICollection <Entry> entries = repository.GetEntriesByTag(3, "Tag1"); // Assert 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."); }
public void CanGetItemsFlaggedAsSpam() { Entry entry = SetupBlogForCommentsAndCreateEntry(); var repository = new DatabaseObjectProvider(); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.FalsePositive); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.ConfirmedSpam); FeedbackItem included = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.FlaggedAsSpam); FeedbackItem includedToo = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.FlaggedAsSpam | FeedbackStatusFlag.NeedsModeration); //We expect 2 of the four. IPagedCollection <FeedbackItem> feedback = repository.GetPagedFeedback(0, 10, FeedbackStatusFlag. FlaggedAsSpam, FeedbackStatusFlag. Approved | FeedbackStatusFlag. Deleted, FeedbackType.Comment); Assert.AreEqual(2, feedback.Count, "We expected two to match."); //Expect reverse order Assert.AreEqual(included.Id, feedback[1].Id, "The first does not match"); Assert.AreEqual(includedToo.Id, feedback[0].Id, "The second does not match"); }
static FeedbackItem CreateAndUpdateFeedbackWithExactStatus(Entry entry, FeedbackType type, FeedbackStatusFlag status) { var repository = new DatabaseObjectProvider(); var feedback = new FeedbackItem(type); feedback.Title = UnitTestHelper.GenerateUniqueString(); feedback.Body = UnitTestHelper.GenerateUniqueString(); feedback.EntryId = entry.Id; feedback.Author = "TestAuthor"; 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()); subtextContext.Setup(c => c.HttpContext).Returns(new HttpContextWrapper(HttpContext.Current)); var service = new CommentService(subtextContext.Object, null); int id = service.Create(feedback, true /*runFilters*/); feedback = repository.Get(id); feedback.Status = status; repository.Update(feedback); return(repository.Get(id)); }
public void CanGetAllApprovedComments() { Entry entry = SetupBlogForCommentsAndCreateEntry(); var repository = new DatabaseObjectProvider(); FeedbackItem commentOne = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); FeedbackItem commentTwo = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.ApprovedByModerator); FeedbackItem commentThree = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.ConfirmedSpam); repository.ConfirmSpam(commentThree, null); FeedbackItem commentFour = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.FalsePositive); //We expect three of the four. IPagedCollection <FeedbackItem> feedback = repository.GetPagedFeedback(0, 10, FeedbackStatusFlag. Approved, FeedbackStatusFlag.None, FeedbackType.Comment); Assert.AreEqual(3, feedback.Count, "We expected three to match."); //Expect reverse order Assert.AreEqual(commentOne.Id, feedback[2].Id, "The first does not match"); Assert.AreEqual(commentTwo.Id, feedback[1].Id, "The first does not match"); Assert.AreEqual(commentFour.Id, feedback[0].Id, "The first does not match"); }
public void OnlyApprovedItemsContributeToEntryFeedbackCount() { Entry entry = SetupBlogForCommentsAndCreateEntry(); var repository = new DatabaseObjectProvider(); int entryId = entry.Id; CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.Approved); entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false); Assert.AreEqual(1, entry.FeedBackCount, "Expected one approved feedback entry."); FeedbackItem comment = CreateAndUpdateFeedbackWithExactStatus(entry, FeedbackType.Comment, FeedbackStatusFlag.FlaggedAsSpam); entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false); Assert.AreEqual(1, entry.FeedBackCount, "Expected one approved feedback entry."); comment.Approved = true; repository.Update(comment); entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false); Assert.AreEqual(2, entry.FeedBackCount, "After approving the second comment, expected two approved feedback entry."); comment.Approved = false; repository.Update(comment); entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false); Assert.AreEqual(1, entry.FeedBackCount, "After un-approving the second comment, expected one approved feedback entry."); repository.Delete(comment); entry = UnitTestHelper.GetEntry(entryId, PostConfig.None, false); Assert.AreEqual(1, entry.FeedBackCount, "After un-approving the second comment, expected one approved feedback entry."); }
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 GetEntriesByTagIncludesEnclosure() { Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero"); Thread.Sleep(100); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one"); UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); var repository = new DatabaseObjectProvider(); Enclosure enc = UnitTestHelper.BuildEnclosure("Nothing to see here.", "httP://blablabla.com", "audio/mp3", entryZero.Id, 12345678, true, true); repository.Create(enc); var tags = new List <string>(new[] { "Tag1", "Tag2" }); new DatabaseObjectProvider().SetEntryTagList(entryZero.Id, tags); new DatabaseObjectProvider().SetEntryTagList(entryOne.Id, tags); ICollection <Entry> entries = repository.GetEntriesByTag(3, "Tag1"); //Test outcome Assert.AreEqual(2, entries.Count, "Should have retrieved 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 GetPreviousAndNextEntriesReturnsNextWhenNoPreviousExists() { 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 currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow.AddDays(-1)); Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body", UnitTestHelper.GenerateUniqueString(), DateTime.UtcNow); int currentId = UnitTestHelper.Create(currentEntry); int nextId = UnitTestHelper.Create(nextEntry); var entries = repository.GetPreviousAndNextEntries(currentId, PostType.BlogPost); Assert.AreEqual(1, entries.Count, "Since there is no previous entry, should return only next"); Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations."); }
public void CanCreateAndDeleteLinkCategory() { UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); // Create some categories int categoryId = repository.CreateLinkCategory(CreateCategory("My Favorite Feeds", "Some of my favorite RSS feeds", CategoryType.LinkCollection, true)); LinkCategory category = repository.GetLinkCategory(categoryId, true); Assert.AreEqual(Config.CurrentBlog.Id, category.BlogId); Assert.AreEqual("My Favorite Feeds", category.Title); Assert.AreEqual("Some of my favorite RSS feeds", category.Description); Assert.IsTrue(category.HasDescription); Assert.IsFalse(category.HasLinks); Assert.IsFalse(category.HasImages); Assert.IsTrue(category.IsActive); Assert.AreEqual(CategoryType.LinkCollection, category.CategoryType); Assert.IsNotNull(category); repository.DeleteLinkCategory(categoryId); Assert.IsNull(repository.GetLinkCategory(categoryId, true)); }
public IPagedCollection <FeedbackItem> GetPagedItems(int pageIndex, int pageSize) { var repository = new DatabaseObjectProvider(); return(repository.GetPagedFeedback(pageIndex, pageSize, FeedbackStatusFlag.Approved, FeedbackStatusFlag.None, FeedbackType.None)); }
public void CanGetCategoriesByPostId() { UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); int category1Id = repository.CreateLinkCategory(CreateCategory("Post Category 1", "Cody roolz!", CategoryType.PostCollection, true)); int category2Id = repository.CreateLinkCategory(CreateCategory("Post Category 2", "Cody roolz again!", CategoryType.PostCollection, true)); repository.CreateLinkCategory(CreateCategory("Post Category 3", "Cody roolz and again!", CategoryType.PostCollection, true)); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "title", "body"); int entryId = UnitTestHelper.Create(entry); repository.SetEntryCategoryList(entryId, new[] { category1Id, category2Id }); ICollection <LinkCategory> categories = repository.GetLinkCategoriesByPostId(entryId); Assert.AreEqual(2, categories.Count, "Expected two of the three categories"); Assert.AreEqual(category1Id, categories.First().Id); Assert.AreEqual(category2Id, categories.ElementAt(1).Id); Assert.AreEqual(Config.CurrentBlog.Id, categories.First().BlogId); }
/// <summary> /// Ons the load. /// </summary> /// <param name="e">E.</param> protected override void OnLoad(EventArgs e) { InstallationState status = InstallationManager.GetInstallationStatus(VersionInfo.CurrentAssemblyVersion); var repository = new DatabaseObjectProvider(); switch (status) { case InstallationState.NeedsInstallation: case InstallationState.NeedsUpgrade: EnsureInstallStep("Default.aspx", "Step02_ConfigureHost.aspx"); break; default: HostInfo info = HostInfo.LoadHostInfoFromDatabase(repository, true /* suppressException */); int blogCount = repository.GetBlogCount(); if (info == null) { EnsureInstallStep("Step02_ConfigureHost.aspx"); } if (info != null && blogCount == 0) { EnsureInstallStep("Step03_CreateBlog.aspx"); } if (info != null && blogCount > 0) { EnsureInstallStep("InstallationComplete.aspx"); } break; } base.OnLoad(e); }
public void GetBlogAliasByBlog() { var repository = new DatabaseObjectProvider(); string host = UnitTestHelper.GenerateUniqueString(); Blog blog1 = UnitTestHelper.CreateBlogAndSetupContext(); Blog blog2 = UnitTestHelper.CreateBlogAndSetupContext(); var alias1 = new BlogAlias(); alias1.BlogId = blog1.Id; alias1.Host = host; var alias2 = new BlogAlias(); alias2.BlogId = blog2.Id; alias2.Host = host; alias2.Subfolder = UnitTestHelper.GenerateUniqueString(); repository.AddBlogAlias(alias1); repository.AddBlogAlias(alias2); IPagedCollection <BlogAlias> aliases = blog1.GetBlogAliases(new DatabaseObjectProvider(), 0, 10); Assert.AreEqual(1, aliases.Count); Assert.AreEqual(alias1.Id, aliases[0].Id); Assert.IsEmpty(alias1.Subfolder); }
public void CanInsertAndDeleteImage() { var repository = new DatabaseObjectProvider(); int imageId = 0; Image image = CreateImageInstance(); image.IsActive = true; Image loadedImage = null; try { imageId = repository.Insert(image, singlePixelBytes); loadedImage = repository.GetImage(imageId, false /* activeOnly */); Assert.IsNotNull(loadedImage); Assert.AreEqual(image.CategoryID, loadedImage.CategoryID); } finally { if (loadedImage != null) { repository.Delete(loadedImage); } Assert.IsNull(repository.GetImage(imageId, false /* activeOnly */)); } }
public void GetEntriesByCategoryDoesNotIncludeFuturePosts() { // Arrange var repository = new DatabaseObjectProvider(); DateTime now = DateTime.UtcNow.AddMinutes(-5); int blogId = Config.CurrentBlog.Id; int categoryId = UnitTestHelper.CreateCategory(blogId, "Test Category"); Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero", null, now); Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one", null, now.AddMinutes(1)); Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two", null, now.AddMinutes(2)); entryZero.Categories.Add("Test Category"); entryOne.Categories.Add("Test Category"); entryTwo.Categories.Add("Test Category"); UnitTestHelper.Create(entryZero); UnitTestHelper.Create(entryOne); entryTwo.DatePublishedUtc = DateTime.UtcNow.AddMinutes(20); UnitTestHelper.Create(entryTwo); // Act ICollection <Entry> entries = repository.GetEntriesByCategory(3, categoryId, true); // Assert 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."); }
public void ProcessRequest_WithInvalidEntryId_SendsErrorResponse() { //arrange UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); Blog blog = Config.CurrentBlog; blog.TrackbacksEnabled = true; var subtextContext = new Mock <ISubtextContext>(); StringWriter writer = subtextContext.FakeSubtextContextRequest(blog, "/trackbackhandler", "/", string.Empty); subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Object.RequestContext.RouteData.Values.Add("id", int.MaxValue.ToString()); Mock <BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper); urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny <int>())).Returns("/whatever/trackback"); subtextContext.SetupBlog(blog); var handler = new TrackBackHandler(subtextContext.Object); //act handler.ProcessRequest(); //assert Assert.IsTrue(writer.ToString().Contains("EntryId is invalid or missing")); }
public void CanUpdateMetaTag(string content, string name, string httpequiv) { var blog = UnitTestHelper.CreateBlogAndSetupContext(); var repository = new DatabaseObjectProvider(); MetaTag tag = UnitTestHelper.BuildMetaTag(content, name, httpequiv, blog.Id, null, DateTime.UtcNow); repository.Create(tag); string randomStr = UnitTestHelper.GenerateUniqueString().Left(20); tag.Content = content + randomStr; if (!string.IsNullOrEmpty(name)) { tag.Name = name + randomStr; } if (!string.IsNullOrEmpty(httpequiv)) { tag.HttpEquiv = httpequiv + randomStr; } Assert.IsTrue(repository.Update(tag)); MetaTag updTag = repository.GetMetaTagsForBlog(blog, 0, 100)[0]; ValidateMetaTags(tag, updTag); }
public void CanDeleteEntryMetaTag() { var blog = UnitTestHelper.CreateBlogAndSetupContext(); var repository = new DatabaseObjectProvider(); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Steven Harman", "Sweet arse entry!", "Giddy, giddy, goo!"); UnitTestHelper.Create(entry); MetaTag tag = UnitTestHelper.BuildMetaTag("Foo, bar, zaa?", "author", null, blog.Id, entry.Id, DateTime.UtcNow); repository.Create(tag); Assert.AreEqual(1, repository.GetMetaTagsForBlog(blog, 0, 100).Count, "Should be one (1) MetaTag for this blog."); Assert.AreEqual(1, repository.GetMetaTagsForEntry(entry, 0, 100).Count, "Should be one (1) MetaTag for this entry."); // Now let's remove it from the data store Assert.IsTrue(repository.DeleteMetaTag(tag.Id), "Deleting the MetaTag failed."); Assert.AreEqual(0, repository.GetMetaTagsForBlog(blog, 0, 100).Count, "Should be zero (0) MetaTags for this blog."); Assert.AreEqual(0, repository.GetMetaTagsForEntry(entry, 0, 100).Count, "Should be zero (0) MetaTag for this entry."); }
public void CanAddAndRemoveAllCategories() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("empty title", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty, "/"); BlogRequest.Current.Blog = new DatabaseObjectProvider().GetBlog(hostname, ""); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("Me", "Unit Test Entry", "Body"); int id = UnitTestHelper.Create(entry); int categoryId = UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, "My Subtext UnitTest Category"); repository.SetEntryCategoryList(id, new[] { categoryId }); Entry loaded = UnitTestHelper.GetEntry(id, PostConfig.None, true); Assert.AreEqual("My Subtext UnitTest Category", loaded.Categories.First(), "Expected a category for this entry"); repository.SetEntryCategoryList(id, new int[] { }); loaded = UnitTestHelper.GetEntry(id, PostConfig.None, true); Assert.AreEqual(0, loaded.Categories.Count, "Expected that our category would be removed."); }
public void CanGetPostsByYearArchive() { DateTime utcNow = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal).ToUniversalTime(); UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); ICollection <ArchiveCount> counts = repository.GetPostCountsByYear(); Assert.AreEqual(0, counts.Count); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title", "body"); entry.DatePublishedUtc = utcNow; UnitTestHelper.Create(entry); counts = repository.GetPostCountsByYear(); Assert.AreEqual(1, counts.Count); foreach (ArchiveCount archiveCount in counts) { Console.WriteLine("archiveCount.Date: " + archiveCount.Date); Assert.AreEqual(1, archiveCount.Count, "Expected one post in the archive."); Assert.AreEqual(utcNow.Year, archiveCount.Date.Year); return; } }
public void newPost_WithCategory_CreatesEntryWithCategory() { //arrange var repository = new DatabaseObjectProvider(); var blog = new Blog { Id = 42, UserName = "******", Password = "******", AllowServiceAccess = true, Host = "localhost" }; var entryPublisher = new Mock <IEntryPublisher>(); Entry publishedEntry = null; entryPublisher.Setup(publisher => publisher.Publish(It.IsAny <Entry>())).Callback <Entry>(e => publishedEntry = e); var subtextContext = new Mock <ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(blog); subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock <IDependencyResolver>().Object); var api = new MetaWeblog(subtextContext.Object, entryPublisher.Object); var post = new Post { categories = new[] { "CategoryA" }, description = "A unit test", title = "A unit testing title", dateCreated = DateTime.UtcNow }; //act api.newPost("42", "username", "password", post, true); //assert Assert.IsNotNull(publishedEntry); Assert.AreEqual(1, publishedEntry.Categories.Count); Assert.AreEqual("CategoryA", publishedEntry.Categories.First()); }
public void CanGetRecentImages() { //arrange UnitTestHelper.SetupBlog(); var repository = new DatabaseObjectProvider(); var category = new LinkCategory { BlogId = Config.CurrentBlog.Id, Description = "Whatever", IsActive = true, Title = "Whatever" }; int categoryId = repository.CreateLinkCategory(category); var image = new Image { Title = "Title", CategoryID = categoryId, BlogId = Config.CurrentBlog.Id, FileName = "Foo", Height = 10, Width = 10, IsActive = true, }; int imageId = repository.InsertImage(image); //act ICollection <Image> images = repository.GetImages(Config.CurrentBlog.Host, null, 10); //assert Assert.AreEqual(1, images.Count); Assert.AreEqual(imageId, images.First().ImageID); }
public void ArchiveMonth_ReturnsLinksToMonthlyArchives() { // Arrange UnitTestHelper.CreateBlogAndSetupContext(); var blogUrlHelper = new Mock <BlogUrlHelper>(); blogUrlHelper.Setup(u => u.MonthUrl(It.IsAny <DateTime>())).Returns <DateTime>(dt => "/year/" + dt.Year + "/month/" + dt.Month); var firstDate = DateTimeOffset.ParseExact("2011/01/05 06:15 AM +08:00", "yyyy/MM/dd hh:mm tt zzz", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).DateTime.ToUniversalTime(); var entry = UnitTestHelper.CreateEntryInstanceForSyndication("joe", "title1", "body1", "foo1", firstDate, firstDate); UnitTestHelper.Create(entry); var entry2 = UnitTestHelper.CreateEntryInstanceForSyndication("joe", "title2", "body2", "foo2", firstDate.AddMonths(1), firstDate.AddMonths(1)); UnitTestHelper.Create(entry2); var entry3 = UnitTestHelper.CreateEntryInstanceForSyndication("joe", "title3", "body3", "foo3", firstDate.AddMonths(2), firstDate.AddMonths(2)); UnitTestHelper.Create(entry3); // Act var linkCategory = new DatabaseObjectProvider().ArchiveMonth(blogUrlHelper.Object, Config.CurrentBlog); // Assert Assert.AreEqual("Archives", linkCategory.Title); Assert.AreEqual(3, linkCategory.Links.Count); Assert.AreEqual("/year/2011/month/3", linkCategory.Links.First().Url); Assert.AreEqual("/year/2011/month/2", linkCategory.Links.ElementAt(1).Url); Assert.AreEqual("/year/2011/month/1", linkCategory.Links.ElementAt(2).Url); }
public void CreateBlogCannotHideAnotherBlog() { var repository = new DatabaseObjectProvider(); repository.CreateBlog("title", "username", "password", _hostName, string.Empty); UnitTestHelper.AssertThrows <BlogHiddenException>(() => repository.CreateBlog("title", "username", "password", _hostName, "MyBlog")); }