Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 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");
            });
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 16
0
 public void keeps_the_route_data()
 {
     var currentChain = new CurrentChain(theChain, theRouteData);
     currentChain.RouteData.ShouldBeTheSameAs(theRouteData);
 }
Ejemplo n.º 17
0
 public void is_in_partial_negative()
 {
     var currentChain = new CurrentChain(theChain, null);
     currentChain.IsInPartial().ShouldBeFalse();
 }
Ejemplo n.º 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);
        }