示例#1
0
        public void the_resource_hash_is_deterministic_by_pattern()
        {
            var hash1 = new CurrentChain(theChain, theRouteData).ResourceHash();
            var hash2 = new CurrentChain(theSecondChain, theRouteData).ResourceHash();

            hash1.ShouldNotEqual(hash2);
        }
        public void hash_values_when_the_chain_has_a_route_but_not_real_values()
        {
            var chain = new RoutedChain(new RouteDefinition("some/pattern/url"));

            var currentChain = new CurrentChain(chain, new Dictionary<string, object>());

            var varyBy = new VaryByResource(currentChain);

            var values = varyBy.Values();
            values.Select(x => "{0}={1}".ToFormat(x.Key, x.Value)).ShouldHaveTheSameElementsAs("chain=" + chain.GetRoutePattern());
        }
        public void is_in_partial_negative_after_popping_the_last_child()
        {
            var currentChain = new CurrentChain(theChain, null);
            currentChain.Push(theSecondChain);
            currentChain.Push(theThirdChain);

            currentChain.Pop();
            currentChain.Pop();

            currentChain.IsInPartial().ShouldBeFalse();
        }
        public void hash_values_with_a_route_That_has_substitutions()
        {
            var chain = new RoutedChain(RouteBuilder.Build<Query>("some/pattern/url/{from}/{to}"));

            var currentChain = new CurrentChain(chain, new Dictionary<string, object>{{"from", 1}, {"to", 2}});
            var varyBy = new VaryByResource(currentChain);

            var values = varyBy.Values();
            values.Select(x => "{0}={1}".ToFormat(x.Key, x.Value))
                .ShouldHaveTheSameElementsAs("chain=" + "some/pattern/url/{from}/{to}", "from=1", "to=2");
        }
        public void is_in_partial_positive()
        {
            var currentChain = new CurrentChain(theChain, null);
            currentChain.Push(theSecondChain);
            currentChain.IsInPartial().ShouldBeTrue();

            currentChain.Push(theThirdChain);
            currentChain.IsInPartial().ShouldBeTrue();

            currentChain.Pop();
            currentChain.IsInPartial().ShouldBeTrue();
        }
示例#6
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);
        }
        public void SetUp()
        {
            var theHttpRequest = new CurrentChain(new BehaviorChain(), new Dictionary<string, object>());
            theExpectedHash = ResourceHash.For(theHttpRequest);

            FubuApplication.SetupNamingStrategyForHttpHeaders();

             theEtagRequest = BindingScenario<ETaggedRequest>.Build(x =>
            {
                x.Service<ICurrentChain>(theHttpRequest);
                x.Data("If-None-Match", "12345");
            });
        }
        public void hash_values_with_a_chain_that_is_a_partial()
        {
            var chain = new BehaviorChain()
            {

            };

            var currentChain = new CurrentChain(chain, new Dictionary<string, object> { { "from", 1 }, { "to", 2 } });
            var varyBy = new VaryByResource(currentChain);

            var values = varyBy.Values();
            values.Select(x => "{0}={1}".ToFormat(x.Key, x.Value))
                .ShouldHaveTheSameElementsAs("chain=" + chain.ToString());
        }
        public InvocationContext(Envelope envelope, HandlerChain chain)
        {
            if (envelope == null) throw new ArgumentNullException("envelope");

            var currentChain = new CurrentChain(chain, _emptyDictionary);
            Set(typeof(ICurrentChain), currentChain);

            _envelope = envelope;
            var inputType = envelope.Message.GetType();
            var request = new InMemoryFubuRequest();
            request.Set(inputType, _envelope.Message);

            Set(typeof(IFubuRequest), request);
            Set(typeof(IInvocationContext), this);
            Set(typeof(Envelope), envelope);
        }
示例#10
0
        public void push_and_pop_track_the_current_chain()
        {
            var currentChain = new CurrentChain(theChain, theRouteData);
            currentChain.Push(theSecondChain);

            currentChain.Current.ShouldBeTheSameAs(theSecondChain);

            currentChain.Push(theThirdChain);
            currentChain.Current.ShouldBeTheSameAs(theThirdChain);

            currentChain.Pop();
            currentChain.Current.ShouldBeTheSameAs(theSecondChain);

            currentChain.Pop();
            currentChain.Current.ShouldBeTheSameAs(theChain);
        }
        public void hash_values_with_a_chain_that_is_a_partial()
        {
            var chain = new BehaviorChain()
            {
                Route = RouteBuilder.Build<Query>("some/pattern/url/{from}/{to}"),
                IsPartialOnly = true

            };

            var currentChain = new CurrentChain(chain, new Dictionary<string, object> { { "from", 1 }, { "to", 2 } });
            var varyBy = new VaryByResource(currentChain);

            var values = varyBy.Values();
            values.Select(x => "{0}={1}".ToFormat(x.Key, x.Value))
                .ShouldHaveTheSameElementsAs("chain=" + chain.UniqueId.ToString());
        }
示例#12
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();
        }
示例#13
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();
        }
示例#14
0
        public async Task Invoke(TypeArguments arguments, IDictionary<string, object> routeValues)
        {
            var currentChain = new CurrentChain(_chain, routeValues);
            arguments.Set(typeof(ICurrentChain), currentChain);

            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);
            }

            try
            {
                await behavior.Invoke().ConfigureAwait(false);
            }
            finally
            {
                var disposable = behavior as IDisposable;
                disposable?.Dispose();
            }
        }
示例#15
0
        public void the_top_chain_is_always_the_originating_chain()
        {
            var currentChain = new CurrentChain(theChain, theRouteData);
            currentChain.OriginatingChain.ShouldBeTheSameAs(theChain);

            currentChain.Push(theSecondChain);
            currentChain.OriginatingChain.ShouldBeTheSameAs(theChain);

            currentChain.Pop();

            currentChain.OriginatingChain.ShouldBeTheSameAs(theChain);
        }
示例#16
0
 public void keeps_the_route_data()
 {
     var currentChain = new CurrentChain(theChain, theRouteData);
     currentChain.RouteData.ShouldBeTheSameAs(theRouteData);
 }
示例#17
0
 public void is_in_partial_negative()
 {
     var currentChain = new CurrentChain(theChain, null);
     currentChain.IsInPartial().ShouldBeFalse();
 }
示例#18
0
        public void the_resource_hash_is_deterministic_by_route_parameters()
        {
            var hash1 = new CurrentChain(theChain, theRouteData).ResourceHash();
            var hash2 = new CurrentChain(theChain, theRouteData).ResourceHash();

            hash1.ShouldBe(hash2);

            var hash3 = new CurrentChain(theChain, someDifferentRouteData).ResourceHash();

            hash1.ShouldNotBe(hash3);
        }