Say you have a profile page that only the owner of this profile can access. This profile page is located at:
User / Profile / {} user ID
Now, I suppose, to prevent other users from accessing this page, you can structure your UserController profile profile function to check the current session ID:
HttpContext.Current.User.Identity.Name
If the identifier matches the identifier in the URL, you continue. Otherwise, you are redirected to some kind of error page.
My question is: how do you unit test something like this? I assume that you need to use some kind of dependency injection instead of the HttpContext in the controller to check, but I do not quite understand what the best way to do this. Any advice would be helpful.
tdd asp.net-mvc
Kevin pang
source share