本文整理汇总了C#中FubuMVC.Core.Registration.Routes.RouteDefinition类的典型用法代码示例。如果您正苦于以下问题:C# RouteDefinition类的具体用法?C# RouteDefinition怎么用?C# RouteDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RouteDefinition类属于FubuMVC.Core.Registration.Routes命名空间,在下文中一共展示了RouteDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public IRouteDefinition Build(ActionCall call)
{
var className = call.HandlerType.Name.ToLower()
.Replace("endpoints", "")
.Replace("endpoint", "")
.Replace("controller", "");
RouteDefinition route = null;
if (RouteDefinition.VERBS.Any(x => x.EqualsIgnoreCase(call.Method.Name)))
{
route = new RouteDefinition(className);
route.AddHttpMethodConstraint(call.Method.Name.ToUpper());
}
else
{
route = new RouteDefinition("{0}/{1}".ToFormat(className, call.Method.Name.ToLowerInvariant()));
}
if (call.InputType() != null)
{
if (call.InputType().CanBeCastTo<ResourcePath>())
{
ResourcePath.AddResourcePathInputs(route);
}
else
{
AddBasicRouteInputs(call, route);
}
}
return route;
}
示例2: add_http_method_constraint
public void add_http_method_constraint()
{
var route = new RouteDefinition("something");
route.AddHttpMethodConstraint("get");
route.GetHttpMethodConstraints().ShouldHaveTheSameElementsAs("GET");
}
示例3: create_url_for_a_route_with_two_parameters
public void create_url_for_a_route_with_two_parameters()
{
var url = new RouteDefinition<SampleViewModel>("my/sample/{InPath}/{AlsoInPath}");
url.AddRouteInput(x => x.InPath);
url.AddRouteInput(x => x.AlsoInPath);
url.ToRoute().Url.ShouldEqual("my/sample/{InPath}/{AlsoInPath}");
}
示例4: Configure
public void Configure(BehaviorGraph graph)
{
var route = new RouteDefinition("");
route.AddHttpMethodConstraint("GET");
var chain = new BehaviorChain { Route = route };
chain.AddToEnd(new RedirectNode());
graph.AddChain(chain);
graph.Services.AddService(this);
}
示例5: add_constraint_to_route_with_model
public void add_constraint_to_route_with_model()
{
var url = new RouteDefinition<SampleViewModel>("my/sample");
var constraintToAdd = new HttpMethodConstraint("POST");
url.AddRouteConstraint("httpMethod", constraintToAdd);
Route route = url.ToRoute();
route.Constraints["httpMethod"].ShouldEqual(constraintToAdd);
}
示例6: AddBasicRouteInputs
public static void AddBasicRouteInputs(ActionCall call, RouteDefinition route)
{
call.InputType()
.GetProperties()
.Where(x => x.HasAttribute<RouteInputAttribute>())
.Each(prop => route.Append("{" + prop.Name + "}"));
route.ApplyInputType(call.InputType());
}
示例7: create_default_value_for_a_route
public void create_default_value_for_a_route()
{
var url = new RouteDefinition<SampleViewModel>("my/sample");
url.AddRouteInput(x => x.InPath);
url.RouteInputFor("InPath").DefaultValue = "something";
Route route = url.ToRoute();
route.Defaults["InPath"].ShouldEqual("something");
}
示例8: create_url_with_input_model
public void create_url_with_input_model()
{
var url = new RouteDefinition<SampleViewModel>("test/edit/{InPath}");
url.AddRouteInput(x => x.InPath);
url.CreateUrl(new SampleViewModel
{
InPath = "5"
}).ShouldEqual("/test/edit/5");
}
示例9: add_constraint_to_route_with_model
public void add_constraint_to_route_with_model()
{
var parent = new RouteDefinition("my/sample");
parent.Input = new RouteInput<SampleViewModel>(parent);
var constraintToAdd = new HttpMethodConstraint("POST");
parent.AddRouteConstraint("httpMethod", constraintToAdd);
Route route = parent.ToRoute();
route.Constraints["httpMethod"].ShouldEqual(constraintToAdd);
}
示例10: Build
public IRouteDefinition Build(ActionCall call)
{
Type viewModelType = call.HandlerType.GetGenericArguments()[0];
var route = new RouteDefinition(viewModelType.Name.Replace("ViewModel","").ToLower());
route.ApplyInputType(viewModelType);
route.AddHttpMethodConstraint("POST");
return route;
}
示例11: create_url_will_escape_the_url
public void create_url_will_escape_the_url()
{
var url = new RouteDefinition<SampleViewModel>("test/edit/{InPath}");
url.AddRouteInput(x => x.InPath);
url.CreateUrl(new SampleViewModel
{
InPath = "some text"
}).ShouldEqual("/test/edit/some%20text");
}
示例12: create_two_default_values_for_a_route
public void create_two_default_values_for_a_route()
{
var url = new RouteDefinition<SampleViewModel>("my/sample");
url.AddRouteInput(x => x.InPath);
url.AddRouteInput(x => x.AlsoInPath);
url.RouteInputFor("InPath").DefaultValue = "something";
url.RouteInputFor("AlsoInPath").DefaultValue = "something else";
Route route = url.ToRoute();
route.Defaults.Count().ShouldEqual(2);
}
示例13: Build
public IRouteDefinition Build(ActionCall call)
{
// Later on we need to put in real plural naming.
string pattern = call.HandlerType.GetGenericArguments()[0].Name.Replace("ViewModel", "") + "es";
var route = new RouteDefinition(pattern.ToLower());
route.ApplyInputType(call.InputType());
route.AddHttpMethodConstraint("GET");
return route;
}
示例14: adds_the_route_aliases
public void adds_the_route_aliases()
{
var route1 = new RouteDefinition("something/else");
var route2 = new RouteDefinition("again/something/else");
var chain = theGraph.BehaviorFor<RouteAliasController>(x => x.get_something());
var routes = chain.AdditionalRoutes;
routes.ShouldHaveCount(2);
routes.ShouldContain(route1);
routes.ShouldContain(route2);
}
示例15: create_url_with_input_model_and_default_value_for_optional_input
public void create_url_with_input_model_and_default_value_for_optional_input()
{
var url = new RouteDefinition<SampleViewModelWithInputs>("test/edit/{OptionalInput}");
url.AddRouteInput(x => x.OptionalInput);
url
.CreateUrl(new SampleViewModelWithInputs
{
OptionalInput = "a"
})
.ShouldEndWith("/test/edit/a");
}