public void create_for_action()
        {
            var key  = StringToken.FromKeyString("Something");
            var node = MenuNode.ForAction <FakeController>(key, x => x.GetFake());

            var chain1 = new BehaviorChain();

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

            var chain2 = new BehaviorChain();

            chain2.AddToEnd(ActionCall.For <FakeController>(x => x.GetFake()));
            chain2.Route = new RouteDefinition("something");
            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);
        }
        public void create_for_action_with_lambda()
        {
            var key  = StringToken.FromKeyString("Something");
            var node = MenuNode.ForAction <FakeController>(key, x => x.GetFake(), x => x.Category = "Test");

            node.Category.ShouldEqual("Test");
        }
Ejemplo n.º 3
0
        public void add_roles_by_name()
        {
            var graph = buildGraph(x =>
            {
                x.Navigation(r =>
                {
                    r.ForMenu("Menu1");
                    r.Add += MenuNode.ForAction <OneController>("something", c => c.Go());
                    r.Add += MenuNode.ForAction <OneController>("else", c => c.Query(null));
                    r.Add += MenuNode.ForAction <OneController>("different", c => c.Report());
                });

                x.ApplyConvention <NavigationRootPolicy>(policy =>
                {
                    policy.ForKey("Menu1");
                    policy.RequireRole("role1");
                    policy.RequireRole("role2");
                });
            });

            // positive cases
            graph.BehaviorFor <OneController>(c => c.Go()).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");
            graph.BehaviorFor <OneController>(c => c.Query(null)).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");
            graph.BehaviorFor <OneController>(c => c.Report()).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");


            graph.BehaviorFor <TwoController>(c => c.Go()).Authorization.AllowedRoles().Any().ShouldBeFalse();
            graph.BehaviorFor <ThreeController>(c => c.Go()).Authorization.AllowedRoles().Any().ShouldBeFalse();
        }
Ejemplo n.º 4
0
        public void wrap_with_chrome()
        {
            var graph = buildGraph(x =>
            {
                x.Navigation(r =>
                {
                    r.ForMenu("Menu1");
                    r.Add += MenuNode.ForAction <OneController>("something", c => c.Go());
                    r.Add += MenuNode.ForAction <OneController>("else", c => c.Query(null));
                    r.Add += MenuNode.ForAction <OneController>("different", c => c.Report());
                });

                x.ApplyConvention <NavigationRootPolicy>(policy =>
                {
                    policy.ForKey("Menu1");

                    policy.WrapWithChrome <FakeChrome>();
                });
            });

            // positive cases

            graph.BehaviorFor <OneController>(c => c.Query(null)).OfType <ChromeNode>().Single().ContentType.ShouldEqual(typeof(FakeChrome));
            graph.BehaviorFor <OneController>(c => c.Report()).OfType <ChromeNode>().Single().ContentType.ShouldEqual(typeof(FakeChrome));


            // Go() does not have any output type
            graph.BehaviorFor <OneController>(c => c.Go()).OfType <ChromeNode>().Any().ShouldBeFalse();

            graph.BehaviorFor <TwoController>(c => c.Report()).OfType <ChromeNode>().Any().ShouldBeFalse();
            graph.BehaviorFor <ThreeController>(c => c.Report()).OfType <ChromeNode>().Any().ShouldBeFalse();
        }
        public void add_roles_by_key()
        {
            var key = StringToken.FromKeyString("Menu1");

            var graph = buildGraph(x =>
            {
                x.Import <NavigationRegistryExtension>();

                x.Policies.Add <NavigationRegistry>(r =>
                {
                    r.ForMenu(key);
                    r.Add += MenuNode.ForAction <OneController>("something", c => c.Go());
                    r.Add += MenuNode.ForAction <OneController>("else", c => c.Query(null));
                    r.Add += MenuNode.ForAction <OneController>("different", c => c.Report());
                });

                x.Policies.Add <NavigationRootPolicy>(policy =>
                {
                    policy.ForKey(key);
                    policy.RequireRole("role1");
                    policy.RequireRole("role2");
                });
            });

            // positive cases
            graph.BehaviorFor <OneController>(c => c.Go()).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");
            graph.BehaviorFor <OneController>(c => c.Query(null)).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");
            graph.BehaviorFor <OneController>(c => c.Report()).Authorization.AllowedRoles().ShouldHaveTheSameElementsAs("role1", "role2");


            graph.BehaviorFor <TwoController>(c => c.Go()).Authorization.AllowedRoles().Any().ShouldBeFalse();
            graph.BehaviorFor <ThreeController>(c => c.Go()).Authorization.AllowedRoles().Any().ShouldBeFalse();
        }
        public DiagnosticsMenu()
        {
            ForMenu(DiagnosticKeys.Main);

            Add += MenuNode.ForInput <PackageDiagnosticsRequestModel>(DiagnosticKeys.ApplicationStartup);

            Add += MenuNode.ForAction <RequestsEndpoint>(DiagnosticKeys.Requests, x => x.get_requests());
            Add += MenuNode.ForInput <RoutesRequest>(DiagnosticKeys.Endpoints);

            Add += MenuNode.ForAction <ModelBindingEndpoints>(DiagnosticKeys.ModelBindingExplorer, x => x.get_binding_all());


            Add += MenuNode.Node(DiagnosticKeys.Services);
            ForMenu(DiagnosticKeys.Services);

            Add += MenuNode.ForAction <ServiceEndpoints>(DiagnosticKeys.ServicesByName, x => x.get_services_byname());
            Add += MenuNode.ForAction <ServiceEndpoints>(DiagnosticKeys.ServicesBySource, x => x.get_services_bysource());
        }
Ejemplo n.º 7
0
 public FubuWorldMenu()
 {
     ForMenu(FubuWorldKeys.Main);
     Add += MenuNode.ForAction <HomeController>(FubuWorldKeys.Home, x => x.get_home());
 }