コード例 #1
0
        private static BehaviorChain chainFor <T>(Expression <Func <T, object> > expression)
        {
            var chain = new RoutedChain("something");

            chain.AddToEnd(ActionCall.For(expression));
            return(chain);
        }
        public void behavior_tracers_deeper()
        {
            var node  = Wrapper.For <SimpleBehavior>();
            var chain = new RoutedChain("foo");

            chain.AddToEnd(node);
            node.AddAfter(Wrapper.For <DifferentBehavior>());

            ApplyTracing.ApplyToChain(chain);



            var objectDef = chain.As <IContainerModel>().ToObjectDef().FindDependencyDefinitionFor <IActionBehavior>();

            objectDef.Type.ShouldEqual(typeof(BehaviorTracer));
            var child1 = objectDef.FindDependencyDefinitionFor <IActionBehavior>();

            child1.Type.ShouldEqual(typeof(SimpleBehavior));

            var child2 = child1.FindDependencyDefinitionFor <IActionBehavior>();

            child2.Type.ShouldEqual(typeof(BehaviorTracer));

            var child3 = child2.FindDependencyDefinitionFor <IActionBehavior>();

            child3.Type.ShouldEqual(typeof(DifferentBehavior));
        }
コード例 #3
0
        public void find_by_null_category_with_multiple_chains_but_only_one_is_default_2()
        {
            var search = new ChainSearch
            {
                CategoryMode         = CategorySearchMode.Relaxed,
                CategoryOrHttpMethod = null
            };

            var chain1 = new RoutedChain("")
            {
                UrlCategory =
                {
                    Category = "something"
                }
            };

            var chain2 = new RoutedChain("")
            {
                UrlCategory =
                {
                    Category = Categories.DEFAULT
                }
            };

            var chains = new BehaviorChain[] { chain1, chain2 };

            search.FindForCategory(chains).Single().ShouldBeTheSameAs(chain2);
        }
コード例 #4
0
ファイル: MenuNodeTester.cs プロジェクト: zzekikaya/fubumvc
        public void for_intput_with_model()
        {
            var key   = StringToken.FromKeyString("Something");
            var input = new FakeInput()
            {
                Name = "something"
            };
            var node = MenuNode.ForInput(key, input);

            node.UrlInput.ShouldBeTheSameAs(input);

            var chain1 = new RoutedChain("something");

            chain1.AddToEnd(ActionCall.For <FakeController>(x => x.FromInput(null)));
            chain1.Route.AddHttpMethodConstraint("GET");

            var chain2 = new RoutedChain("something");

            chain2.AddToEnd(ActionCall.For <FakeController>(x => x.FromInput(null)));
            chain2.Route.AddHttpMethodConstraint("POST");

            resolve(node, graph =>
            {
                graph.AddChain(chain1);
                graph.AddChain(chain2);
            });

            node.BehaviorChain.ShouldBeTheSameAs(chain1);
        }
コード例 #5
0
        public void matches_positive_because_route_definition_does_not_have_any_constraints()
        {
            var filter = new HttpMethodFilter("POST");
            var chain  = new RoutedChain(new RouteDefinition("something"));

            filter.Matches(chain).ShouldBeTrue();
        }
コード例 #6
0
ファイル: MenuNodeTester.cs プロジェクト: zzekikaya/fubumvc
        public void create_for_input_where_it_is_null()
        {
            var key  = StringToken.FromKeyString("Something");
            var node = MenuNode.ForInput <FakeInput>(key);

            node.UrlInput.ShouldBeNull();

            var chain1 = new RoutedChain("something");

            chain1.AddToEnd(ActionCall.For <FakeController>(x => x.FromInput(null)));
            chain1.Route.AddHttpMethodConstraint("GET");

            var chain2 = new RoutedChain("something");

            chain2.AddToEnd(ActionCall.For <FakeController>(x => x.FromInput(null)));
            chain2.Route.AddHttpMethodConstraint("POST");

            resolve(node, graph =>
            {
                graph.AddChain(chain1);
                graph.AddChain(chain2);
            });

            node.BehaviorChain.ShouldBeTheSameAs(chain1);
        }
コード例 #7
0
ファイル: MenuNodeTester.cs プロジェクト: zzekikaya/fubumvc
        public void create_for_action()
        {
            var key  = StringToken.FromKeyString("Something");
            var node = MenuNode.ForAction <FakeController>(key, x => x.GetFake());

            var chain1 = new RoutedChain(new RouteDefinition("something"));

            chain1.AddToEnd(ActionCall.For <FakeController>(x => x.GetFake()));
            chain1.Route.AddHttpMethodConstraint("GET");

            var chain2 = new RoutedChain(new RouteDefinition("something"));

            chain2.AddToEnd(ActionCall.For <FakeController>(x => x.GetFake()));
            chain2.Route.AddHttpMethodConstraint("POST");

            resolve(node, graph =>
            {
                graph.AddChain(chain1);
                graph.AddChain(chain2);
                graph.AddChain(new BehaviorChain());
                graph.AddChain(new BehaviorChain());
                graph.AddChain(new BehaviorChain());
                graph.AddChain(new BehaviorChain());
            });

            node.BehaviorChain.ShouldBeTheSameAs(chain1);
        }
コード例 #8
0
        public void do_nothing_if_tracing_is_off()
        {
            var registry = new FubuRegistry();

            registry.AlterSettings <DiagnosticsSettings>(x => x.TraceLevel = TraceLevel.None);
            registry.Configure(graph =>
            {
                chain1 = new RoutedChain("something");
                chain1.AddToEnd(Wrapper.For <SimpleBehavior>());
                chain1.AddToEnd(Wrapper.For <DifferentBehavior>());
                graph.AddChain(chain1);

                chain2 = new BehaviorChain();
                chain2.IsPartialOnly = true;
                chain2.AddToEnd(Wrapper.For <SimpleBehavior>());
                chain2.AddToEnd(Wrapper.For <DifferentBehavior>());
                graph.AddChain(chain2);
            });



            var notTracedGraph = BehaviorGraph.BuildFrom(registry);

            notTracedGraph.Behaviors.SelectMany(x => x).Any(x => x is DiagnosticBehavior).ShouldBeFalse();
            notTracedGraph.Behaviors.SelectMany(x => x).Any(x => x is BehaviorTracer).ShouldBeFalse();
        }
コード例 #9
0
        protected override void beforeEach()
        {
            theChain = new RoutedChain(new RouteDefinition("something")
            {
                Input = new RouteInput <FakeInput>("somepattern")
            });

            Services.Inject(new BehaviorGraph());


            theNode = new MenuNode(FakeKeys.Key1, r => theChain);
            theNode.Resolve(null);
            theNode.BehaviorChain.ShouldBeTheSameAs(theChain);
            theNode.UrlInput = new object();

            theNode.Icon("some image");

            theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key2));
            theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key3));
            theNode.Children.AddToEnd(new MenuNode(FakeKeys.Key4));

            theIconUrl = "test.png";
            MockFor <IAssetTagBuilder>().Stub(x => x.FindImageUrl(theNode.Icon())).Return(theIconUrl);

            theUrls = new StubUrlRegistry();
            Services.Inject <IUrlRegistry>(theUrls);

            MockFor <IMenuStateService>().Stub(x => x.DetermineStateFor(theNode))
            .Return(MenuItemState.Available);

            MockFor <IChainUrlResolver>().Stub(x => x.UrlFor(theNode.UrlInput, theNode.BehaviorChain))
            .Return("the full url");
        }
コード例 #10
0
ファイル: BehaviorGraphBuilder.cs プロジェクト: xeno3/fubumvc
 private static void addBuiltInDiagnostics(BehaviorGraph graph)
 {
     if (FubuMode.InDevelopment())
     {
         graph.AddChain(RoutedChain.For <AboutDiagnostics>(x => x.get__about(), "_about"));
         graph.AddChain(RoutedChain.For <AboutDiagnostics>(x => x.get__loaded(), "_loaded"));
     }
 }
コード例 #11
0
 public void SetUp()
 {
     theChain       = new BehaviorChain();
     theRoutedChain = new RoutedChain("something");
     theUrls        = new StubUrlRegistry();
     _report        = new Lazy <EndpointReport>(() => EndpointReport.ForChain(theChain));
     _routedReport  = new Lazy <EndpointReport>(() => EndpointReport.ForChain(theRoutedChain));
 }
コード例 #12
0
        public IEnumerable <RouteParameter> ToParameters(RoutedChain chain)
        {
            if (chain.Route.Input == null)
            {
                return(Enumerable.Empty <RouteParameter>());
            }

            return(chain.Route.Input.RouteParameters);
        }
コード例 #13
0
        public void matches_negative_because_of_methods()
        {
            var filter = new HttpMethodFilter("POST");
            var chain  = new RoutedChain(new RouteDefinition("something"));

            chain.Route.AddHttpMethodConstraint("GET");

            filter.Matches(chain).ShouldBeFalse();
        }
コード例 #14
0
        public void matches_positive_is_not_case_sensitive()
        {
            var filter = new HttpMethodFilter("POST");
            var chain  = new RoutedChain(new RouteDefinition("something"));

            chain.Route.AddHttpMethodConstraint("post");

            filter.Matches(chain).ShouldBeTrue();
        }
コード例 #15
0
        public void automatically_excludes_the_NotAuthenticated_attribute()
        {
            var chain = new RoutedChain("foo");

            chain.AddToEnd(ActionCall.For <AuthenticatedEndpoints>(x => x.get_notauthenticated()));

            new AuthenticationSettings().ShouldBeExcluded(chain)
            .ShouldBeTrue();
        }
コード例 #16
0
        public void add_a_route_alias()
        {
            var chain = new RoutedChain("something/else");
            var alias = new RouteDefinition("something/else");

            chain.AddRouteAlias(alias);

            chain.AdditionalRoutes.ShouldHaveTheSameElementsAs(alias);
        }
コード例 #17
0
        public void exclude_by_default_if_the_input_type_is_marked_as_NotAuthenticated()
        {
            var chain = new RoutedChain("bar");

            chain.AddToEnd(ActionCall.For <AuthenticatedEndpoints>(x => x.post_something(null)));


            var settings = new AuthenticationSettings();

            settings.ShouldBeExcluded(chain).ShouldBeTrue();
        }
コード例 #18
0
        public void exclude_by_default_actions_marked_as_pass_through()
        {
            var chain = new RoutedChain("foo");

            chain.AddToEnd(ActionCall.For <AuthenticatedEndpoints>(x => x.get_pass_through_authentication()));


            var settings = new AuthenticationSettings();

            settings.ShouldBeExcluded(chain).ShouldBeTrue();
        }
コード例 #19
0
ファイル: BehaviorGraph.cs プロジェクト: zzekikaya/fubumvc
        /// <summary>
        ///   Finds the matching BehaviorChain for the given IRouteDefinition.  If no
        ///   BehaviorChain exists, one is created and added to the BehaviorGraph
        /// </summary>
        /// <param name = "route"></param>
        /// <returns></returns>
        public BehaviorChain ChainFor(IRouteDefinition route)
        {
            var chain = _chains.OfType<RoutedChain>().FirstOrDefault(x => x.Route == route);
            if (chain == null)
            {
                chain = new RoutedChain(route);
                _chains.Fill(chain);
            }

            return chain;
        }
コード例 #20
0
        public void apply_a_custome_exclusion_and_it_does_not_apply_to_login_page()
        {
            var settings = new AuthenticationSettings();
            var chain    = new RoutedChain("foo");

            chain.AddToEnd(ActionCall.For <LoginController>(x => x.get_login(null)));
            settings.ShouldBeExcluded(chain).ShouldBeTrue();

            settings.ExcludeChains = c => c.Calls.Count() == 5; // just need a fake

            settings.ShouldBeExcluded(chain).ShouldBeTrue();
        }
コード例 #21
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());
        }
コード例 #22
0
        public void got_to_have_a_route_name()
        {
            var chain = new RoutedChain("foo");

            //chain.RouteName = "bar";
            chain.Route.AddHttpMethodConstraint("PUT");

            var router = new MyJavascriptRouter();

            Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() => {
                router.Add(chain);
            });
        }
コード例 #23
0
        private IEnumerable <ChainRoute> toRoutes(RoutedChain chain)
        {
            yield return(new ChainRoute {
                Chain = chain, Route = chain.Route
            });

            foreach (var additionalRoute in chain.AdditionalRoutes)
            {
                yield return(new ChainRoute {
                    Chain = chain, Route = additionalRoute
                });
            }
        }
コード例 #24
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");
        }
コード例 #25
0
        public void apply_a_custom_exclusion()
        {
            var chain = new RoutedChain("foo");

            chain.AddToEnd(ActionCall.For <AuthenticatedEndpoints>(x => x.get_tag()));


            var settings = new AuthenticationSettings();

            settings.ShouldBeExcluded(chain).ShouldBeFalse();

            settings.ExcludeChains = c => typeof(HtmlTag) == c.ResourceType();

            settings.ShouldBeExcluded(chain).ShouldBeTrue();
        }
コード例 #26
0
ファイル: DiagnosticsRegistry.cs プロジェクト: xeno3/fubumvc
        public void Configure(BehaviorGraph graph)
        {
            if (!graph.Behaviors.OfType <RoutedChain>().Any(x => x.GetRoutePattern().IsEmpty()))
            {
                var action    = ActionCall.For <DefaultHome>(x => x.GoToDiagnostics());
                var continuer = new ContinuationNode();

                var chain = new RoutedChain("");
                chain.Route.AddHttpMethodConstraint("GET");
                chain.AddToEnd(action);
                chain.AddToEnd(continuer);

                graph.AddChain(chain);
            }
        }
コード例 #27
0
ファイル: MenuNodeTester.cs プロジェクト: zzekikaya/fubumvc
        public void create_by_creator_of()
        {
            var key  = StringToken.FromKeyString("Something");
            var node = MenuNode.ForCreatorOf(key, typeof(Address));


            var chain = new RoutedChain("something");

            chain.UrlCategory.Creates.Add(typeof(Address));

            resolve(node, graph => graph.AddChain(chain));


            node.BehaviorChain.ShouldBeTheSameAs(chain);
        }
コード例 #28
0
ファイル: FormRequestTester.cs プロジェクト: xeno3/fubumvc
        public void SetUp()
        {
            theServices = new InMemoryServiceLocator();
            theSearch   = ChainSearch.ByUniqueInputType(typeof(object));
            theInput    = new object();

            theResolver    = MockRepository.GenerateStub <IChainResolver>();
            theUrlResolver = MockRepository.GenerateStub <IChainUrlResolver>();

            theChain = new RoutedChain("something");

            theServices.Add(theResolver);
            theServices.Add(theUrlResolver);

            theRequest = new FormRequest(theSearch, theInput);
        }
コード例 #29
0
        public void find_by_category_when_the_category_is_null_and_relaxed_search_and_only_one_chain_2()
        {
            var search = new ChainSearch
            {
                CategoryMode         = CategorySearchMode.Relaxed,
                CategoryOrHttpMethod = null
            };

            var chain1 = new RoutedChain("something");

            chain1.UrlCategory.Category = Categories.DEFAULT;

            var chains = new BehaviorChain[] { chain1, };

            search.FindForCategory(chains).Single().ShouldBeTheSameAs(chains.Single());
        }
コード例 #30
0
ファイル: FormRequestTester.cs プロジェクト: xeno3/fubumvc
        public void sets_the_full_url()
        {
            var fullUrl = "this/is/a/test";

            var route = new RouteDefinition("blah");

            route.ApplyInputType(typeof(object));

            theChain = new RoutedChain(fullUrl);

            theUrlResolver.Stub(x => x.UrlFor(theInput, theChain)).Return(fullUrl);
            theResolver.Stub(x => x.Find(theSearch)).Return(theChain);

            theRequest.Attach(theServices);

            theRequest.Url.ShouldEqual(fullUrl);
        }