Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like your controller does too much work. Try to abstract the json reader in another class, and inject it in the controller. That way you will have 2 independent tests - one for the reader itself, and another one for the controller, that it just calls the reader, w/o actually having to think abouit how the reader works.</p> <p>Something like this (pseudo code):</p> <pre><code>public interface IJsonReader { dynamic SqueezeJson(Stream stream); } public class JsonReader : IJsonReader { //implement SqeezeJson method } public class MyController { private readonly IJsonReader _jsonReader; public MyController(IJsonReader jsonReader) { _jsonReader = jsonReader; } public ActionResult Create() { var data = _jsonReader.SqeezeJson(Context.Request.InputStream); //... do wahtever needed } } // ... and the tests [Test] public void SqueezeJsonTest() { //test that the reader works as expected } public void ControllerTest() { //arrange var requestStream = Mock.Of&lt;Stream&gt;(); var request = Mock.Of&lt;HttpRequestBase&gt;( r =&gt; r.InputStream == requestStream &amp;&amp; r.Url == "http://whatever"); var context = Mock.Of&lt;HttpRequestBase&gt;(c=&gt;c.Request == request); dynamic sqeezedData = new ExpandoObject(); // populate with the expected data from reader var mockReader = new Mock&lt;IJsonReader&gt;(); mockReader.Setup(r=&gt;r.SqeezeJson(requestStream)).Returns(sqeezedData); var controller = new MyController(); controller.Context = context; //act var result = controller.Create(); //assert //whatever is needed to verify that the controller processed the sueezed data } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload