Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting ServiceStack services with custom factory
    primarykey
    data
    text
    <p>I have read excellent article <a href="http://www.richardfawcett.net/2012/02/29/accessing-asp-net-session-from-servicestack/" rel="nofollow">here</a> about accessing ASP.NET session from ServiceStack. </p> <p>It seems to work great, but I don't know how to make a "passing" UT (Nunit) for services which need direct acces to HttpContext, because Nunit does not use Web.config with my custom factory configuration, and cannot create my custom factory.</p> <pre><code>&lt;httpHandlers&gt; &lt;add path="api*" type="SomeNamespace.SessionHttpHandlerFactory" verb="*" /&gt; &lt;/httpHandlers&gt; </code></pre> <p>So, I have a null reference at HttpContext.Current</p> <pre><code>class SomeService : RestServiceBase&lt;SomeDto&gt; { public override object OnGet(SomeDto request) { var context = HttpContext.Current; return something; } IRequestContext RequestContext { get; set; } } </code></pre> <p>I've tried also to mock a session in this way, but still not works</p> <pre><code> HttpWorkerRequest _wr = new SimpleWorkerRequest("/dummyWorkerRequest", @"c:\inetpub\wwwroot\dummy", "default.aspx", null, new StringWriter()); HttpContext.Current = new HttpContext(_wr); HttpSessionStateContainer sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false); SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, sessionContainer); </code></pre> <p>How can I create my custom factory in UT?</p> <p>Sorry for bad english.</p>
    singulars
    1. This table or related slice is empty.
    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