Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit testing an ASP.NET MVC 3 application
    primarykey
    data
    text
    <p>We have an ASP.NET WebForms application that we're going to convert to be ASP.NET MVC application - one of the reasons is so that we may take full advantage of Unit Testing and TDD.</p> <p>Our current WebForms application makes heavy use of HttpModules. We're currently debating whether we should stick with HttpModules or use Global Filters (any advice here would be great).</p> <p>However, with my few "hello world" test MVC applications, I've not worked out how to get the HttpModule (or indeed the Global Filter) code to fire when Unit testing.</p> <p>Maybe I'm wrong, but it seems to me that I need this to be part of my unit-testing (integration testing) otherwise it can't be a true representation of what's going on in my Production code.</p> <p>Any guidance would be most welcome.</p> <p>Thanks</p> <p>Griff</p> <p>PS - I added the following after the initial responses to my question.</p> <p><strong>Simple made-up Use Case</strong></p> <p><em>In Production</em></p> <ol> <li>Browser makes a Request for a Controller Method</li> <li>HttpModule fires (or Global Filter) - this sets a static Guid property to have a value.</li> <li>The controller method takes this Guid value and uses it in its subsequent logic</li> <li>Correct result is then returned to the browser</li> </ol> <p><em>In Unit Testing</em></p> <ol> <li>Unit test calls the same Controller Method</li> <li>The HttpModule (or Global Filter) does not fire - the static Guid property has a value of Guid.Empty</li> <li>The controller method takes this Guid value, but throws an error because it was an Empty Guid</li> <li>Unit test fails</li> </ol> <p><em>My thoughts are</em>:</p> <ul> <li>if a Controller relies upon an HttpModule (or Global Filter) to run first, then the HttpModule is a dependency and therefore the results of it's action must be Stubbed for the test to be a true <em>Unit</em> Test. </li> <li>If the test is to include the effect of the HttpModule (or Global Filter) to run, then this would be an <em>Integration</em> test (though it's still not clear yet how to get the HttpModule or Global Filter to run as part of the Integration test)</li> <li>The HttpModule (or Global Filter) should have their own set of Unit Tests</li> </ul> <p>I think this is the approach I'll take, but if anyone could suggest how I get my Integration test (as described above) to work then I'd be most grateful. </p> <p>The problem as I see it is that my TEST project becomes the "start up" project when running my tests, so the HttpModules (defined in the ASP.NET MVC's web.config file) and the Global Filters (defined in the ASP.NET MVC's global.asax file) will not run because the web.config and global.asax files are not executed. So the question remains: how do I get these to run in my Integration test?</p> <p>Thanks everyone</p> <p>Griff</p>
    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.
 

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