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); }
TestServer CreateTestServer(OwinHttpServer httpServer) { return(TestServer.Create(builder => { httpServer.Build(builder); })); }
public RavenDbServer Initialize(Action <RavenDBOptions> configure = null) { if (configuration.IgnoreSslCertificateErrors == IgnoreSslCertificateErrorsMode.All) { // we ignore either all or none at the moment ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; } BooleanQuery.MaxClauseCount = configuration.MaxClauseCount; BooleanQuery.MaxClauseCount = configuration.MaxClauseCount; owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure); options = owinHttpServer.Options; serverThingsForTests = new ServerThingsForTests(options); Func <HttpMessageHandler> httpMessageHandlerFactory = () => new OwinClientHandler(owinHttpServer.Invoke, options.SystemDatabase.Configuration.EnableResponseLoggingForEmbeddedDatabases); documentStore.HttpMessageHandlerFactory = httpMessageHandlerFactory; documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; documentStore.Initialize(); filesStore.HttpMessageHandlerFactory = httpMessageHandlerFactory; filesStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; filesStore.Initialize(); return(this); }
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 static void WaitForUserToContinueTheTest(IDocumentStore documentStore, bool debug = true, int port = 8079) { if (debug && Debugger.IsAttached == false) { return; } var embeddableDocumentStore = documentStore as EmbeddableDocumentStore; OwinHttpServer server = null; string url = documentStore.Url; if (embeddableDocumentStore != null) { embeddableDocumentStore.Configuration.Port = port; SetStudioConfigToAllowSingleDb(embeddableDocumentStore); embeddableDocumentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.Admin; NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); server = new OwinHttpServer(embeddableDocumentStore.Configuration, embeddableDocumentStore.DocumentDatabase); url = embeddableDocumentStore.Configuration.ServerUrl; } using (server) { Process.Start(url); // start the server do { Thread.Sleep(100); } while (documentStore.DatabaseCommands.Head("Debug/Done") == null && (debug == false || Debugger.IsAttached)); } }
public RavenDbServer Initialize(Action <RavenDBOptions> configure = null) { if (configuration.IgnoreSslCertificateErros == IgnoreSslCertificateErrorsMode.All) { // we ignore either all or none at the moment ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; } owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure); options = owinHttpServer.Options; serverThingsForTests = new ServerThingsForTests(options); documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke, options.SystemDatabase.Configuration.EnableResponseLoggingForEmbeddedDatabases); documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; documentStore.Initialize(); filesStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke, options.SystemDatabase.Configuration.EnableResponseLoggingForEmbeddedDatabases); filesStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; filesStore.Initialize(); serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); task.Execute(this); } return(this); }
public RavenDbServer Initialize(Action <RavenDBOptions> configure = null) { owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure); options = owinHttpServer.Options; serverThingsForTests = new ServerThingsForTests(options); documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke); documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; documentStore.Initialize(); return(this); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { var endpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint("RestEndpoint"); var fabricBrsSecuritySetting = SecuritySetting.GetClusterSecurityDetails(); var listeningAddress = String.Format(CultureInfo.InvariantCulture, "{0}://+:{1}/", fabricBrsSecuritySetting.EndpointProtocol, endpoint.Port); var publishUri = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); this.owinHttpServer = new OwinHttpServer(this.statefulService, fabricBrsSecuritySetting, cancellationToken); this.owinHttpServer.StartOwinHttpServer(listeningAddress); return(Task.FromResult(publishUri)); }
protected static void WaitForUserToContinueTheTest(IDocumentStore documentStore, bool debug = true, int port = 8079) { if (debug && Debugger.IsAttached == false) { return; } var databaseName = Constants.SystemDatabase; var embeddableDocumentStore = documentStore as EmbeddableDocumentStore; OwinHttpServer server = null; string url = documentStore.Url; if (embeddableDocumentStore != null) { databaseName = embeddableDocumentStore.DefaultDatabase; embeddableDocumentStore.Configuration.Port = port; SetStudioConfigToAllowSingleDb(embeddableDocumentStore); embeddableDocumentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.Admin; NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); server = new OwinHttpServer(embeddableDocumentStore.Configuration, embeddableDocumentStore.DocumentDatabase); url = embeddableDocumentStore.Configuration.ServerUrl; } var remoteDocumentStore = documentStore as DocumentStore; if (remoteDocumentStore != null) { databaseName = remoteDocumentStore.DefaultDatabase; } using (server) { try { var databaseNameEncoded = Uri.EscapeDataString(databaseName ?? Constants.SystemDatabase); var documentsPage = url + "studio/index.html#databases/documents?&database=" + databaseNameEncoded + "&withStop=true"; Process.Start(documentsPage); // start the server } catch (Win32Exception e) { Console.WriteLine("Failed to open the browser. Please open it manually at {0}. {1}", url, e); } do { Thread.Sleep(100); } while (documentStore.DatabaseCommands.Head("Debug/Done") == null && (debug == false || Debugger.IsAttached)); } }
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); }
public static void WaitForUserToContinueTheTest(DocumentStore documentStore, bool debug = true, int port = 8079) { if (debug && Debugger.IsAttached == false) { return; } OwinHttpServer server = null; string url = documentStore.Url; using (server) { Process.Start(url); // start the server do { Thread.Sleep(100); } while (documentStore.DatabaseCommands.Head("Debug/Done") == null && (debug == false || Debugger.IsAttached)); } }
public RavenDbServer Initialize(Action <RavenDBOptions> configure = null) { owinHttpServer = new OwinHttpServer(configuration, useHttpServer: UseEmbeddedHttpServer, configure: configure); options = owinHttpServer.Options; serverThingsForTests = new ServerThingsForTests(options); documentStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke); documentStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; documentStore.Initialize(); filesStore.HttpMessageHandler = new OwinClientHandler(owinHttpServer.Invoke); filesStore.Url = string.IsNullOrWhiteSpace(Url) ? "http://localhost" : Url; filesStore.Initialize(); foreach (var task in configuration.Container.GetExportedValues <IServerStartupTask>()) { task.Execute(this); } return(this); }
public static void WaitForUserToContinueTheTest(DocumentStore documentStore, bool debug = true, int port = 8079) { if (debug && Debugger.IsAttached == false) { return; } OwinHttpServer server = null; string url = documentStore.Url; using (server) { var databaseNameEncoded = Uri.EscapeDataString(documentStore.DefaultDatabase ?? Constants.SystemDatabase); var documentsPage = url + "/studio/index.html#databases/documents?&database=" + databaseNameEncoded + "&withStop=true"; Process.Start(documentsPage); // start the server do { Thread.Sleep(100); } while (documentStore.DatabaseCommands.Head("Debug/Done") == null && (debug == false || Debugger.IsAttached)); } }