0

I have an MVC controller, that take JSON from the input stream. Since the type of data varies I can't just set the data as a parameter to the function.

In the unit tests, I do I set the request.inputstream?

public class ApiController : Controller
{
    public async Task<JsonResult> Log()
    {
        var data = new System.IO.StreamReader(Request.InputStream).ReadToEnd()
        var value = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.MyClass>(input);
    }
}

[TestMethod()]
public void LogTest()
{
    var controller = new ApiController();
    // need to inject JSON code request.input stream???
    var result = controller.Log();
    result.Wait();
    Assert.AreEqual(((dynamic)result.Result.Data).success, true);
}
John Hughes
  • 367
  • 1
  • 3
  • 20

1 Answers1

0

You can't set Request.InputStream manually. It is getter only. https://msdn.microsoft.com/en-us/library/system.web.httprequest.inputstream(v=vs.110).aspx

M_Idrees
  • 2,080
  • 2
  • 23
  • 53