public void ApplyTo_Throws_IfCalledTwiceOnSameConfig() { var mobileAppConfig = new MobileAppConfiguration(); var config = new HttpConfiguration(); mobileAppConfig.ApplyTo(config); Assert.Throws<InvalidOperationException>(() => mobileAppConfig.ApplyTo(config)); }
public void ApplyTo_Throws_IfCalledTwiceOnSameConfig() { var mobileAppConfig = new MobileAppConfiguration(); var config = new HttpConfiguration(); mobileAppConfig.ApplyTo(config); Assert.Throws <InvalidOperationException>(() => mobileAppConfig.ApplyTo(config)); }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Configure Web API to use only bearer token authentication. config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var maConfig = new MobileAppConfiguration(); maConfig.ApplyTo(config); }
public void MapApiControllers_AppliesControllerExclusions() { // Arrange var typeList = new[] { typeof(Mobile1Controller), typeof(Mobile2Controller), typeof(Mobile3Controller) }; HttpConfiguration config = new HttpConfiguration(); SetupMockControllerList(config, typeList); // Act var mobileAppConfig = new MobileAppConfiguration() .MapApiControllers(); mobileAppConfig.AddBaseRouteExclusion("Mobile2"); // verify comparisons are case-insensitive mobileAppConfig.AddBaseRouteExclusion("MOBILE3"); mobileAppConfig.ApplyTo(config); // Assert Assert.Equal(1, config.Routes.Count); var route = config.Routes[0]; Assert.Equal("api/{controller}/{id}", route.RouteTemplate); Assert.Equal(1, route.Constraints.Count); var constraint = route.Constraints["controller"] as SetRouteConstraint <string>; Assert.NotNull(constraint); Assert.Equal(false, constraint.Excluded); Assert.Equal(new[] { "Mobile1" }, constraint.Set); }
public void MapApiControllers_AppliesControllerExclusions() { // Arrange var typeList = new[] { typeof(Mobile1Controller), typeof(Mobile2Controller), typeof(Mobile3Controller) }; HttpConfiguration config = new HttpConfiguration(); SetupMockControllerList(config, typeList); // Act var mobileAppConfig = new MobileAppConfiguration() .MapApiControllers(); mobileAppConfig.AddBaseRouteExclusion("Mobile2"); // verify comparisons are case-insensitive mobileAppConfig.AddBaseRouteExclusion("MOBILE3"); mobileAppConfig.ApplyTo(config); // Assert Assert.Equal(1, config.Routes.Count); var route = config.Routes[0]; Assert.Equal("api/{controller}/{id}", route.RouteTemplate); Assert.Equal(1, route.Constraints.Count); var constraint = route.Constraints["controller"] as SetRouteConstraint<string>; Assert.NotNull(constraint); Assert.Equal(false, constraint.Excluded); Assert.Equal(new[] { "Mobile1" }, constraint.Set); }
private TestServer CreateTestServer(IEnumerable<string> origins) { HttpConfiguration config = new HttpConfiguration(); MobileAppConfiguration mobileConfig = new MobileAppConfiguration(); CrossDomainController.Reset(); if (origins == null) { mobileConfig = mobileConfig.MapLegacyCrossDomainController(); } else { mobileConfig = mobileConfig.MapLegacyCrossDomainController(origins); } mobileConfig.ApplyTo(config); return TestServer.Create(appBuilder => { appBuilder.UseWebApi(config); }); }