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


C# Mock.FakeSubtextContextRequest方法代码示例

本文整理汇总了C#中Mock.FakeSubtextContextRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.FakeSubtextContextRequest方法的具体用法?C# Mock.FakeSubtextContextRequest怎么用?C# Mock.FakeSubtextContextRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.FakeSubtextContextRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: ProcessRequest_WithInvalidEntryId_SendsErrorResponse

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

示例3: ProcessRequest_WithValidTrackback_CreatesTracbackRecordInDatabase

        public void ProcessRequest_WithValidTrackback_CreatesTracbackRecordInDatabase()
        {
            //arrange
            var repository = new DatabaseObjectProvider();
            UnitTestHelper.SetupBlog();
            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());
            subtextContext.SetupBlog(blog);
            var handler = new TrackBackHandler(subtextContext.Object);
            handler.SourceVerification += (sender, e) => e.Verified = true;
            Mock<BlogUrlHelper> urlHelper = Mock.Get(subtextContext.Object.UrlHelper);
            urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/whatever/entry");
            urlHelper.Setup(u => u.TrackbacksUrl(It.IsAny<int>())).Returns("/whatever/trackback");
            Mock<HttpContextBase> httpContext = Mock.Get(subtextContext.Object.RequestContext.HttpContext);
            httpContext.Setup(c => c.Request.HttpMethod).Returns("POST");

            var form = new NameValueCollection();
            form["title"] = entry.Title;
            form["excert"] = entry.Body;
            form["url"] = "http://myblog.example.com/";
            form["blog_name"] = "Random Blog";

            httpContext.Setup(c => c.Request.Form).Returns(form);

            //act
            handler.ProcessRequest();

            //assert
            ICollection<FeedbackItem> trackbacks = repository.GetFeedbackForEntry(entry);
            Assert.AreEqual(1, trackbacks.Count, "We expect to see the one feedback we just created.");
            Assert.AreEqual("this is the title", trackbacks.First().Title);
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:41,代码来源:TrackbackHandlerTests.cs

示例4: ProcessRequest_WithTrackbacksDisabled_ReturnEmptyResponse

        public void ProcessRequest_WithTrackbacksDisabled_ReturnEmptyResponse()
        {
            //arrange
            UnitTestHelper.SetupBlog();
            Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "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 = false;
            var subtextContext = new Mock<ISubtextContext>();
            StringWriter writer = subtextContext.FakeSubtextContextRequest(blog, "/trackbackhandler", "/", string.Empty);
            subtextContext.Object.RequestContext.RouteData.Values.Add("id", id.ToString());
            var handler = new TrackBackHandler(subtextContext.Object);

            //act
            handler.ProcessRequest();

            //assert
            Assert.AreEqual(string.Empty, writer.ToString());
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:22,代码来源:TrackbackHandlerTests.cs


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