当前位置: 首页>>代码示例>>C#>>正文


C# Data.DatabaseObjectProvider类代码示例

本文整理汇总了C#中Subtext.Framework.Data.DatabaseObjectProvider的典型用法代码示例。如果您正苦于以下问题:C# DatabaseObjectProvider类的具体用法?C# DatabaseObjectProvider怎么用?C# DatabaseObjectProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DatabaseObjectProvider类属于Subtext.Framework.Data命名空间,在下文中一共展示了DatabaseObjectProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBlogPostsReturnsActiveOnlyAndNoneInFuture

        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);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:35,代码来源:EntryDayGetTests.cs

示例2: CanDeleteEntryMetaTag

        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.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:25,代码来源:MetaTagDeleteTests.cs

示例3: CanUpdateEnclosure

        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);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:33,代码来源:EnclosureUpdateTests.cs

示例4: Create_WithFeedbackItem_SetsDateCreatedAndModifiedToUtcNow

        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);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:35,代码来源:FeedbackRepositoryTests.cs

示例5: GetReturnsZeroWhenNoMetaTagsExistForBlog

 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.");
 }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:7,代码来源:MetaTagGetTests.cs

示例6: ProcessRequest_WithGetRequest_SendsRssResponse

        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"));
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:29,代码来源:TrackbackHandlerTests.cs

示例7: CreateTrackbackSetsFeedbackTypeCorrectly

        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");
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:26,代码来源:TrackbackCreation.cs

示例8: CanUpdateMetaTag

        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);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:26,代码来源:MetaTagUpdateTests.cs

示例9: CanInsertNewMetaTag

        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");
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:35,代码来源:MetaTagInsertTests.cs

示例10: GetEntriesByTagDoesNotIncludeFuturePosts

        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.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:28,代码来源:FutureEntriesGetTests.cs

示例11: CanGetRecentImages

        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);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:33,代码来源:ImageTests.cs

示例12: GetEntriesByCategoryDoesNotIncludeFuturePosts

        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.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:30,代码来源:FutureEntriesGetTests.cs

示例13: SettingDatePublishedUtcToNullRemovesItemFromSyndication

        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.");
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:33,代码来源:EntryUpdateTests.cs

示例14: TrackbackShowsUpInFeedbackList

        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.");
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:34,代码来源:TrackbackCreation.cs

示例15: CheckBlogNotReturnedWithoutAlias

        public void CheckBlogNotReturnedWithoutAlias()
        {
            UnitTestHelper.CreateBlogAndSetupContext();
            var repository = new DatabaseObjectProvider();
            Blog testBlog = repository.GetBlogByDomainAlias(UnitTestHelper.GenerateUniqueString(),
                                                                           UnitTestHelper.GenerateUniqueString(), false);

            Assert.IsNull(testBlog);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:9,代码来源:BlogAliasTests.cs


注:本文中的Subtext.Framework.Data.DatabaseObjectProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。