public async Task Given_Valid_Request_And_Remote_Server_Listening_When_Sending_Then_Remote_Accepts() { var messageReceivedEvent = new ManualResetEvent(false); string content = null; var serverBaseUri = new UriBuilder { Scheme = "http", Host = "localhost", Port = 52180, Path = "/platibus.test/" }.Uri; var configuration = new HttpServerConfiguration { BaseUri = serverBaseUri }; configuration.AddHandlingRule<string>(".*", (c, ctx) => { content = c; messageReceivedEvent.Set(); ctx.Acknowledge(); }); bool messageReceived; using (var server = await HttpServer.Start(configuration)) { var endpoint = serverBaseUri; var message = new Message(new MessageHeaders { {HeaderName.ContentType, "text/plain"}, {HeaderName.MessageId, Guid.NewGuid().ToString()}, {HeaderName.Destination, endpoint.ToString()}, {HeaderName.MessageName, typeof (string).FullName}, }, "Hello, world!"); var transportService = await server.GetTransportService(); await transportService.SendMessage(message); messageReceived = await messageReceivedEvent .WaitOneAsync(TimeSpan.FromSeconds(3)); } // Sanity check. We're really testing the transport to ensure // that it doesn't throw. But if it does throw, then it would // be nice to get some info about how the server behaved. Assert.That(messageReceived, Is.True); Assert.That(content, Is.EqualTo("Hello, world!")); }
private static async Task <HttpServer> StartAsync( string configSectionName, Func <HttpServerConfiguration, Task> configure, CancellationToken cancellationToken = default(CancellationToken)) { var configManager = new HttpServerConfigurationManager(); var configuration = new HttpServerConfiguration(); await configManager.Initialize(configuration, configSectionName); #pragma warning disable 612 await configManager.FindAndProcessConfigurationHooks(configuration); #pragma warning restore 612 if (configure != null) { await configure(configuration); } var server = await StartAsync(configuration, cancellationToken); return(server); }