Testing ASP.NET Session state part 2

After publishing the first example I thought I’d better show how to check the actual values in the cache too…
       
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("ValueInIndex").Args("IndexKey");
            string value = (string)page.Session["IndexKey"];
            Console.WriteLine(value);
            Console.ReadKey();
            MockManager.Verify();
            MockManager.ClearAll();
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s