public void RegisterExistingUser() { var mock = new Mock<IUserRepository>(); //mock.Setup(r => r.) var service = new UserAccountService(mock.Object); Assert.IsNotNull(service.Register("newLogin123", "Password123")); }
public void LogOnWithInvalidLoginReturnsNull() { var mock = new Mock<IUserRepository>(); mock.Setup(r => r.GetUser("12345678")) .Returns(new UserModel() { Id = 1, Login = "******", Password = "******", }); var service = new UserAccountService(mock.Object); Assert.IsNull(service.LogOn("invalidPass", "87654321")); }
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { if (FormsAuthentication.CookiesSupported) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { IUserAccountService accountService = new UserAccountService(new UserRepository()); string login = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; var userModel = accountService.GetUser(login); //HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(username, "Forms"), roles.Split(';')); HttpContext.Current.User = new CustomPrincipal(userModel); } catch (Exception) { //somehting went wrong } } } }
public void CreateUserAccountServiceObject() { var mock = new Mock<IUserRepository>(); var service = new UserAccountService(mock.Object); }