当前位置: 首页>>代码示例>>C#>>正文


C# IUserAuthRepository.TryAuthenticate方法代码示例

本文整理汇总了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);
        }
开发者ID:nstjelja,项目名称:ServiceStack,代码行数:39,代码来源:OAuthUserSessionTests.cs

示例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);
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:50,代码来源:OAuthUserSessionTests.cs


注:本文中的IUserAuthRepository.TryAuthenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。