コード例 #1
0
        public void GetBlogPostsReturnsActiveOnlyAndNoneInFuture()
        {
            //Create some entries.
            var repository = new DatabaseObjectProvider();
            Entry entryZero = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-zero", "body-zero");
            entryZero.IsActive = entryZero.IncludeInMainSyndication = true;
            Entry entryOne = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-one", "body-one");
            entryOne.IsActive = entryOne.IncludeInMainSyndication = true;
            entryOne.DateCreatedUtc = DateTime.UtcNow.AddDays(-1);
            entryOne.DatePublishedUtc = DateTime.UtcNow.AddDays(-1);
            Entry entryTwo = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-two", "body-two");
            entryTwo.IsActive = false;
            Entry entryThree = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title-three", "body-zero");
            entryThree.IsActive = entryThree.IncludeInMainSyndication = true;
            entryThree.DateCreatedUtc.AddDays(-2);
            entryThree.DatePublishedUtc = DateTime.UtcNow.AddDays(10);

            //Persist entries.
            UnitTestHelper.Create(entryZero);
            Thread.Sleep(500);
            UnitTestHelper.Create(entryOne);
            Thread.Sleep(500);
            UnitTestHelper.Create(entryTwo);
            Thread.Sleep(500);
            UnitTestHelper.Create(entryThree);
            Assert.IsTrue(entryThree.DatePublishedUtc > DateTime.UtcNow);

            //Get EntryDay
            ICollection<EntryDay> entryList = repository.GetBlogPostsForHomePage(10, PostConfig.IsActive).ToList();

            //Test outcome
            Assert.AreEqual(2, entryList.Count);
            Assert.AreEqual(1, entryList.First().Count);
            Assert.AreEqual(1, entryList.ElementAt(1).Count);
        }
コード例 #2
0
        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.");
        }
コード例 #3
0
        public void CanUpdateEnclosure(string title, string url, string mimetype, long size, bool addToFeed,
                                       bool showWithPost)
        {
            // Arrange
            UnitTestHelper.SetupBlog(string.Empty);
            var repository = new DatabaseObjectProvider();
            Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Simone Chiaretta", "Post for testing Enclosures",
                                                                       "Listen to my great podcast");
            int entryId = UnitTestHelper.Create(e);
            Enclosure enc = UnitTestHelper.BuildEnclosure(title, url, mimetype, entryId, size, addToFeed, showWithPost);

            repository.Create(enc);

            string randomStr = UnitTestHelper.GenerateUniqueString().Left(20);
            enc.Url = url + randomStr;

            if (!string.IsNullOrEmpty(title))
            {
                enc.Title = title + randomStr;
            }

            enc.MimeType = mimetype + randomStr;

            int randomSize = new Random().Next(10, 100);
            enc.Size = size + randomSize;

            // Act
            repository.Update(enc);

            // Assert
            Entry newEntry = repository.GetEntry(entryId, true, false);
            UnitTestHelper.AssertEnclosures(enc, newEntry.Enclosure);
        }
コード例 #4
0
        public void Create_WithFeedbackItem_SetsDateCreatedAndModifiedToUtcNow()
        {
            // Arrange
            var now = DateTime.UtcNow;
            var sps = new Mock<StoredProcedures>("test");
            sps.Setup(s => s.InsertFeedback(It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<int>(),
                It.IsAny<int?>(),
                It.IsAny<string>(),
                It.IsAny<bool>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<int>(),
                It.IsAny<int>(),
                It.IsAny<bool>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<string>(),
                It.IsAny<DateTime>(),
                It.IsAny<DateTime?>(),
                It.IsAny<DateTime>()));
            var repository = new DatabaseObjectProvider(blogId: 1, procedures: sps.Object);
            var feedback = new FeedbackItem(FeedbackType.Comment) { Body = "blah" };

            // Act
            repository.Create(feedback);

            // Assert
            Assert.GreaterEqualThan(DateTime.UtcNow, feedback.DateCreatedUtc);
            Assert.GreaterEqualThan(DateTime.UtcNow, feedback.DateModifiedUtc);
            Assert.GreaterEqualThan(feedback.DateCreatedUtc, now);
            Assert.GreaterEqualThan(feedback.DateModifiedUtc, now);
        }
コード例 #5
0
 public void GetReturnsZeroWhenNoMetaTagsExistForBlog()
 {
     var repository = new DatabaseObjectProvider();
     blog = UnitTestHelper.CreateBlogAndSetupContext();
     Assert.AreEqual(0, repository.GetMetaTagsForBlog(blog, 0, 100).Count,
                     "Shouldn't have found any MetaTags for this blog.");
 }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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");
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public void CanInsertNewMetaTag(string content, string name, string httpEquiv, bool withEntry, string errMsg)
        {
            blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            int? entryId = null;
            if (withEntry)
            {
                Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Steven Harman", "My Post", "Foo Bar Zaa!");
                entryId = UnitTestHelper.Create(e);
            }

            MetaTag mt = UnitTestHelper.BuildMetaTag(content, name, httpEquiv, blog.Id, entryId, DateTime.UtcNow);

            // make sure there are no meta-tags for this blog in the data store
            ICollection<MetaTag> tags = repository.GetMetaTagsForBlog(blog, 0, 100);
            Assert.AreEqual(0, tags.Count, "Should be zero MetaTags.");

            // add the meta-tag to the data store
            int tagId = repository.Create(mt);

            tags = repository.GetMetaTagsForBlog(blog, 0, 100);

            Assert.AreEqual(1, tags.Count, errMsg);

            MetaTag newTag = tags.First();

            // make sure all attributes of the meta-tag were written to the data store correctly.
            Assert.AreEqual(tagId, newTag.Id, "Wrong Id");
            Assert.AreEqual(mt.Content, newTag.Content, "Wrong content");
            Assert.AreEqual(mt.Name, newTag.Name, "wrong name attribute");
            Assert.AreEqual(mt.HttpEquiv, newTag.HttpEquiv, "Wrong http-equiv attriubte");
            Assert.AreEqual(mt.BlogId, newTag.BlogId, "Wrong blogId");
            Assert.AreEqual(mt.EntryId, newTag.EntryId, "Wrong entryId");
            Assert.AreEqual(mt.DateCreatedUtc.Date, newTag.DateCreatedUtc.Date, "Wrong created date");
        }
コード例 #10
0
        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.");
        }
コード例 #11
0
ファイル: ImageTests.cs プロジェクト: rhoadsce/Subtext
        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);
        }
コード例 #12
0
        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.");
        }
コード例 #13
0
ファイル: EntryUpdateTests.cs プロジェクト: rhoadsce/Subtext
        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.");
        }
コード例 #14
0
        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.");
        }
コード例 #15
0
ファイル: BlogAliasTests.cs プロジェクト: rhoadsce/Subtext
        public void CheckBlogNotReturnedWithoutAlias()
        {
            UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            Blog testBlog = repository.GetBlogByDomainAlias(UnitTestHelper.GenerateUniqueString(),
                                                                           UnitTestHelper.GenerateUniqueString(), false);

            Assert.IsNull(testBlog);
        }
コード例 #16
0
ファイル: RssHandlerTests.cs プロジェクト: rhoadsce/Subtext
        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.");
        }
コード例 #17
0
ファイル: EntryViewTests.cs プロジェクト: rsaladrigas/Subtext
 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);
 }
コード例 #18
0
        public void Create_WithInvalidEntry_ThrowsArgumentException()
        {
            // arrange
            var repository = new DatabaseObjectProvider();
            var enclosure = new Enclosure { EntryId = 0 };

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            UnitTestHelper.AssertThrows<ArgumentException>(() => repository.Create(enclosure));
        }
コード例 #19
0
ファイル: BlogAliasTests.cs プロジェクト: rhoadsce/Subtext
        public void CheckThatAliasChecksSubfolderIfBlogOnSameHost()
        {
            var repository = new DatabaseObjectProvider();
            Blog blog = UnitTestHelper.CreateBlogAndSetupContext();
            BlogAlias alias = UnitTestHelper.CreateBlogAlias(blog, blog.Host, UnitTestHelper.GenerateUniqueString());

            repository.AddBlogAlias(alias);

            Blog testBlog = repository.GetBlogByDomainAlias(blog.Host, "", false);
            Assert.IsNull(testBlog, "Should not have found a blog, alias is on same host.");
        }
コード例 #20
0
        public void Update_WithInvalidEnclosure_ThrowsArgumentException()
        {
            // arrange
            var enclosure = new Enclosure { EntryId = 0 };
            var repository = new DatabaseObjectProvider();

            // act, assert
            Assert.IsFalse(enclosure.IsValid);
            var exception = UnitTestHelper.AssertThrows<ArgumentException>(() => repository.Update(enclosure));
            Assert.AreEqual(enclosure.ValidationMessage, exception.Message);
        }
コード例 #21
0
ファイル: ConfigTests.cs プロジェクト: rsaladrigas/Subtext
        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.");
        }
コード例 #22
0
        public void CanGetMetaTagsForBlog()
        {
            blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            InsertNewMetaTag("Adding description meta tag", "description", null, DateTime.UtcNow, blog.Id, null);
            InsertNewMetaTag("no-cache", null, "cache-control", DateTime.UtcNow, blog.Id, null);

            ICollection<MetaTag> tags = repository.GetMetaTagsForBlog(blog, 0, 100);

            Assert.AreEqual(2, tags.Count, "Should be two tags for this blog.");
        }
コード例 #23
0
        public void EntryWithNoEnclosureHasNullAsEnclosure()
        {
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();
            Entry e = UnitTestHelper.CreateEntryInstanceForSyndication("Simone Chiaretta", "Post for testing Enclosures",
                                                                       "Listen to my great podcast");
            int entryId = UnitTestHelper.Create(e);

            Entry newEntry = repository.GetEntry(entryId, true, false);

            Assert.IsNull(newEntry.Enclosure, "enclosure must be null");
        }
コード例 #24
0
ファイル: BlogInfoTests.cs プロジェクト: rsaladrigas/Subtext
        public void CanGetBlogs()
        {
            // arrange
            UnitTestHelper.SetupBlog();

            // act
            IPagedCollection<Blog> blogs = new DatabaseObjectProvider().GetBlogs(0, int.MaxValue, ConfigurationFlags.None);

            // assert
            Assert.GreaterEqualThan(blogs.Count, 1);
            var blog = blogs.First(b => b.Id == Config.CurrentBlog.Id);
            Assert.IsNotNull(blog);
        }
コード例 #25
0
ファイル: HostInfoTests.cs プロジェクト: rhoadsce/Subtext
        public void CanLoadHost()
        {
            var repository = new DatabaseObjectProvider();
            SqlHelper.ExecuteNonQuery(Config.ConnectionString, CommandType.Text, "DELETE subtext_Host");

            HostInfo.LoadHostInfoFromDatabase(repository, suppressException: false);

            Assert.IsNull(HostInfo.Instance, "HostInfo should be Null");

            HostInfo.CreateHost(repository, "test", "test", "*****@*****.**");

            Assert.IsNotNull(HostInfo.Instance, "Host should not be null.");
        }
コード例 #26
0
ファイル: BlogAliasTests.cs プロジェクト: rhoadsce/Subtext
        public void CheckBlogNotReturnedWithInactiveAlias()
        {
            var repository = new DatabaseObjectProvider();
            Blog blog = UnitTestHelper.CreateBlogAndSetupContext();
            BlogAlias alias = UnitTestHelper.CreateBlogAlias(blog, UnitTestHelper.GenerateUniqueString(), "", false);

            BlogAlias testAlias = repository.GetBlogAlias(alias.Id);
            Blog testBlog = repository.GetBlogByDomainAlias(alias.Host, alias.Subfolder, false);

            Assert.AreNotEqual(NullValue.NullInt32, alias.Id, "Alias was not saved.");
            Assert.AreEqual(alias.Id, testAlias.Id, "The test alias is not the alias saved.");
            Assert.IsFalse(testAlias.IsActive, "This alias is active.");
            Assert.IsNull(testBlog, "Should not have found a blog");
        }
コード例 #27
0
ファイル: ConfigTests.cs プロジェクト: rsaladrigas/Subtext
        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);
        }
コード例 #28
0
        public void CanRemoveHttpEquivAndAddName()
        {
            var blog = UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            MetaTag tag = UnitTestHelper.BuildMetaTag("Still nothing to see here.", null, "expires", blog.Id, null, DateTime.UtcNow);
            repository.Create(tag);

            tag.HttpEquiv = null;
            tag.Name = "author";
            tag.Content = "Steve-o-rino!";

            repository.Update(tag);

            ValidateMetaTags(tag, repository.GetMetaTagsForBlog(blog, 0, 100)[0]);
        }
コード例 #29
0
ファイル: TagsTests.cs プロジェクト: rhoadsce/Subtext
        public void GetGetTopTags()
        {
            UnitTestHelper.SetupBlog();
            var repository = new DatabaseObjectProvider();
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "the title for this post", "test");
            UnitTestHelper.Create(entry);
            repository.SetEntryTagList(entry.Id, new List<string>(new[] { "tag1", "tag2", "tag3" }));

            entry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "the title for this post",
                                                                     @"<a href=""http://blah/tag3/"" rel=""tag"">test</a>");
            UnitTestHelper.Create(entry);

            ICollection<Tag> topTags = repository.GetMostUsedTags(1);
            Assert.AreEqual("tag3", topTags.First().TagName);
        }
コード例 #30
0
ファイル: EntryTagTests.cs プロジェクト: rhoadsce/Subtext
        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.");
        }