本文整理汇总了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"));
}
示例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"));
}
示例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);
}
示例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());
}