Создайте метод в вашем классе, например
public class SomeClass{
public static void main(String[] args) {
LocalDateTime now = getCurrentLocalDateTime();
System.out.println(now);
}
private LocalDateTime getCurrentLocalDateTime() {
return LocalDateTime.now();
}
}
И в тестовом классе вы используете
@PrepareForTest(SomeClass.class)
@RunWith(PowerMockRunner.class)
В TestCase
LocalDateTime tommorow= LocalDateTime.now().plusDays(1);
SomeClass classUnderTest = PowerMockito.spy(new SomeClass());
PowerMockito.when(classUnderTest, "getCurrentLocalDateTime").thenReturn(tommorow);
После того, как проверка успешна, необходимо войти в систему пользователь путем вызова FormsAuthentication. Пройдите проверку подлинности: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx
Править: Это - FormsAuthentication. SetAuthCookie: http://msdn.microsoft.com/en-us/library/twk5762b.aspx
Кроме того, для перенаправления пользователя назад, где он хотел пойти звоните: FormsAuthentication. RedirectFromLoginPage: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirectfromloginpage.aspx
Можно установить собственное FormsAuthenticationTicket
если проверка успешна.
Что-то вроде этого;
if (provider != null) {
if (provider.ValidateUser(ticket)) {
// Login Success
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1, //version
someUserName, //name
DateTime.Now, //issue date
DateTime.Now.AddMinutes(lengthOfSession), //expiration
false, // persistence of login
FormsAuthentication.FormsCookiePath
);
//encrypt the ticket
string hash = FormsAuthentication.Encrypt(authTicket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
Response.Cookies.Add(cookie);
Response.Redirect(url where you want the user to land);
} else {
// Login Fail
}
}