Ejemplo n.º 1
0
            public void SetFixture(MockRepository mocks)
            {
                mockRepository        = mocks;
                DefaultProvider       = mocks.DynamicMock <IOAuthProvider>();
                DefaultcontextBuilder = mocks.DynamicMock <IOAuthContextBuilder>();
                var httpRequest     = mocks.DynamicMock <HttpRequestBase>();
                var httpContextMock = mocks.DynamicMock <HttpContextBase>();

                mockOAuthContext = mocks.DynamicMock <IOAuthContext>();
                DefaultcontextBuilder.Stub(contextBuilder => contextBuilder.FromHttpRequest(httpRequest)).Return(mockOAuthContext);
                DefaultProvider.Stub(provider => provider.ExchangeRequestTokenForAccessToken(mockOAuthContext)).Return(requestToken);
                httpContextMock.Stub(httpcontext => httpcontext.Request).Return(httpRequest);
                var controller        = new OAuthController(ContextBuilder, Provider);
                var controllerContext = new ControllerContext(httpContextMock, new RouteData(), controller);

                controller.ControllerContext = controllerContext;
                mocks.ReplayAll();
                result = controller.AccessToken();
            }
Ejemplo n.º 2
0
            public void SetFixture(MockRepository mocks)
            {
                var securedFilter      = new OAuthSecuredAttribute();
                var mockControllerBase = mocks.DynamicMock <ControllerBase>();
                var mockHttpContext    = mocks.DynamicMock <HttpContextBase>();

                mockResponse   = mocks.DynamicMock <HttpResponseBase>();
                contextBuilder = mocks.DynamicMock <IOAuthContextBuilder>();
                oauthContext   = mocks.DynamicMock <IOAuthContext>();
                var httpRequest       = mocks.DynamicMock <HttpRequestBase>();
                var controllerContext = new ControllerContext(mockHttpContext, new RouteData(), mockControllerBase);
                var filterContext     = new ResultExecutedContext(controllerContext, new EmptyResult(), false, null);

                mockHttpContext.Stub(context => context.Response).Return(mockResponse);
                mockHttpContext.Stub(context => context.Request).Return(httpRequest);
                mockResponse.Stub(response => response.Headers).Return(Headers);
                contextBuilder.Stub(builder => builder.FromHttpRequest(httpRequest)).Return(oauthContext);
                oauthContext.Stub(context => context.Realm).Return(DefaultRealm);
                mocks.ReplayAll();
                securedFilter.OAuthContextBuilder = contextBuilder;
                securedFilter.OnResultExecuted(filterContext);
            }
Ejemplo n.º 3
0
            public void SetFixture(MockRepository mocks)
            {
                AuthFiliter = new OAuthSecuredAttribute();
                DefaultoAuthContextBuilder = mocks.DynamicMock <IOAuthContextBuilder>();
                DefaultoAuthPovider        = mocks.DynamicMock <IOAuthProvider>();
                var controllerBase  = mocks.DynamicMock <ControllerBase>();
                var httpContext     = mocks.DynamicMock <HttpContextBase>();
                var mockHttpRequest = mocks.DynamicMock <HttpRequestBase>();

                DefaultoAuthContext = mocks.DynamicMock <IOAuthContext>();

                var controllerContext = new ControllerContext(httpContext, new RouteData(), controllerBase);

                httpContext.Stub(context => context.Request).Return(mockHttpRequest);

                DefaultoAuthContextBuilder.Stub(contextBuilder => contextBuilder.FromHttpRequest(mockHttpRequest)).Return(OAuthContext);
                SetupExpectations();
                FilterContext = new AuthorizationContext(controllerContext);
                AuthFiliter.OAuthContextBuilder = OAuthContextBuilder;
                AuthFiliter.OAuthProvider       = OAuthPovider;
                mocks.ReplayAll();
                Exception = Record.Exception(() => AuthFiliter.OnAuthorization(FilterContext));
            }