本文整理汇总了C#中MonoTests.System.Web.Routing.HttpContextStub2.SetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextStub2.SetResponse方法的具体用法?C# HttpContextStub2.SetResponse怎么用?C# HttpContextStub2.SetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoTests.System.Web.Routing.HttpContextStub2
的用法示例。
在下文中一共展示了HttpContextStub2.SetResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ignore_String
public void Ignore_String ()
{
var c = new RouteCollection ();
AssertExtensions.Throws<ArgumentNullException> (() => {
c.Ignore (null);
}, "#A1");
c.Ignore ("{resource}.axd/{*pathInfo}");
var hc = new HttpContextStub2 ("~/something.axd/pathinfo", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#A1-1");
Assert.IsNotNull (rd.RouteHandler, "#A1-2");
Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
Assert.IsTrue (rd.Route is Route, "#A1-4");
Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
Assert.AreEqual (0, ((Route) rd.Route).Constraints.Count, "#A1-6");
}
示例2: Ignore_String_Object
public void Ignore_String_Object ()
{
var c = new RouteCollection ();
AssertExtensions.Throws<ArgumentNullException> (() => {
c.Ignore (null, new { allaspx = @".*\.aspx(/.*)?" });
}, "#A1");
c.Ignore ("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
var hc = new HttpContextStub2 ("~/page.aspx", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#A1-1");
Assert.IsNotNull (rd.RouteHandler, "#A1-2");
Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
Assert.IsTrue (rd.Route is Route, "#A1-4");
Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
Assert.AreEqual (1, ((Route) rd.Route).Constraints.Count, "#A1-6");
Assert.AreEqual (@".*\.aspx(/.*)?", ((Route) rd.Route).Constraints ["allaspx"], "#A1-7");
c = new RouteCollection ();
c.Ignore ("{*allaspx}", "something invalid");
AssertExtensions.Throws<InvalidOperationException> (() => {
rd = c.GetRouteData (hc);
}, "#A2");
}
示例3: GetVirtualPathToExistingFile
public void GetVirtualPathToExistingFile ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
// it tries to get HttpContextBase.Response, so set it.
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
}
示例4: GetRouteDataNerdDinner2
public void GetRouteDataNerdDinner2 ()
{
var c = new RouteCollection ();
c.Add ("UpcomingDiners",
new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
);
c.Add ("Default",
new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
);
var hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#A1");
}
示例5: GetVirtualPath4
public void GetVirtualPath4 ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("blog/{user}/{action}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary {
{ "controller", "blog" },
{ "user", "admin" }
}
}
);
c.Add (new MyRoute ("forum/{user}/{action}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary {
{ "controller", "forum" },
{ "user", "admin" }
}
}
);
var hc = new HttpContextStub2 ("~/forum/admin/Index", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="forum"}));
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("/forum/admin/Index", vp.VirtualPath, "#2-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="blah"}));
Assert.IsNull (vp, "#3");
}
示例6: GetVirtualPath6
public void GetVirtualPath6 ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("reports/{year}/{month}/{day}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary {
{ "day", 1 }
}
}
);
var hc = new HttpContextStub2 ("~/reports/2009/05", String.Empty, "/myapp");
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
{ "year", 2007 },
{ "month", 1 },
{ "day", 12 },
}
);
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("/myapp/reports/2007/1/12", vp.VirtualPath, "#2-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
{ "year", 2007 },
{ "month", 1 }
}
);
Assert.IsNotNull (vp, "#3");
Assert.AreEqual ("/myapp/reports/2007/1", vp.VirtualPath, "#3-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
{ "year", 2007 },
{ "month", 1 },
{ "day", 12 },
{ "category", 123 }
}
);
Assert.IsNotNull (vp, "#4");
Assert.AreEqual ("/myapp/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
{ "year", 2007 },
}
);
Assert.IsNull (vp, "#5");
}
示例7: GetVirtualPath2
public void GetVirtualPath2 ()
{
var c = new RouteCollection ();
c.Add ("Summary",
new MyRoute ("summary/{action}-{type}/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Summary", action = "Index", page = 1}) }
);
c.Add ("Apis",
new MyRoute ("apis/{apiname}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Apis", action = "Index" }) }
);
c.Add ("Single Report",
new MyRoute ("report/{guid}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "SingleReport" }) }
);
c.Add ("Reports",
new MyRoute ("reports/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "Index", page = 1 }) }
);
c.Add ("Default",
new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index"}) }
);
var hc = new HttpContextStub2 ("~/Home/About", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (2));
var rd = c.GetRouteData (hc);
var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.IsNotNull (vpd, "#A1");
Assert.AreEqual ("/Home/About_modified", vpd.VirtualPath, "#A2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");
hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (2));
rd = c.GetRouteData (hc);
vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.IsNotNull (vpd, "#B1");
Assert.AreEqual ("/_modified", vpd.VirtualPath, "#B2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");
hc = new HttpContextStub2 ("~/Account/LogOn", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (2));
rd = c.GetRouteData (hc);
vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.IsNotNull (vpd, "#C1");
Assert.AreEqual ("/Account/LogOn_modified", vpd.VirtualPath, "#C2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");
hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
rd = c.GetRouteData (hc);
vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }) );
Assert.IsNotNull (vpd, "#D1");
Assert.AreEqual ("/", vpd.VirtualPath, "#D2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#D3");
hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
rd = c.GetRouteData (hc);
vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "Home" }) );
Assert.IsNotNull (vpd, "#E1");
Assert.AreEqual ("/", vpd.VirtualPath, "#E2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#E3");
}
示例8: PostResolveRequestCachePathToExistingFile
public void PostResolveRequestCachePathToExistingFile ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("~/{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/hoge/fuga", String.Empty, ".");
// it tries to get HttpContextBase.Response, so set it.
hc.SetResponse (new HttpResponseStub (3));
try {
m.PostResolveRequestCache (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
}
示例9: GetVirtualPathCheckVirtualPathToModify
public void GetVirtualPathCheckVirtualPathToModify ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
// it tries to get HttpContextBase.Response, so set it.
hc.SetResponse (new HttpResponseStub (1));
var rd = c.GetRouteData (hc);
try {
var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("apppath/x/y", ex.Message, "#2");
}
}
示例10: GetVirtualPath
public void GetVirtualPath ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
// it tries to get HttpContextBase.Response, so set it.
hc.SetResponse (new HttpResponseStub (2));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.IsNotNull (vpd, "#2");
Assert.AreEqual ("apppath/x/y_modified", vpd.VirtualPath, "#3");
Assert.AreEqual (0, vpd.DataTokens.Count, "#4");
}
示例11: GetVirtualPathNoApplyAppPathModifier
public void GetVirtualPathNoApplyAppPathModifier ()
{
var c = new RouteCollection ();
c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
// it tries to call HttpContextBase.Response.ApplyAppPathModifier() and then causes NIE.
hc.SetResponse (new HttpResponseStub ());
var rd = c.GetRouteData (hc);
var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
}
示例12: GetVirtualPath8
public void GetVirtualPath8 ()
{
var routes = new RouteCollection();
routes.Add (new MyRoute ("login", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary (new { controller = "Home", action = "LogOn" })
});
routes.Add (new MyRoute ("{site}/{controller}/{action}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary (new { site = "_", controller = "Home", action = "Index" }),
Constraints = new RouteValueDictionary ( new { site = "_?[0-9A-Za-z-]*" })
});
routes.Add (new MyRoute ("{*path}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary (new { controller = "Error", action = "NotFound" }),
});
var hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = routes.GetRouteData (hc);
var rvs = new RouteValueDictionary () {
{ "controller", "Home" },
{ "action" , "Index" }
};
var vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
Assert.IsNotNull (vpd, "#A1");
Assert.AreEqual ("/", vpd.VirtualPath, "#A2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");
hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
rd = routes.GetRouteData (hc);
rvs = new RouteValueDictionary () {
{ "controller", "Home" }
};
vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
Assert.IsNotNull (vpd, "#B1");
Assert.AreEqual ("/login", vpd.VirtualPath, "#B2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");
hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
rd = routes.GetRouteData (hc);
rvs = new RouteValueDictionary () {
{ "action" , "Index" }
};
vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
Assert.IsNotNull (vpd, "#C1");
Assert.AreEqual ("/", vpd.VirtualPath, "#C2");
Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");
hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
rd = routes.GetRouteData (hc);
Assert.IsNotNull (rd, "#D1");
}
示例13: Pipeline3
public void Pipeline3 ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
#if NET_4_0
var hc = new HttpContextStub5 ("~/x/y", String.Empty, "apppath");
#else
var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
#endif
hc.SetResponse (new HttpResponseStub (2));
#if NET_4_0
Assert.IsNull (m.RouteCollection.GetRouteData (hc), "#0");
#else
Assert.IsNotNull (m.RouteCollection.GetRouteData (hc), "#0");
m.PostResolveRequestCache (hc);
try {
m.PostMapRequestHandler (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
#endif
}
示例14: MapPageRoute_String_String_String
public void MapPageRoute_String_String_String ()
{
var c = new RouteCollection ();
c.MapPageRoute (null, "{foo}-{bar}", "~/some-url");
var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#A1-1");
Assert.IsNotNull (rd.RouteHandler, "#A1-2");
Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
c = new RouteCollection ();
AssertExtensions.Throws<ArgumentNullException> (() => {
c.MapPageRoute ("RouteName", null, "~/some-url");
}, "#A2");
c = new RouteCollection ();
c.MapPageRoute ("RouteName", String.Empty, "~/some-url");
rd = c.GetRouteData (hc);
Assert.IsNull (rd, "#A2");
c = new RouteCollection ();
// thrown by PageRouteHandler's constructor
AssertExtensions.Throws<ArgumentException> (() => {
c.MapPageRoute ("RouteName", "~/some-url", null);
}, "#A3");
}
示例15: GetVirtualPath3
public void GetVirtualPath3 ()
{
var c = new RouteCollection ();
c.Add ("todo-route",
new MyRoute ("todo/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "todo", action="list", page=0}) }
);
c.Add ("another-route",
new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "home", action="list", page=0}) }
);
var hc = new HttpContextStub2 ("~/home/list", String.Empty, String.Empty);
hc.SetResponse (new HttpResponseStub (3));
var rd = c.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
Assert.AreEqual (3, rd.Values.Count, "#1-1");
Assert.AreEqual ("home", rd.Values["controller"], "#1-2");
Assert.AreEqual ("list", rd.Values["action"], "#1-3");
Assert.AreEqual (0, rd.Values["page"], "#1-4");
var vp = c.GetVirtualPath (new RequestContext (hc, rd), "todo-route", new RouteValueDictionary ());
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("/todo", vp.VirtualPath, "#2-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary ());
Assert.IsNotNull (vp, "#3");
Assert.AreEqual ("/todo", vp.VirtualPath, "#3-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }));
Assert.IsNotNull (vp, "#4");
Assert.AreEqual ("/", vp.VirtualPath, "#4-1");
vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home", extra="stuff" }));
Assert.IsNotNull (vp, "#5");
Assert.AreEqual ("/?extra=stuff", vp.VirtualPath, "#5-1");
}