Skip to content

Instantly share code, notes, and snippets.

@damianh
Last active December 11, 2015 04:39
Show Gist options
  • Select an option

  • Save damianh/4547106 to your computer and use it in GitHub Desktop.

Select an option

Save damianh/4547106 to your computer and use it in GitHub Desktop.
WebApplication.Start suggestion
public interface IWebApplication : IDisposable
{
public Func<IDictionary<string, object>, Task> AppFunc { get; }
public string Url { get; }
}
// Start an app listen = false so that it is pure in-proc for testing.
using(IWebApplication webApp = WebApplication.Start(
builder => builder.UseThing(_foo),
listen: false))
{
var httpClient = new HttpClient(new OwinHttpMessageHandler(webApp.AppFunc));
httpClient.GetAsync("http://doesntmatter.com/");
}
// Alternatively use the network stack
using(IWebApplication webApp = WebApplication.Start(
builder => builder.UseThing(_foo),
url: "http://localhost:1234/"))
{
var httpClient = new HttpClient();
httpClient.GetAsync(webApp.Url);
}
@panesofglass
Copy link
Copy Markdown

In the second sample, I assume you still need to pass new OwinHttpMessageHandler(webApp.AppFunc) to the HttpClient constructor?

Very nice, by the way!

@damianh
Copy link
Copy Markdown
Author

damianh commented Jan 17, 2013

Cheers :)

Yes, you would. This would be in your test setup, not normal client usage though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment