本文整理汇总了C#中IUserAuthRepository.TryAuthenticate方法的典型用法代码示例。如果您正苦于以下问题:C# IUserAuthRepository.TryAuthenticate方法的具体用法?C# IUserAuthRepository.TryAuthenticate怎么用?C# IUserAuthRepository.TryAuthenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserAuthRepository
的用法示例。
在下文中一共展示了IUserAuthRepository.TryAuthenticate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_login_with_user_created_CreateUserAuth
public void Can_login_with_user_created_CreateUserAuth(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
var registrationService = GetRegistrationService(userAuthRepository);
var responseObj = registrationService.Post(registrationDto);
var httpResult = responseObj as IHttpResult;
if (httpResult != null)
{
Assert.Fail("HttpResult found: " + httpResult.Dump());
}
var response = (RegistrationResponse)responseObj;
Assert.That(response.UserId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(response.UserId);
AssertEqual(userAuth, registrationDto);
userAuth = userAuthRepository.GetUserAuthByUserName(registrationDto.UserName);
AssertEqual(userAuth, registrationDto);
userAuth = userAuthRepository.GetUserAuthByUserName(registrationDto.Email);
AssertEqual(userAuth, registrationDto);
UserAuth userId;
var success = userAuthRepository.TryAuthenticate(registrationDto.UserName, registrationDto.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(registrationDto.Email, registrationDto.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(registrationDto.UserName, "Bad Password", out userId);
Assert.That(success, Is.False);
Assert.That(userId, Is.Null);
}
示例2: Can_login_with_user_created_CreateUserAuth
public void Can_login_with_user_created_CreateUserAuth(IUserAuthRepository userAuthRepository)
{
((IClearable)userAuthRepository).Clear();
var request = new Registration {
UserName = "UserName",
Password = "[email protected]",
Email = "[email protected]",
DisplayName = "DisplayName",
FirstName = "FirstName",
LastName = "LastName",
};
var loginService = new RegistrationService {
UserAuthRepo = userAuthRepository,
RegistrationValidator = new RegistrationValidator { UserAuthRepo = RegistrationServiceTests.GetStubRepo() },
};
var responseObj = loginService.Post(request);
var httpResult = responseObj as IHttpResult;
if (httpResult != null)
{
Assert.Fail("HttpResult found: " + httpResult.Dump());
}
var response = (RegistrationResponse)responseObj;
Assert.That(response.UserId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(response.UserId);
AssertEqual(userAuth, request);
userAuth = userAuthRepository.GetUserAuthByUserName(request.UserName);
AssertEqual(userAuth, request);
userAuth = userAuthRepository.GetUserAuthByUserName(request.Email);
AssertEqual(userAuth, request);
string userId;
var success = userAuthRepository.TryAuthenticate(request.UserName, request.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(request.Email, request.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(request.UserName, "Bad Password", out userId);
Assert.That(success, Is.False);
Assert.That(userId, Is.Null);
}