hibri / HttpMock

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

Get Body from the post and put method #102

Closed neiesc closed 5 years ago

neiesc commented 5 years ago

Is it possible to get Body from the post or put method?

hibri commented 5 years ago

Hi @neiesc, Can you give me a few more details on what you are trying to achieve?

neiesc commented 5 years ago

An example: image I would like to get the value of AcceptedWarnings in Return, type:

var acceptedWarnings = 0;
var _stubTaskServerApiHttp = HttpMockRepository.At($"http://localhost:3000");
_stubTaskServerApiHttp.Stub(x => x.Post($"/task_server/tasks"))
    .Return(() =>
    {
        acceptedWarnings = GetAcceptedWarnings();
        return @"
            {
                'status_code': 0,
                'message': 'Taks manager mocked by HttpMock, url /task_server/tasks',
                'task_id': '10'
            }";
    })
    .OK();
hibri commented 5 years ago

Post body is supported. See https://github.com/hibri/HttpMock/blob/master/src/HttpMock.Integration.Tests/HttpEndPointTests.cs#L61 Could you not construct the response body earlier?

neiesc commented 5 years ago

Cool, thanks!

Could you not construct the response body earlier?

I think, so.

neiesc commented 5 years ago

I tested it, LastRequest is getting the first request and not the last one. Is this expected? @hibri

hibri commented 5 years ago

That's not what is expected. Sounds like a bug. Can you create a new issue with the failing test please?

Thanks

neiesc commented 5 years ago

Can you create a new issue with the failing test please?

Of course.