Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In ASP.NET, you can't create a Test Double of HttpSessionState because it is <code>sealed</code>. Yes, this is bad design on the part of the original designers of ASP.NET, but there's not a lot to do about it.</p> <p>This is one of many reasons why TDD'ers and other SOLID practictioners have largely abandonded ASP.NET in favor of ASP.NET MVC and other, more testable frameworks. In ASP.NET MVC, the HTTP session is modelled by the abstract HttpSessionStateBase class.</p> <p>You could take a similar approach and let your objects work on an abstract session, and then wrap the real HttpSessionState class when you are running in the ASP.NET environment. Depending on circumstances, you may even be able to reuse the types from System.Web.Abstractions, but if not, you can define your own.</p> <p>In any case, your business logic is your <strong>Domain Model</strong> and it should be modeled independently of any particular run-time technology, so I would say that it shouldn't be accessing the session object in the first place.</p> <p>If you absolutely need to use Test Doubles for unit tets involving HttpSessionState, this is still possible with certain invasive dynamic mocks, such as <a href="http://site.typemock.com/" rel="nofollow noreferrer">TypeMock</a> or <a href="http://research.microsoft.com/en-us/projects/moles/" rel="nofollow noreferrer">Moles</a>, althought these carry plenty of disadvantages as well (see <a href="https://stackoverflow.com/questions/1718463/what-are-the-real-world-pros-and-cons-of-each-of-the-major-mocking-frameworks/1720654#1720654">this comparison of dynamic mocks</a>).</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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