2

Using the local development web server (Cassini) in Visual Studio 2012 I receive consistent 404 Not Found responses from an HttpClient during unit test execution. Hitting the same local URI in fiddler (or another REST client) produces a 200 OK response with the JSON I expected.

Any idea's why VS2012 would give different results? All of this testing is pointed to localhost until I can figure this out.

    [TestCategory("Cat 1")]
    [TestMethod]
    public void SomeTestMethod()
    {
        string id = "00000012";
        var client = new HttpClient( _server );

        var request = new HttpRequestMessage();
        request.RequestUri = new Uri( String.Format("http://localhost:1234/api/GetDataById/{0}", id));
        request.Headers.Add( "apikey", "somekey" );
        request.Method = HttpMethod.Get;

        using ( HttpResponseMessage response = client.SendAsync( request ).Result ) {
            Assert.IsNotNull( response.Content );
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual( "application/json", response.Content.Headers.ContentType.MediaType );
        }

        request.Dispose();
    }
4

0 回答 0