当前位置: 首页>>代码示例>>C#>>正文


C# HttpConfiguration.EnsureInitialized方法代码示例

本文整理汇总了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);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:35,代码来源:AttributeRoutingTest.cs

示例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);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:12,代码来源:AttributeRoutesTest.cs

示例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);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:13,代码来源:AttributeRoutesTest.cs

示例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);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:21,代码来源:AttributeRoutingConventionTest.cs

示例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));
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:13,代码来源:AttributeRoutesTest.cs


注:本文中的HttpConfiguration.EnsureInitialized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。