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 MockRequestContext LoggedInContext()
        {
            var mockRequestContext = new MockRequestContext();
            var httpReq            = (MockHttpRequest)mockRequestContext.Get <IHttpRequest>();

            httpReq.RemoteIp = "86.131.235.233, 127.0.0.1";
            var httpRes         = mockRequestContext.Get <IHttpResponse>();
            var authUserSession = mockRequestContext.ReloadSession();

            authUserSession.Id = httpRes.CreateSessionId(httpReq);
            authUserSession.IsAuthenticated = true;
            authUserSession.ProviderOAuthAccess.Add(new OAuthTokens {
                AccessToken = FakeUserData.FakeAccessToken.Token, AccessTokenSecret = FakeUserData.FakeAccessToken.Secret
            });
            httpReq.Items[ServiceExtensions.RequestItemsSessionKey] = authUserSession;
            return(mockRequestContext);
        }