public void HandleRequest(WebhookModel model)
{
var strRequest = "cmd=_notify-validate&" + ipnContext.RequestBody;
var webRequest = FormRequest(strRequest);
var requestStream = _webRequestWrapper.GetRequestStream();
var responseStream = _webRequestWrapper.GetResponse().GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream))
{
model.Verification = reader.ReadToEnd();
}
}
private WebRequest FormRequest(string strRequest)
{
var webRequest = WebRequest.Create("some url is over here");
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = strRequest.Length;
return webRequest;
}
Where _webrequestWrapper just a wrapper around WebRequest class. So, my question is how i can mock _webRequestWrapper.GetResponse().GetResponseStream()? The problem is that there is no problems with mocking GetResponse() cause of we create for it wrapper around WebRequest. But the problem is with GetReponseStream, because it returns a Strem object, how i can test HandleRequest() method? I really haven't any ideas about it. Please help me. Thanks
Aucun commentaire:
Enregistrer un commentaire