GetStubRepo() public static method

public static GetStubRepo ( ) : IUserAuthRepository
return IUserAuthRepository
示例#1
0
        public void Can_login_with_user_created_CreateUserAuth(IUserAuthRepository userAuthRepository)
        {
            ((IClearable)userAuthRepository).Clear();

            var request = new Registration {
                UserName    = "******",
                Password    = "******",
                Email       = "*****@*****.**",
                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);
        }
        public static RegistrationService GetRegistrationService(
            IUserAuthRepository userAuthRepository,
            AuthUserSession oAuthUserSession  = null,
            MockRequestContext requestContext = null)
        {
            if (requestContext == null)
            {
                requestContext = new MockRequestContext();
            }
            if (oAuthUserSession == null)
            {
                oAuthUserSession = requestContext.ReloadSession();
            }

            var httpReq = requestContext.Get <IHttpRequest>();
            var httpRes = requestContext.Get <IHttpResponse>();

            oAuthUserSession.Id = httpRes.CreateSessionId(httpReq);
            httpReq.Items[ServiceExtensions.RequestItemsSessionKey] = oAuthUserSession;

            var mockAppHost = new BasicAppHost {
                Container = requestContext.Container
            };

            requestContext.Container.Register(userAuthRepository);

            var authService = new AuthService {
                RequestContext = requestContext,
            };

            authService.SetAppHost(mockAppHost);
            mockAppHost.Register(authService);

            var registrationService = new RegistrationService {
                UserAuthRepo          = userAuthRepository,
                RequestContext        = requestContext,
                RegistrationValidator =
                    new RegistrationValidator {
                    UserAuthRepo = RegistrationServiceTests.GetStubRepo()
                },
            };

            registrationService.SetAppHost(mockAppHost);

            return(registrationService);
        }
        public static RegisterService GetRegistrationService(
            IUserAuthRepository userAuthRepository,
            AuthUserSession oAuthUserSession = null,
            BasicRequest request             = null)
        {
            if (request == null)
            {
                request = new BasicRequest();
            }
            if (oAuthUserSession == null)
            {
                oAuthUserSession = request.ReloadSession();
            }

            oAuthUserSession.Id = request.Response.CreateSessionId(request);
            request.Items[SessionFeature.RequestItemsSessionKey] = oAuthUserSession;

            var mockAppHost = new BasicAppHost();

            mockAppHost.Container.Register <IAuthRepository>(userAuthRepository);

            var authService = new AuthenticateService
            {
                Request = request,
            };

            authService.SetResolver(mockAppHost);
            mockAppHost.Register(authService);

            var registrationService = new RegisterService
            {
                AuthRepo = userAuthRepository,
                Request  = request,
                RegistrationValidator =
                    new RegistrationValidator {
                    UserAuthRepo = RegistrationServiceTests.GetStubRepo()
                },
            };

            registrationService.SetResolver(mockAppHost);

            return(registrationService);
        }