本文整理汇总了C#中HttpConfiguration.EnsureInitialized方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.EnsureInitialized方法的具体用法?C# HttpConfiguration.EnsureInitialized怎么用?C# HttpConfiguration.EnsureInitialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpConfiguration
的用法示例。
在下文中一共展示了HttpConfiguration.EnsureInitialized方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttriubteRouting_SelectsExpectedControllerAndAction
[InlineData("GET", "http://localhost/Customers(42)/NS.SpecialCustomer/IsSpecialUpgraded()", "IsSpecialUpgraded_42")] // function bound to derived entity type
public async Task AttriubteRouting_SelectsExpectedControllerAndAction(string method, string requestUri,
string expectedResult)
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
var controllers = new[] { typeof(CustomersController), typeof(MetadataController), typeof(OrdersController) };
TestAssemblyResolver resolver = new TestAssemblyResolver(new MockAssembly(controllers));
HttpConfiguration config = new HttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Services.Replace(typeof(IAssembliesResolver), resolver);
config.Routes
.MapODataRoute("odata", "", model.Model)
.MapODataRouteAttributes(config);
HttpServer server = new HttpServer(config);
config.EnsureInitialized();
HttpClient client = new HttpClient(server);
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(method), requestUri);
// Act
var response = await client.SendAsync(request);
// Assert
if (!response.IsSuccessStatusCode)
{
Assert.False(true, await response.Content.ReadAsStringAsync());
}
var result = await response.Content.ReadAsAsync<AttributeRoutingTestODataResponse>();
Assert.Equal(expectedResult, result.Value);
}
示例2: EmptyDescription_OnAttributeRoutedAction_UsingStandardRoute
public void EmptyDescription_OnAttributeRoutedAction_UsingStandardRoute()
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute("Default", "api/someAction/{id}", new { controller = "Attributed", action = "Get" });
DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(AttributedController));
config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);
config.EnsureInitialized();
IApiExplorer explorer = config.Services.GetApiExplorer();
Assert.Empty(explorer.ApiDescriptions);
}
示例3: VerifyDescription_OnMixedRoutes
public void VerifyDescription_OnMixedRoutes(Type controllerType, List<object> expectedResults)
{
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("Default", "api/{controller}/{id}", new { id = RouteParameter.Optional });
DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, controllerType);
config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);
config.EnsureInitialized();
IApiExplorer explorer = config.Services.GetApiExplorer();
ApiExplorerHelper.VerifyApiDescriptions(explorer.ApiDescriptions, expectedResults);
}
示例4: CtorTakingHttpConfiguration_InitializesAttributeMappings_OnFirstSelectControllerCall
public void CtorTakingHttpConfiguration_InitializesAttributeMappings_OnFirstSelectControllerCall()
{
// Arrange
HttpConfiguration config = new HttpConfiguration();
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataPathTemplate pathTemplate = new ODataPathTemplate();
Mock<IODataPathTemplateHandler> pathTemplateHandler = new Mock<IODataPathTemplateHandler>();
pathTemplateHandler.Setup(p => p.ParseTemplate(model.Model, "Customers")).Returns(pathTemplate).Verifiable();
AttributeRoutingConvention convention = new AttributeRoutingConvention(model.Model, config, pathTemplateHandler.Object);
config.EnsureInitialized();
// Act
convention.SelectController(new ODataPath(), new HttpRequestMessage());
// Assert
pathTemplateHandler.VerifyAll();
Assert.NotNull(convention.AttributeMappings);
Assert.Equal("GetCustomers", convention.AttributeMappings[pathTemplate].ActionName);
}
示例5: NoDescription_OnAttributeRoutedAction_UsingStandardControllerRoute
public void NoDescription_OnAttributeRoutedAction_UsingStandardControllerRoute()
{
HttpConfiguration config = new HttpConfiguration();
var route = config.Routes.MapHttpRoute("Default", "api/someController", new { controller = "DefaultRoute" });
config.MapHttpAttributeRoutes();
DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(DefaultRouteController));
config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);
config.EnsureInitialized();
IApiExplorer explorer = config.Services.GetApiExplorer();
Assert.True(explorer.ApiDescriptions.All(d => d.Route != route));
}