/// <summary>
        /// In Unit tests I have no context and have no session
        /// so I have to create it manually
        /// Now you can get session this way
        /// HttpContext.Current.Session
        /// </summary>
        public void CreateHttpSessionTest()
        {
            HttpContext.Current = new HttpContext(new HttpRequest
(string.Empty,
 
"http://localhost/";,
 
string.Empty),
                                                  new HttpResponse(new
StringWriter()));

            IHttpSessionState iSessState = new
HttpSessionStateContainer(string.Empty,
 
new SessionStateItemCollection(),
 
new HttpStaticObjectsCollection(),
 
20000,
 
true,
 
HttpCookieMode.UseCookies,
 
SessionStateMode.Off,
 
false);
            SessionStateUtility.AddHttpSessionStateToContext(
                HttpContext.Current,
                iSessState);
            Assert.IsNotNull(HttpContext.Current.Session);
            Assert.IsNotNull(HttpContext.Current.Cache);
        }




On 28 авг, 10:00, TheMightyKumquat <[email protected]> wrote:
> I'm running a lot of unit tests on a class inheriting from another
> class, where the base class' methods make a lot of calls involving
> HttpContext.Current.Session. When unit tests run, of course, they
> fail, because there is no HttpContext when the test is executed by the
> Visual Studio IDE.
>
> I've done a bit of Googling for a workaround and found a couple of
> things - something called HttpSimulator and also a Scott Hanselman
> blog page that discussed trying to simulate Session using Rhino Mocks,
> but I don't really understand the usage of either. Does anyone have
> experience trying to deal with Session in unit tests, and is there a
> "best practice" solution involving Rhino Mocks? I'd love to hear
> everyone's input.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to