hibri / HttpMock

A library for creating Http servers on the fly in tests and stubbing responses
MIT License
128 stars 44 forks source link

RequestHandler.LastRequest() returns a truncated RecievedRequest body #28

Closed stevenao closed 9 years ago

stevenao commented 9 years ago

I am setting a json in the body. I want to check the received request body. I see that the body is truncated.

hibri commented 9 years ago

@stevenao Thanks for reporting this. Would you be able to send me a test to reproduce the issue ? Or the tests you are writing

stevenao commented 9 years ago

@hibri Sure. I have added a test in the HttpEndPointTests.cs

[TestCase(1)]       
[TestCase(100)]     
[TestCase(5000)]        
public void SUT_should_get_back_exact_content_in_the_last_request_body(int count) {
    _stubHttp = HttpMockRepository.At( _hostUrl );

    string expected = string.Format( "<xml><>response>{0}</response></xml>", string.Join( " ", Enumerable.Range( 0, count ) ) );
    var requestHandler = _stubHttp.Stub( x => x.Post( "/endpoint" ) );

    requestHandler.Return( expected ).OK();

    Console.WriteLine( _stubHttp.WhatDoIHave() );

    using( var wc = new WebClient() ) {
        wc.Headers[HttpRequestHeader.ContentType] = "application/xml";
        var htmlResult = wc.UploadString( string.Format( "{0}/endpoint", _hostUrl ), expected );
    }
    var requestBody = requestHandler.LastRequest().Body;

    Assert.That( requestBody, Is.EqualTo(expected));
}      
hibri commented 9 years ago

@stevenao Pushed a new version with a fix for this. It's in 1.1.6