本文整理汇总了C#中ReflectedHttpActionDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# ReflectedHttpActionDescriptor类的具体用法?C# ReflectedHttpActionDescriptor怎么用?C# ReflectedHttpActionDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReflectedHttpActionDescriptor类属于命名空间,在下文中一共展示了ReflectedHttpActionDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
private void Bind(string methodName)
{
//创建FormatterParameterBinding对象
MethodInfo method = typeof(ContactsController).GetMethod(methodName);
HttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(this.ControllerContext.ControllerDescriptor, method);
HttpParameterDescriptor parameterDescriptor = actionDescriptor.GetParameters().First();
MediaTypeFormatter[] formatters = new MediaTypeFormatter[] { new JsonMediaTypeFormatter() };
FormatterParameterBinding parameterBinding = new FormatterParameterBinding(parameterDescriptor, formatters, null);
//创建HttpActionBinding并执行
HttpActionBinding actionBinding = new HttpActionBinding(actionDescriptor,new FormatterParameterBinding[] { parameterBinding });
HttpActionContext actionContext =new HttpActionContext(this.ControllerContext, actionDescriptor);
try
{
actionBinding.ExecuteBindingAsync(actionContext, CancellationToken.None).Wait();
//获取绑定参数对象并打印相关数据
Contact contact = (Contact)actionContext.ActionArguments["contact"];
Console.WriteLine("{0,-12}: {1}", "Name", contact.Name);
Console.WriteLine("{0,-12}: {1}", "Phone No.", contact.PhoneNo);
Console.WriteLine("{0,-12}: {1}", "EmailAddress", contact.EmailAddress);
Console.WriteLine("{0,-12}: {1}", "Address", contact.Address);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例2: WrapperResolvesAuthenticationFilterFromDependencyScope
public void WrapperResolvesAuthenticationFilterFromDependencyScope()
{
var builder = new ContainerBuilder();
builder.Register<ILogger>(c => new Logger()).InstancePerDependency();
var activationCount = 0;
builder.Register<IAutofacAuthenticationFilter>(c => new TestAuthenticationFilter(c.Resolve<ILogger>()))
.AsWebApiAuthenticationFilterFor<TestController>(c => c.Get())
.InstancePerRequest()
.OnActivated(e => activationCount++);
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
var configuration = new HttpConfiguration { DependencyResolver = resolver };
var requestMessage = new HttpRequestMessage();
requestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, configuration);
var contollerContext = new HttpControllerContext { Request = requestMessage };
var controllerDescriptor = new HttpControllerDescriptor { ControllerType = typeof(TestController) };
var methodInfo = typeof(TestController).GetMethod("Get");
var actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, methodInfo);
var actionContext = new HttpActionContext(contollerContext, actionDescriptor);
var context = new HttpAuthenticationContext(actionContext, Thread.CurrentPrincipal);
var metadata = new FilterMetadata
{
ControllerType = typeof(TestController),
FilterScope = FilterScope.Action,
MethodInfo = methodInfo
};
var wrapper = new AuthenticationFilterWrapper(metadata);
wrapper.OnAuthenticate(context);
Assert.That(activationCount, Is.EqualTo(1));
}
示例3: Ctor_SetsActionsDataToken
public void Ctor_SetsActionsDataToken()
{
var actions = new ReflectedHttpActionDescriptor[0];
var route = new HttpDirectRoute("route", 0, actions);
Assert.Equal(actions, route.Actions);
}
示例4: IsDefined_Retruns_True_WhenParameterAttributeIsFound
public void IsDefined_Retruns_True_WhenParameterAttributeIsFound()
{
UsersRpcController controller = new UsersRpcController();
Action<User> addUserMethod = controller.AddUser;
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
}
示例5: ParameterBinderAttribute_NotNull_WhenParameterAttributeIsFound
public void ParameterBinderAttribute_NotNull_WhenParameterAttributeIsFound()
{
UsersRpcController controller = new UsersRpcController();
Action<User> addUserMethod = controller.AddUser;
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
Assert.NotNull(parameterDescriptor.ParameterBinderAttribute);
}
示例6: Ctor_SetsActionsDataToken
public void Ctor_SetsActionsDataToken()
{
var actions = new ReflectedHttpActionDescriptor[0];
var route = HttpRouteBuilder.BuildDirectRoute("route", 0, actions);
var actualActions = route.DataTokens[RouteKeys.ActionsDataTokenKey];
Assert.Equal(actions, actualActions);
}
示例7: IsOptional_Returns_True_ForOptionalParameter
public void IsOptional_Returns_True_ForOptionalParameter()
{
UsersRpcController controller = new UsersRpcController();
MethodInfo methodWithOptionalParam = GetType().GetMethod("MethodWithOptionalParam", BindingFlags.Static | BindingFlags.NonPublic);
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = methodWithOptionalParam };
ParameterInfo parameterInfo = methodWithOptionalParam.GetParameters()[0];
ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
Assert.True(parameterDescriptor.IsOptional);
}
示例8: CreateBuilderWithoutResolverAndBuild_AddsDefaultValuesAsOptional
public void CreateBuilderWithoutResolverAndBuild_AddsDefaultValuesAsOptional()
{
var actions = new ReflectedHttpActionDescriptor[] { new ReflectedHttpActionDescriptor() };
var route = BuildWithoutResolver("movies/{id}", actions);
route.Defaults.Add("id", RouteParameter.Optional);
var routeData = route.GetRouteData("", new HttpRequestMessage(HttpMethod.Get, "http://localhost/movies"));
Assert.Equal(RouteParameter.Optional, routeData.Values["id"]);
}
示例9: GetFilters_ReturnsEmptyCollection_ForNonQueryableActions
public void GetFilters_ReturnsEmptyCollection_ForNonQueryableActions(string actionName)
{
HttpConfiguration config = new HttpConfiguration();
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(config, "FilterProviderTest", typeof(FilterProviderTestController));
HttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(FilterProviderTestController).GetMethod(actionName));
FilterInfo[] filters = new QueryFilterProvider(new EnableQueryAttribute()).GetFilters(config, actionDescriptor).ToArray();
Assert.Empty(filters);
}
示例10: GetRouteData_AddsDefaultValuesAsNull
public void GetRouteData_AddsDefaultValuesAsNull()
{
var actions = new ReflectedHttpActionDescriptor[] { new ReflectedHttpActionDescriptor() };
var route = new HttpDirectRoute("movies/{id}", 0, actions);
route.Defaults.Add("id", RouteParameter.Optional);
var routeData = route.GetRouteData("", new HttpRequestMessage(HttpMethod.Get, "http://localhost/movies"));
Assert.Null(routeData.Values["id"]);
}
示例11: GetCustomAttributes_AttributeType_Returns_ParameterAttributes
public void GetCustomAttributes_AttributeType_Returns_ParameterAttributes()
{
UsersRpcController controller = new UsersRpcController();
Action<User> addUserMethod = controller.AddUser;
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
IEnumerable<FromBodyAttribute> attributes = parameterDescriptor.GetCustomAttributes<FromBodyAttribute>();
Assert.Equal(1, attributes.Count());
}
示例12: Default_Constructor
public void Default_Constructor()
{
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor();
Assert.Null(actionDescriptor.ActionName);
Assert.Null(actionDescriptor.Configuration);
Assert.Null(actionDescriptor.ControllerDescriptor);
Assert.Null(actionDescriptor.MethodInfo);
Assert.Null(actionDescriptor.ReturnType);
Assert.NotNull(actionDescriptor.Properties);
}
示例13: GetCustomAttributes_Returns_ParameterAttributes
public void GetCustomAttributes_Returns_ParameterAttributes()
{
UsersRpcController controller = new UsersRpcController();
Action<User> addUserMethod = controller.AddUser;
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = addUserMethod.Method };
ParameterInfo parameterInfo = addUserMethod.Method.GetParameters()[0];
ReflectedHttpParameterDescriptor parameterDescriptor = new ReflectedHttpParameterDescriptor(actionDescriptor, parameterInfo);
object[] attributes = parameterDescriptor.GetCustomAttributes<object>().ToArray();
Assert.Equal(1, attributes.Length);
Assert.Equal(typeof(FromBodyAttribute), attributes[0].GetType());
}
示例14: LogExit_should_log_with_exit_text
public void LogExit_should_log_with_exit_text()
{
var helper = new ActionLogHelperTestDouble(_loggerMock.Object);
var controllerDescriptor = new HttpControllerDescriptor { ControllerType = typeof(ActionLogHelper) };
var actionDescriptor = new ReflectedHttpActionDescriptor { ControllerDescriptor = controllerDescriptor };
helper.LogExit(actionDescriptor);
Assert.AreEqual(actionDescriptor, helper.ActionDescriptorGiven);
Assert.AreEqual(ActionLogHelper.ExitingText, helper.PrefixGiven);
}
示例15: ControllerDescriptor_Property
public void ControllerDescriptor_Property()
{
ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor();
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor();
Assert.Reflection.Property<ReflectedHttpActionDescriptor, HttpControllerDescriptor>(
instance: actionDescriptor,
propertyGetter: ad => ad.ControllerDescriptor,
expectedDefaultValue: null,
allowNull: false,
roundTripTestValue: controllerDescriptor);
}