public bool Invoke(Action invokeMvcPipeline, ActionDescriptor actionDescriptor, ControllerContext controllerContext)
        {
            //IMvcActionInvoker is httpcontext scoped
            var mvcActionInvoker = _mvcActionInvokerResolver();
            mvcActionInvoker.Set(invokeMvcPipeline);

            var actionName = _actionNameProvider.GetName(actionDescriptor);

            //find uniqueId for behavior chain that corresponds to this action call
            var controllerType = controllerContext.Controller.GetType();
            var parameterDescriptors = actionDescriptor.GetParameters();
            var inputParameters = parameterDescriptors.ToDictionary(x => x.ParameterName, x => x.ParameterType);
            var uniqueId = _behaviorChainIdLookup.GetUniqueId(controllerType, actionName, inputParameters);

            //get the behavior chain and invoke it, using this instance of ControllerContext for it
            var arguments = new ServiceArguments();
            //provide controller context to any behaviors that need to get at it
            arguments.Set(typeof(ControllerContext), controllerContext);
            using (var nestedContainer = _container.GetNestedContainer())
            {
                var actionBehavior = nestedContainer.GetInstance<IActionBehavior>(arguments.ToExplicitArgs(), uniqueId.ToString());
                actionBehavior.Invoke();
            }
            return true;
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof(Latch)))
            {
                return(DoNext.Stop);
            }


            var request = arguments.Get <IHttpRequest>();

            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding))
            {
                return(DoNext.Continue);
            }

            var acceptEncoding = request
                                 .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer   = arguments.Get <IHttpResponse>();

            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof(Latch), new Latch());

            return(DoNext.Continue);
        }
Example #3
0
 public void set_should_add_plugin()
 {
     var args = new ServiceArguments();
     var plugin = new Plugin();
     args.Has(typeof(Plugin)).ShouldBeFalse();
     args.Set(typeof(Plugin), plugin);
     args.Has(typeof(Plugin)).ShouldBeTrue();
 }
        public void set_should_add_plugin()
        {
            var args   = new ServiceArguments();
            var plugin = new Plugin();

            args.Has(typeof(Plugin)).ShouldBeFalse();
            args.Set(typeof(Plugin), plugin);
            args.Has(typeof(Plugin)).ShouldBeTrue();
        }
Example #5
0
        protected override void beforeEach()
        {
            theArguments        = new ServiceArguments();
            theEncoding         = MockFor <IHttpContentEncoding>();
            theAcceptedEncoding = "gzip, deflate, sdch";

            theEncoding.Stub(x => x.MatchingEncoding).Return(ContentEncoding.GZip);
            MockFor <IHttpContentEncoders>().Stub(x => x.MatchFor(theAcceptedEncoding)).Return(theEncoding);

            theHeaders = new KeyValues();
            theHeaders[HttpRequestHeaders.AcceptEncoding] = theAcceptedEncoding;
            var requestData = new RequestData(new FlatValueSource(theHeaders, RequestDataSource.Header.ToString()));

            theArguments.Set(typeof(IRequestData), requestData);
            theArguments.Set(typeof(IHttpWriter), MockFor <IHttpWriter>());

            ClassUnderTest.Filter(theArguments).ShouldEqual(DoNext.Continue);
        }
Example #6
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }


            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });

            behavior.Invoke();
        }
            public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
            {
                var exceptionHandlingObserver = new ExceptionHandlingObserver();

                _arguments.Set(typeof(IExceptionHandlingObserver), exceptionHandlingObserver);
                var task = Task.Factory.StartNew(state => _invoker.Invoke(_arguments, _routeData), exceptionHandlingObserver);

                task.ContinueWith(x => cb(x));
                return(task);
            }
Example #8
0
        public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);
            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (arguments.Has(typeof (IChainExecutionLog)))
            {
                arguments.Get<IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof (IChainExecutionLog)))
            {
                arguments.Get<IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }

            
            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });

            behavior.Invoke();
        }
        protected override void beforeEach()
        {
            theArguments        = new ServiceArguments();
            theEncoding         = MockFor <IHttpContentEncoding>();
            theAcceptedEncoding = "gzip, deflate, sdch";

            theEncoding.Stub(x => x.MatchingEncoding).Return(ContentEncoding.GZip);
            MockFor <IHttpContentEncoders>().Stub(x => x.MatchFor(theAcceptedEncoding)).Return(theEncoding);

            var request = new OwinHttpRequest();

            request.AppendHeader(HttpRequestHeaders.AcceptEncoding, theAcceptedEncoding);



            theArguments.Set(typeof(IHttpRequest), request);
            theArguments.Set(typeof(IHttpResponse), MockFor <IHttpResponse>());

            ClassUnderTest.Filter(theArguments).ShouldBe(DoNext.Continue);
        }
 protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
 {
     Controller result = null;
     if (controllerType != null)
     {
         var arguments = new ServiceArguments();
         arguments.Set(typeof (ControllerContext), null);
         result = (Controller) _container.GetInstance(controllerType, arguments.ToExplicitArgs());
         result.ActionInvoker = _container.GetInstance<IActionInvoker>();
     }
     return result;
 }
Example #11
0
        public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);
            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }
            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });
            behavior.Invoke();
        }
        public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId)
        {
            var diagnostics = _container.Get<DiagnosticBehavior>();

            var writer = _container.Get<IOutputWriter>();
            var report = _container.Get<IDebugReport>();
            arguments.Set(typeof(IOutputWriter), new RecordingOutputWriter(report, writer));

            var behavior = _inner.BuildBehavior(arguments, behaviorId);
            diagnostics.Inner = behavior;

            return diagnostics;
        }
Example #13
0
        public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues)
        {
            var currentChain = new CurrentChain(_chain, routeValues);
            arguments.Set(typeof(ICurrentChain), currentChain);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            Invoke(behavior);
        }
Example #14
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }
            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);

            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });
            behavior.Invoke();
        }
Example #15
0
        public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId)
        {
            var diagnostics = _container.Get <DiagnosticBehavior>();

            var writer = _container.Get <IOutputWriter>();
            var report = _container.Get <IDebugReport>();

            arguments.Set(typeof(IOutputWriter), new RecordingOutputWriter(report, writer));

            var behavior = _inner.BuildBehavior(arguments, behaviorId);

            diagnostics.Inner = behavior;

            return(diagnostics);
        }
Example #16
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            var behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);

            behavior.Invoke();
        }
        public void SetUp()
        {
            theServiceArguments = new ServiceArguments();
            theDictionary       = new AggregateDictionary();
            theHeaders          = new Dictionary <string, object>();
            theDictionary.AddDictionary(RequestDataSource.Header.ToString(), theHeaders);

            theServiceArguments.Set(typeof(AggregateDictionary), theDictionary);

            stash <IHttpWriter>();
            stash <ICurrentChain>();

            theCache = new EtagCache();

            theFilter = new AssetEtagInvocationFilter(theCache);
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof(Latch))) return DoNext.Stop;

            arguments
                .Get<IRequestData>()
                .ValuesFor(RequestDataSource.Header)
                .Value(HttpRequestHeaders.AcceptEncoding, x =>
                {
                    var encoding = _encoders.MatchFor(x.RawValue as string);
                    var writer = arguments.Get<IHttpWriter>();

                    writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);
                    writer.UseEncoding(encoding);
                });

            arguments.Set(typeof(Latch), new Latch());

            return DoNext.Continue;
        }
        public void SetUp()
        {
            theHeaders = new KeyValues();
            var requestData = new RequestData(new FlatValueSource(theHeaders, RequestDataSource.Header.ToString()));

            theServiceArguments = new ServiceArguments();

            theServiceArguments.Set(typeof(IRequestData), requestData);

            stash <IHttpWriter>();
            stash <ICurrentChain>();

            theCache = new HeadersCache();

            theHash = Guid.NewGuid().ToString();

            theSource = MockRepository.GenerateMock <Func <ServiceArguments, string> >();
            theSource.Stub(x => x.Invoke(theServiceArguments)).Return(theHash);

            theFilter = new EtagInvocationFilter(theCache, theSource);
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof (Latch))) return DoNext.Stop;


            var request = arguments.Get<IHttpRequest>();
            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) return DoNext.Continue;

            var acceptEncoding = request
                .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer = arguments.Get<IHttpResponse>();
            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof (Latch), new Latch());

            return DoNext.Continue;
        }
Example #21
0
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof(Latch)))
            {
                return(DoNext.Stop);
            }

            arguments
            .Get <IRequestData>()
            .ValuesFor(RequestDataSource.Header)
            .Value(HttpRequestHeaders.AcceptEncoding, x =>
            {
                var encoding = _encoders.MatchFor(x.RawValue as string);
                var writer   = arguments.Get <IHttpWriter>();

                writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);
                writer.UseEncoding(encoding);
            });

            arguments.Set(typeof(Latch), new Latch());

            return(DoNext.Continue);
        }
 private void stash <T>() where T : class
 {
     theServiceArguments.Set(typeof(T), MockRepository.GenerateMock <T>());
 }