public async Task CreateSimpleHttpServer_RoutingWithHttpAttributes_RoutedMiddleware() { var httpServer = new OwinHttpServer(new UriBuilder("http://localhost:5000/")); var container = new SimpleInjector.Container(); var resetEvent = new ManualResetEventSlim(); RegisterManualResetEvent(ref container, resetEvent); httpServer.AddDependencyResolver(() => new SimpleInjectorWebApiDependencyResolver(container)) .SetHttpRouteAttributes() .AddMiddleware((iocResolver) => { var _resetEvent = iocResolver.GetService(typeof(ManualResetEventSlim)); return(new OwinMiddlewareRegistration(typeof(TestOwinMiddleware), new object[] { _resetEvent }, "/WebSockets")); }); HttpClient client = CreateHttpClient(CreateTestServer(httpServer)); client.BaseAddress = new Uri("http://localhost"); var result = await client.GetAsync($"/WebSockets/"); resetEvent.Wait(); Assert.Equal(HttpStatusCode.Redirect, result.StatusCode); }
public async Task CreateSimpleHttpServer_RoutingWithHttpAttributes_ReplaceService() { using (var httpServer = new OwinHttpServer(new UriBuilder("http://localhost:5001/"))) { var container = new SimpleInjector.Container(); var resetEvent = new ManualResetEventSlim(); RegisterExceptionLogger(ref container, resetEvent); httpServer.AddDependencyResolver(() => new SimpleInjectorWebApiDependencyResolver(container)) .SetHttpRouteAttributes() .ReplaceService <IExceptionLogger>((serviceResolver) => { IExceptionLogger exceptionLogger = serviceResolver.GetService(typeof(IExceptionLogger)) as IExceptionLogger; return(exceptionLogger); }).TryStart(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:5001/"); var result = await client.GetAsync($"/Device/state/{1}?active=false"); resetEvent.Wait(); Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode); } }
public async Task CreateSimpleHttpServer_RoutingWithExplicitRoutes_RequestDefaultRoute() { var httpServer = new OwinHttpServer(new UriBuilder("http://localhost:5000/")); httpServer.AddDependencyResolver(() => new SimpleInjectorWebApiDependencyResolver(new SimpleInjector.Container())) .MapRoutes("GetState", "{controller}/{action}/{id}", new { controller = nameof(ManagementController), action = "GetState", id = RouteParameter.Optional }); HttpClient client = CreateHttpClient(CreateTestServer(httpServer)); client.BaseAddress = new Uri("http://localhost"); var result = await client.GetAsync($"/Management/GetState/{1}"); Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
public async Task CreateSimpleHttpServer_RoutingWithHttpAttributes() { var httpServer = new OwinHttpServer(new UriBuilder("http://localhost:5000/")); httpServer.AddDependencyResolver(() => new SimpleInjectorWebApiDependencyResolver(new SimpleInjector.Container())) .SetHttpRouteAttributes(); HttpClient client = CreateHttpClient(CreateTestServer(httpServer)); client.BaseAddress = new Uri("http://localhost"); var result = await client.GetAsync($"/Device/state/{1}?active="); Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
public async Task CreateSimpleHttpServer_RoutingWithHttpAttributes_FilterExceptions() { var httpServer = new OwinHttpServer(new UriBuilder("http://localhost:5000/")); httpServer.AddDependencyResolver(() => new SimpleInjectorWebApiDependencyResolver(new SimpleInjector.Container())) .SetHttpRouteAttributes() .AddFilter((filterCollection, serviceProvider) => { filterCollection.Add(new PlatformExceptionFilter()); }); HttpClient client = CreateHttpClient(CreateTestServer(httpServer)); client.BaseAddress = new Uri("http://localhost"); var result = await client.GetAsync($"/Device/state/{1}?active=false"); Assert.Equal(HttpStatusCode.Conflict, result.StatusCode); }