Created
February 29, 2012 16:19
-
-
Save cromwellryan/1942111 to your computer and use it in GitHub Desktop.
SelfHostWebApiTests
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
[TestFixture] | |
public class MyWebApiIntegrationTests | |
{ | |
[Test] | |
public void ShouldWorkWithWebApi4() | |
{ | |
var config = new HttpSelfHostConfiguration("http://localhost:8080"); | |
config.Routes.MapHttpRoute( | |
"Api", | |
"api/{controller}/{id}", | |
new { id = RouteParameter.Optional, folder = "" } | |
); | |
new HttpSelfHostServer(config) | |
.OpenAsync() | |
.ContinueWith(task => | |
{ | |
var request = WebRequest.Create("http://localhost:8080/api/Things"); | |
var response = request.GetResponse(); | |
var reader = new StreamReader(response.GetResponseStream()); | |
reader.ReadToEnd().Should().Contain("Boo"); | |
}) | |
.Wait(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you sure this code is doing what you expected? When I tried it with a base address of
http://in-memory
(an invalid address on my network), I got an error:This suggests to me that
WebRequest
is actually not communicating with your self-host server. I've been successfully usingHttpClient
andHttpRequestMessage
to work around this.