unit testing - How to write nunit test for ASP.NET Identity in Web Forms? -
i've written (single-tier) asp.net web forms (please note not mvc application) application uses identity model authentication. vs solution consists of web forms project , unit test project. i've added nunit packages unit test project via nuget.
i've been trying find example unit tests login function i've failed so. please point me in correct direction giving me sample/tutorial or providing me guidance on doing so?
p.s. - i'm not familiar writing unit tests.
update 1
meant i'm not familiar writing them in context (using nunit , identity on single tier web forms application). familiar concept , have written few in past java. sorry misunderstanding.
update 2
i've managed write test method test log in functionality. following method i'm attempting test:
public bool loginasuser(string username, string password) { bool issuccessful = false; // validate user password var manager = context.getowincontext().getusermanager<applicationusermanager>(); applicationuser user = manager.find(username, password); if (user != null) { identityhelper.signin(manager, user, rememberme.checked); issuccessful = true; } else { issuccessful = false; } return issuccessful; }
the following test method:
[test] public void testmethod1() { var wrapper = new httpcontextwrapper(httpcontext.current); mock mockcontext = new mock<httpcontextbase>(); login login = new login(); string username = "admin"; string password = "password"; bool flag = login.loginasuser(username, password); assert.istrue(flag, "login in failed user: [" + username + "]"); }
however when come line
var manager = context.getowincontext().getusermanager<applicationusermanager>();
a nullreferenceexception thrown since context null.
any advice on how fix this?
Comments
Post a Comment