Exemple #1
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);
            }
Exemple #2
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));
            }