Quantcast
Channel: IT Bytes » TypeMock
Viewing all articles
Browse latest Browse all 6

Testing ASP.NET session cache

$
0
0
I was asked how to test the ASP.NET Page.Session object. I’m sure there are many ways of doing it, but here is my quick console sample using TypeMock;

 static void Main(string[] args)
        {
            Page page = new Page();
            MockManager.Init();
            MockObject sessionMock = MockManager.MockObject(typeof(HttpSessionState));
            Mock pageMock = MockManager.MockAll(page.GetType());
            pageMock.ExpectGet("Session", sessionMock.Object);
            sessionMock.ExpectGetIndex("bert");
            string value = (string)page.Session["bert"];
            Console.ReadKey();
            MockManager.Verify();
            MockManager.ClearAll();
        }



Viewing all articles
Browse latest Browse all 6

Trending Articles