How to check User Control with a block that relies on the Session object

I am using ASP.NET to build an application and the latest version of the NUNIT framework to test it. I am creating a custom control to create a custom menu. This control at some point checks for the presence of a specific object in the session collection or not adding some items to the menu.

The exact functionality it provides is this: if the registered user is a regular user, it displays a regular set of links, if the registered user is an administrator, it adds additional links to the already displayed links. Management is working properly.

My problem:
I want to take control outside of the web application and test it separately as part of NUNIT testing. My only problem is that it relies on the existence of the Session object. I don't know how to simulate it inside the nunit test method, if possible or there are alternative solutions that I haven't thought of.

+1


source to share


1 answer


You will need a border stroke in the right direction, but you can make it mock the http context .

I tend to have operations like this done in a custom class that I can more easily mock.



Alternatively, you can probably use mstest web tests to achieve the same results.

+2


source







All Articles