本文整理汇总了C#中Mock.SetupRequestContext方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetupRequestContext方法的具体用法?C# Mock.SetupRequestContext怎么用?C# Mock.SetupRequestContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.SetupRequestContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeControls_WithReferrer_LoadsMoreResultsControl
public void InitializeControls_WithReferrer_LoadsMoreResultsControl()
{
// arrange
var page = new SubtextMasterPage();
var context = new Mock<ISubtextContext>();
context.Setup(c => c.Blog).Returns(new Blog {Id = 123});
context.Setup(c => c.HttpContext.Request.UrlReferrer).Returns(new Uri("http://bing.com/?q=test"));
context.Setup(c => c.HttpContext.Request.IsLocal).Returns(false);
context.Setup(c => c.HttpContext.Request.Url).Returns(new Uri("http://example.com/"));
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/the-slug.aspx");
var routeData = new RouteData();
routeData.Values.Add("slug", "the-slug");
context.SetupRequestContext(httpContext, routeData)
.SetupBlog(new Blog { Id = 1, TimeZoneId = TimeZonesTest.PacificTimeZoneId /* pacific */})
.Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });
page.SubtextContext = context.Object;
page.SetControls(new[] { "Test" });
var searchEngine = new Mock<ISearchEngineService>();
searchEngine.Setup(s => s.Search(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new[]{new SearchEngineResult()});
page.SearchEngineService = searchEngine.Object;
var loader = new Mock<ISkinControlLoader>();
loader.Setup(l => l.LoadControl("MoreResults")).Returns(new UserControl());
// act
page.InitializeControls(loader.Object);
// assert
loader.Verify(l => l.LoadControl("Test"));
}
示例2: GetEntryFromRequest_WithSlugInRouteDataMatchingEntryInRepository_ReturnsEntry
public void GetEntryFromRequest_WithSlugInRouteDataMatchingEntryInRepository_ReturnsEntry()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/the-slug.aspx");
var routeData = new RouteData();
routeData.Values.Add("slug", "the-slug");
var subtextContext = new Mock<ISubtextContext>();
subtextContext.SetupRequestContext(httpContext, routeData)
.SetupBlog(new Blog { Id = 1, TimeZoneId = TimeZonesTest.PacificTimeZoneId /* pacific */})
.Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" });
//act
Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object);
//assert
Assert.AreEqual(123, entry.Id);
Assert.AreEqual("Testing 123", entry.Title);
Assert.AreEqual("the-slug", entry.EntryName);
}
示例3: GetEntryFromRequest_WithIdInRouteDataMatchingEntryInRepository_ReturnsEntry
public void GetEntryFromRequest_WithIdInRouteDataMatchingEntryInRepository_ReturnsEntry()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/123.aspx");
var routeData = new RouteData();
routeData.Values.Add("id", "123");
var subtextContext = new Mock<ISubtextContext>();
subtextContext.SetupRequestContext(httpContext, routeData, new Blog { Id = 123 })
.Setup(c => c.Repository.GetEntry(123, true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, Title = "Testing 123" });
//act
Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object);
//assert
Assert.AreEqual(123, entry.Id);
Assert.AreEqual("Testing 123", entry.Title);
}
示例4: GetEntryFromRequest_WithNonExistentEntry_DoesNotThrowNullReferenceException
public void GetEntryFromRequest_WithNonExistentEntry_DoesNotThrowNullReferenceException()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/99999.aspx");
var routeData = new RouteData();
routeData.Values.Add("id", "999999");
var subtextContext = new Mock<ISubtextContext>();
subtextContext.SetupRequestContext(httpContext, routeData)
.Setup(c => c.Repository.GetEntry(It.IsAny<int>(), true, true)).Returns((Entry)null);
//act
Cacher.GetEntryFromRequest(true, subtextContext.Object);
//assert
//None needed.
}
示例5: Entry
public void GetEntryFromRequest_WithEntryHavingEntryNameButIdInRouteDataMatchingEntryInRepository_RedirectsToUrlWithSlug()
{
//arrange
var repository = new Mock<ObjectRepository>();
var entry = new Entry(PostType.BlogPost) { Id = 123, EntryName = "testing-slug", Title = "Testing 123" };
repository.Setup(r => r.GetEntry(123, true, true)).Returns(entry);
var urlHelper = new Mock<BlogUrlHelper>();
urlHelper.Setup(u => u.EntryUrl(It.IsAny<Entry>())).Returns("/archive/testing-slug.aspx");
UnitTestHelper.SetupBlog();
var response = new Mock<HttpResponseBase>();
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/testing-slug.aspx");
httpContext.Setup(c => c.Response).Returns(response.Object);
var routeData = new RouteData();
routeData.Values.Add("id", "123");
var subtextContext = new Mock<ISubtextContext>();
subtextContext.SetupRequestContext(httpContext, routeData)
.SetupUrlHelper(urlHelper)
.SetupRepository(repository.Object)
.SetupBlog(new Blog { Host = "localhost" });
subtextContext.Setup(c => c.HttpContext).Returns(httpContext.Object);
//act
Entry cachedEntry = Cacher.GetEntryFromRequest(true /* allowRedirect */, subtextContext.Object);
//assert
response.Verify(r => r.RedirectPermanent("http://localhost/archive/testing-slug.aspx", true));
Assert.AreEqual(123, cachedEntry.Id);
Assert.AreEqual("Testing 123", cachedEntry.Title);
}