Last active
December 11, 2015 04:39
-
-
Save damianh/4547106 to your computer and use it in GitHub Desktop.
WebApplication.Start suggestion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } |
Author
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
In the second sample, I assume you still need to pass
new OwinHttpMessageHandler(webApp.AppFunc)to theHttpClientconstructor?Very nice, by the way!