PayPal have provided example code how to receive a notification of a purchase (or similar). Sadly, I don't see a way to manually test this and I'm struggling to see how to replicate Microsoft.AspNetCore.Http HttpRequest
https://github.com/paypal/ipn-code-samples/tree/master/C%23
The relevant part of the code is
[HttpPost]
public IActionResult Receive()
{
IPNContext ipnContext = new IPNContext()
{
IPNRequest = Request //IPNRequest is HttpRequest
};
using (var reader = new StreamReader(ipnContext.IPNRequest.Body, Encoding.ASCII))
{
ipnContext.RequestBody = await reader.ReadToEndAsync();
}
//other code removed for this example
}
What I'd like to do is replicate request
so I can execute this from a test! Normally, I'd refactor the code so I can pass parameters to get around this issue (even if I pass in the rendered string).
In this instance, I want to pretend I can't touch the source code, but still need to test it. This is so I can learn more.
As the bit I am after is the stream
, as seen in ipnContext.IPNRequest.Body
, I'm stumped. If it's a stream, I can't assign it as a string, but when it does the ReadToEndAsync
, a string comes out!
How do I create the Request
object with a similar shape to what PayPal expects for Request.IPNRequest.Body