本文整理汇总了C#中Mock.FakeRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.FakeRequest方法的具体用法?C# Mock.FakeRequest怎么用?C# Mock.FakeRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.FakeRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestWithoutSubfolder_ForAshxFileInDirectory_GetsHandlerInPhysicalDirectory
public void RequestWithoutSubfolder_ForAshxFileInDirectory_GetsHandlerInPhysicalDirectory()
{
//arrange
string virtualPath = string.Empty;
var routeData = new RouteData
{
Route = new DirectoryRoute("admin", new Mock<IDependencyResolver>().Object)
};
;
routeData.Values.Add("pathinfo", "foo.ashx");
var pageBuilder = new Mock<ISubtextPageBuilder>();
var httpHandler = new Mock<IHttpHandler>();
pageBuilder.Setup(b => b.CreateInstanceFromVirtualPath(It.IsAny<string>(), It.IsAny<Type>())).Returns(
httpHandler.Object).Callback<string, Type>((vpath, type) => virtualPath = vpath);
IRouteHandler routeHandler = new DirectoryRouteHandler(pageBuilder.Object, new Mock<IDependencyResolver>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/admin/foo.ashx");
var requestContext = new RequestContext(httpContext.Object, routeData);
//act
IHttpHandler handler = routeHandler.GetHttpHandler(requestContext);
//assert
Assert.AreEqual("~/aspx/admin/foo.ashx", virtualPath);
}
示例2: GetRouteDataWithAnyRequest_ReturnsNull
public void GetRouteDataWithAnyRequest_ReturnsNull()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/", string.Empty /* subfolder */, "~/");
var route = new ImageRoute("{*anything}");
//act
RouteData routeData = route.GetRouteData(httpContext.Object);
//assert
Assert.IsNull(routeData);
}
示例3: GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute
public void GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute()
{
//arrange
var route = new DirectoryRoute("dir", new Mock<IServiceLocator>().Object);
;
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/subfolder/dir/foo.aspx");
var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost"), false);
//act
RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);
//assert
Assert.AreEqual(route, routeData.Route);
}
示例4: GetRouteDataWithRequestForDefaultInSubfolder_WhenAggregationEnabled_MatchesRequestAndReturnsDtp
public void GetRouteDataWithRequestForDefaultInSubfolder_WhenAggregationEnabled_MatchesRequestAndReturnsDtp()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/subfolder/default.aspx", "subfolder" /* subfolder */, "~/");
var route = new STRouting.RootRoute(true, new Mock<IDependencyResolver>().Object);
//act
RouteData routeData = route.GetRouteData(httpContext.Object);
//assert
var routeHandler = routeData.RouteHandler as STRouting.PageRouteHandler;
Assert.AreEqual("~/aspx/Dtp.aspx", routeHandler.VirtualPath);
Assert.AreSame(route, routeData.Route);
}
示例5: RequestUrlWithSingleDigitMonth_ForBlogPost_DoesNotMatchPageRoute
public void RequestUrlWithSingleDigitMonth_ForBlogPost_DoesNotMatchPageRoute()
{
//arrange
var routes = new RouteCollection();
var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
Routes.RegisterRoutes(subtextRoutes);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/2008/1/10/blog-post.aspx");
//act
RouteData routeData = routes.GetRouteData(httpContext.Object);
//assert.
Assert.IsNull(routeData);
}
示例6: RequestWithoutSubfolderForInstallDirectory_Matches
public void RequestWithoutSubfolderForInstallDirectory_Matches()
{
//arrange
var routes = new RouteCollection();
var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
Routes.RegisterRoutes(subtextRoutes);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/install/default.aspx", "");
//act
RouteData routeData = routes.GetRouteData(httpContext.Object);
//assert.
Assert.IsNotNull(routeData);
}
示例7: GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute
public void GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute()
{
//arrange
var route = new PageRoute("url", "~/aspx/Dtp.aspx", new[] { "foo" }, new Mock<ISubtextPageBuilder>().Object,
new Mock<IDependencyResolver>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/subfolder/url");
var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost"), false);
//act
RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);
//assert
Assert.AreEqual(route, routeData.Route);
}
示例8: GetRouteDataWithRequestForAppRoot_WhenAggregationEnabled_MatchesAndReturnsAggDefault
public void GetRouteDataWithRequestForAppRoot_WhenAggregationEnabled_MatchesAndReturnsAggDefault()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/", string.Empty /* subfolder */, "~/");
var route = new STRouting.RootRoute(true, new Mock<IDependencyResolver>().Object);
//act
RouteData routeData = route.GetRouteData(httpContext.Object);
//assert
var routeHandler = routeData.RouteHandler as STRouting.PageRouteHandler;
Assert.AreEqual("~/aspx/AggDefault.aspx", routeHandler.VirtualPath);
Assert.AreSame(route, routeData.Route);
Assert.IsFalse(routeData.DataTokens.ContainsKey(STRouting.PageRoute.ControlNamesKey));
}
示例9: GetRouteDataWithRequestForAppRoot_WhenAggregationDisabled_MatchesAndReturnsDtp
public void GetRouteDataWithRequestForAppRoot_WhenAggregationDisabled_MatchesAndReturnsDtp()
{
//arrange
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/", string.Empty /* subfolder */, "~/");
var route = new STRouting.RootRoute(false, new Mock<IServiceLocator>().Object);
//act
RouteData routeData = route.GetRouteData(httpContext.Object);
//assert
var routeHandler = routeData.RouteHandler as STRouting.PageRouteHandler;
Assert.AreEqual("~/aspx/Dtp.aspx", routeHandler.VirtualPath);
Assert.AreSame(route, routeData.Route);
Assert.IsTrue(routeData.DataTokens.ContainsKey(STRouting.PageRoute.ControlNamesKey));
}
示例10: GetRouteData_ForRequestForEntryAdminController_Matches
public void GetRouteData_ForRequestForEntryAdminController_Matches()
{
//arrange
var routes = new RouteCollection();
var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
Routes.RegisterRoutes(subtextRoutes);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/admin/comments/destroy.ashx", "");
//act
RouteData routeData = routes.GetRouteData(httpContext.Object);
//assert.
Assert.IsNotNull(routeData);
Assert.AreEqual("comment", routeData.Values["controller"]);
Assert.AreEqual("destroy", routeData.Values["action"]);
}
示例11: GetRouteData_ForRequestForExportController_Matches
public void GetRouteData_ForRequestForExportController_Matches()
{
//arrange
var routes = new RouteCollection();
var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
Routes.RegisterRoutes(subtextRoutes);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/admin/export.ashx", "");
//act
RouteData routeData = routes.GetRouteData(httpContext.Object);
//assert.
Assert.IsNotNull(routeData);
Assert.AreEqual("export", routeData.Values["controller"]);
Assert.AreEqual("blogml", routeData.Values["action"]);
}
示例12: GetVirtualPath_WithoutSubolder_ReturnsUrlWithoutSubfolder
public void GetVirtualPath_WithoutSubolder_ReturnsUrlWithoutSubfolder()
{
//arrange
var route = new PageRoute("archive/{slug}.aspx", "~/aspx/Dtp.aspx", null,
new Mock<ISubtextPageBuilder>().Object, new Mock<IDependencyResolver>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/slug.aspx");
var routeData = new RouteData();
var requestContext = new RequestContext(httpContext.Object, routeData);
//act
VirtualPathData virtualPath = route.GetVirtualPath(requestContext,
new RouteValueDictionary(new { slug = "test-slug" }));
//assert
Assert.IsNotNull(virtualPath);
Assert.AreEqual("archive/test-slug.aspx", virtualPath.VirtualPath);
}
示例13: RequestWithoutSubfolder_ForBlogPostWithoutSubfolder_Matches
public void RequestWithoutSubfolder_ForBlogPostWithoutSubfolder_Matches()
{
//arrange
var subtextRoute = new PageRoute("archive/{slug}", "~/aspx/Dtp.aspx", null,
new Mock<ISubtextPageBuilder>().Object, new Mock<IDependencyResolver>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/archive/blog-post");
//This info is provided by the BlogRequestModule.
var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/archive/blog-post"),
true);
//act
RouteData routeData = subtextRoute.GetRouteData(httpContext.Object, blogRequest);
//assert.
Assert.IsNotNull(routeData);
Assert.AreEqual("blog-post", routeData.Values["slug"]);
Assert.AreEqual(string.Empty, routeData.Values["subfolder"]);
}
示例14: GetVirtualPath_WithoutSubolder_ReturnsUrlWithoutSubfolder
public void GetVirtualPath_WithoutSubolder_ReturnsUrlWithoutSubfolder()
{
//arrange
var route = new DirectoryRoute("admin", new Mock<IServiceLocator>().Object);
var httpContext = new Mock<HttpContextBase>();
httpContext.FakeRequest("~/admin/posts/foo.aspx");
var blogRequest = new BlogRequest("localhost", null, new Uri("http://localhost"), true);
var routeData = new RouteData();
var requestContext = new RequestContext(httpContext.Object, routeData);
//act
VirtualPathData virtualPath = route.GetVirtualPath(requestContext
,
new RouteValueDictionary(
new {pathInfo = "posts/foo.aspx"}));
//assert
Assert.IsNotNull(virtualPath);
Assert.AreEqual("admin/posts/foo.aspx", virtualPath.VirtualPath);
}
示例15: FakeSubtextContextRequest
public static StringWriter FakeSubtextContextRequest(this Mock<ISubtextContext> subtextContextMock, Blog blog,
string virtualPath, string applicationPath,
string subfolder)
{
var httpContext = new Mock<HttpContextBase>();
StringWriter writer = httpContext.FakeRequest(virtualPath, subfolder);
httpContext.SetupApplicationPath(applicationPath);
httpContext.Stub(h => h.Response.ContentType);
var hashTable = new Hashtable();
httpContext.Setup(c => c.Items).Returns(hashTable);
var urlHelper = new Mock<BlogUrlHelper>();
var routeData = new RouteData();
routeData.Values.Add("subfolder", subfolder);
subtextContextMock.Setup(c => c.HttpContext).Returns(httpContext.Object);
subtextContextMock.SetupBlog(blog)
.SetupUrlHelper(urlHelper)
.SetupRequestContext(httpContext, routeData);
return writer;
}