Пример #1
0
        public void SetUp()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<JsonController>();

            theGraph = registry.BuildGraph();
        }
        public void SetUp()
        {
            registry = new FubuRegistry(x =>
            {

                // Tell FubuMVC to enrich the behavior chain for each
                // RouteHandler with the "FakeUnitOfWorkBehavior"
                // Kind of like a global [ActionFilter] in MVC
                x.Policies.EnrichCallsWith<FakeUnitOfWorkBehavior>(
                    call => call.Method.Name == "SomeAction");

                // Explicit junk you would only do for exception cases to
                // override the conventions
                x.Route<InputModel>("area/sub/{Name}/{Age}")
                    .Calls<TestController>(c => c.SomeAction(null)).OutputToJson();

                x.Route<InputModel>("area/sub2/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route<InputModel>("area/sub3/{Name}/{Age}")
                    .Calls<TestController>(c => c.ThirdAction(null)).OutputToJson();
            });

            _graph = registry.BuildGraph();
        }
        public void configures_settings_with_default_assemblies_and_namespaces()
        {
            var registry = new FubuRegistry();
            registry.WithSparkDefaults();

            SparkSettings settings = null;
            registry.Services(x =>
                              	{
                              		settings = (SparkSettings) x.DefaultServiceFor<ISparkSettings>().Value;
                              	});

            registry.BuildGraph();

            settings
                .UseAssemblies
                .ShouldContain(typeof(HtmlTag).Assembly.FullName);

            settings
                .UseAssemblies
                .ShouldContain(typeof(FubuPageExtensions).Assembly.FullName);

            settings
                .UseNamespaces
                .ShouldContain(typeof(FubuRegistryExtensions).Namespace);

            settings
                .UseNamespaces
                .ShouldContain(typeof(FubuPageExtensions).Namespace);

            settings
                .UseNamespaces
                .ShouldContain(typeof(HtmlTag).Namespace);
        }
Пример #4
0
        public void apply_the_simplistic_asset_combination_approach()
        {
            var registry = new FubuRegistry();
            registry.Assets.CombineAllUniqueAssetRequests();

            registry.BuildGraph().Services.DefaultServiceFor<ICombinationDeterminationService>()
                .Type.ShouldEqual(typeof(CombineAllUniqueSetsCombinationDeterminationService));
        }
Пример #5
0
        public void register_a_custom_missing_asset_handler()
        {
            var registry = new FubuRegistry();
            registry.Assets.HandleMissingAssetsWith<MyDifferentMissingAssetHandler>();

            registry.BuildGraph().Services.DefaultServiceFor<IMissingAssetHandler>()
                .Type.ShouldEqual(typeof(MyDifferentMissingAssetHandler));
        }
Пример #6
0
        public void YSOD_false()
        {
            var registry = new FubuRegistry();
            registry.Assets.YSOD_on_missing_assets(false);

            registry.BuildGraph().Services.DefaultServiceFor<IMissingAssetHandler>()
                .Type.ShouldEqual(typeof (TraceOnlyMissingAssetHandler));
        }
Пример #7
0
 private BehaviorGraph setupActions()
 {
     var registry = new FubuRegistry();
     registry.Route("a/m1").Calls<Action1>(a => a.M1());
     registry.Route("a/m2").Calls<Action1>(a => a.M2());
     registry.Route("b/m1").Calls<Action2>(b => b.M1());
     registry.Route("b/m2").Calls<Action2>(b => b.M2());
     return registry.BuildGraph();
 }
        public void wraps_handled_actions_with_exception_wrapper()
        {
            var registry = new FubuRegistry(r => r.ApplyConvention<APIExceptionConvention<Error500Request>>());
            registry.Actions.IncludeType<Action>();

            var graph = registry.BuildGraph();

            graph.BehaviorFor<Action>(x => x.ApiMethod(null)).IsWrappedBy(typeof(ActionExceptionWrapper<Error500Request>)).ShouldBeTrue();
        }
        public void uses_the_resource_path_to_do_its_job()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<Controller1>();

            registry.BuildGraph().BehaviorFor<Controller1>(x => x.get_resource(null)).Route.CreateUrlFromInput(
                new ResourcePath("something/else"))
                .ShouldEqual("resource/something/else");
        }
Пример #10
0
        public void integrated_with_fubu_registry()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<PartialController>();

            var graph = registry.BuildGraph();

            graph.BehaviorFor<PartialController>(x => x.Go(null)).IsPartialOnly.ShouldBeFalse();
            graph.BehaviorFor<PartialController>(x => x.GoPartial(null)).IsPartialOnly.ShouldBeTrue();
        }
Пример #11
0
        public void register_a_combination_policy_with_CombineWith()
        {
            var registry = new FubuRegistry();
            registry.Assets
                .CombineWith<CombineAllScriptFiles>()
                .CombineWith<CombineAllStylesheets>();

            registry.BuildGraph().Services.ServicesFor(typeof(ICombinationPolicy))
                .Select(x => x.Type).ShouldHaveTheSameElementsAs(typeof(CombineAllScriptFiles), typeof(CombineAllStylesheets));
        }
        public void should_put_an_anti_forgery_token_on_the_chain()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<Controller1>();

            registry.BuildGraph().BehaviorFor<Controller1>(x => x.MethodWithAF(null))
                .FirstCall()
                .Previous.ShouldBeOfType<AntiForgeryNode>()
                .Salt.ShouldEqual("abc");
        }
        public void should_only_apply_behavior_once()
        {
            var hostRegistry = new FubuRegistry();
            var packageRegistry = new FubuPackageRegistry();
            packageRegistry.Actions.IncludeType<Controller1>();
            hostRegistry.Import(packageRegistry, string.Empty);
            theGraph = hostRegistry.BuildGraph();

            var chain = chainFor(x => x.BasicContinuation(null))
                .Output.Writers.OfType<Writer>().ShouldHaveCount(1);
        }
Пример #14
0
        public void SetUp()
        {
            var registry = new FubuRegistry();
            registry.Import<DiagnosticsRegistration>();

            graph = registry.BuildGraph();
            urls = MockRepository.GenerateMock<IUrlRegistry>();

            graph.Behaviors.Any().ShouldBeTrue();
            graph.Actions().Each(x => Debug.WriteLine(x.Description));
        }
Пример #15
0
 public void should_ignore_types_with_null_namespace()
 {
     var registry = new FubuRegistry(x =>
                                         {
                                             x.Applies.ToThisAssembly();
                                             x.Actions.IncludeType<ControllerWithoutANamespace>();
                                             x.Import<DiagnosticsRegistration>();
                                         });
     // basically just make sure nothing blows up
     registry
         .BuildGraph();
 }
        public void SetUp()
        {
            var registry = new FubuRegistry(x =>
            {
                x.Actions.IncludeType<SitesController>();
                x.Actions.IncludeType<CasesController>();

                x.ApplyConvention<EnsureEntityExistsConvention>();
            });

            theGraph = registry.BuildGraph();
        }
        public void SetUp()
        {
            var registry = new FubuRegistry(x =>
            {
                x.Actions.IncludeType<Controller1>();
                x.Actions.IncludeType<Controller2>();

                x.Media.ApplyContentNegotiationToActions(call => call.OutputType() == typeof (ViewModel3));
            });

            theGraph = registry.BuildGraph();
        }
        public void applies_conneg()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<SomeController>();

            var chain = registry.BuildGraph().BehaviorFor<SomeController>(x => x.Go(null));

            chain.Output.UsesFormatter<JsonFormatter>();
            chain.Output.UsesFormatter<XmlFormatter>();

            chain.Input.AllowHttpFormPosts.ShouldBeTrue();
            chain.Input.UsesFormatter<JsonFormatter>();
            chain.Input.UsesFormatter<XmlFormatter>();
        }
        public void navigation_method_on_fubu_registry_works()
        {
            var registry = new FubuRegistry();
            registry.Navigation(x =>
            {
                x.ForMenu(FakeKeys.Key1);
                x.Add += MenuNode.Node(FakeKeys.Key2);
                x.Add += MenuNode.Node(FakeKeys.Key3);
            });

            var graph = registry.BuildGraph().Navigation;

            graph.MenuFor(FakeKeys.Key1).Select(x => x.Key)
                .ShouldHaveTheSameElementsAs(FakeKeys.Key2, FakeKeys.Key3);
        }
        public void should_append_the_url_suffix_onto_each_appropriate_route()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<Controller1>();

            var graph = registry.BuildGraph();

            graph.BehaviorFor<Controller1>(x => x.get_resource(null))
                .Route.Pattern.ShouldEqual(
                    "resource/{Part0}/{Part1}/{Part2}/{Part3}/{Part4}/{Part5}/{Part6}/{Part7}/{Part8}/{Part9}");

            graph.BehaviorFor<Controller1>(x => x.get_special(null))
                .Route.Pattern.ShouldEqual(
                    "special/{Part0}/{Part1}/{Part2}/{Part3}/{Part4}/{Part5}/{Part6}/{Part7}/{Part8}/{Part9}");
        }
        public void registers_spark_view_factory()
        {
            var registry = new FubuRegistry();
            registry.WithSparkDefaults();

            ISparkViewFactory factory = null;
            registry.Services(x =>
                              	{
                                    factory = (ISparkViewFactory)x.DefaultServiceFor<ISparkViewFactory>().Value;
                              	});

            registry.BuildGraph();

            factory.ShouldNotBeNull();
        }
Пример #22
0
        public void smoke_test_the_with_types()
        {
            var registry = new FubuRegistry();
            registry.Applies.ToThisAssembly();
            registry.WithTypes(types =>
            {
                types.TypesMatching(x => x.IsConcreteTypeOf<MyInterface>()).Each(type =>
                {
                    registry.Services(s => s.AddService(typeof(MyInterface), new ObjectDef(type)));
                });
            });

            registry.BuildGraph().Services.ServicesFor<MyInterface>()
                .Single().Type.ShouldEqual(typeof (MyConcreteClass));
        }
        public void override_the_storage_mechanism()
        {
            var registry = new FubuRegistry();
            registry.Import<BasicLocalizationSupport>(x =>
            {
                x.LocalizationStorageIs<InMemoryLocalizationStorage>();
            });
            var graph = registry.BuildGraph();

            var list = graph.Services.ServicesFor<IActivator>().Select(x => x.Type).ToList();

            list.ShouldNotContain(typeof(RegisterXmlDirectoryLocalizationStorage));
            list.ShouldContain(typeof(SpinUpLocalizationCaches));

            graph.Services.DefaultServiceFor<ILocalizationStorage>().Type.ShouldEqual(
                typeof (InMemoryLocalizationStorage));
        }
        public void SetUp()
        {
            var registry = new FubuRegistry(x =>
            {
                x.Actions.IncludeTypesNamed(t => t.EndsWith("Controller"));

                x.Configure(g =>
                {
                    g.BehaviorFor<AuthorizedController>(c => c.Go()).Authorization.AddRole("RoleA");
                });
            });

            graph = registry.BuildGraph();

            goChain = graph.BehaviorFor<AuthorizedController>(x => x.Go());
            moveChain = graph.BehaviorFor<AuthorizedController>(x => x.Move());
        }
        public void first_configuration_supercedes_second()
        {
            var registry = new FubuRegistry();
            registry.Spark(spark => spark.Settings.AddNamespace("Test"));
            registry.WithSparkDefaults();

            SparkSettings settings = null;
            registry.Services(x =>
                              	{
                              		settings = (SparkSettings) x.DefaultServiceFor<ISparkSettings>().Value;
                              	});

            registry.BuildGraph();

            settings
                .UseNamespaces
                .ShouldContain("Test");
        }
        public void import_navigation_from_child_registry()
        {
            var registry = new FubuRegistry();
            registry.Navigation(x =>
            {
                x.ForMenu(FakeKeys.Key1);
                x.Add += MenuNode.Node(FakeKeys.Key2);
                x.Add += MenuNode.Node(FakeKeys.Key3);
            });

            registry.Import<ChildRegistry>();

            var graph = registry.BuildGraph().Navigation;

            graph.MenuFor(FakeKeys.Key1).Select(x => x.Key)
                .ShouldHaveTheSameElementsAs(FakeKeys.Key2, FakeKeys.Key3, FakeKeys.Key4, FakeKeys.Key5);

            graph.MenuFor(FakeKeys.Key6).Select(x => x.Key)
                .ShouldHaveTheSameElementsAs(FakeKeys.Key7, FakeKeys.Key8);
        }
Пример #27
0
        public void BeforeEach()
        {
            _parent = new FubuRegistry();
            _parent.IncludeDiagnostics(true);

            _import = new FubuRegistry();
            _import.IncludeDiagnostics(true);
            _import.Actions
                .IncludeType<Handler1>()
                .IncludeType<Handler2>();

            _import.Configure(x =>
            {
                _importObserver = x.Observer;
                _importActions = x.Actions()
                    .Where(a => a.HandlerType.Namespace == GetType().Namespace);
            });

            _parent.Import(_import, "import");
            _parentObserver = _parent.BuildGraph().Observer;
        }
        public void SetUp()
        {
            var registry = new FubuRegistry();
            registry.Configure(graph =>
            {
                chain1 = new BehaviorChain();
                chain1.AddToEnd(Wrapper.For<SimpleBehavior>());
                chain1.AddToEnd(Wrapper.For<DifferentBehavior>());
                chain1.Route = new RouteDefinition("something");
                graph.AddChain(chain1);

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

            });

            registry.Policies.Add<ApplyTracing>();

            registry.BuildGraph();
        }
Пример #29
0
        public void Bootstrap(ICollection <RouteBase> routes)
        {
            if (HttpContext.Current != null)
            {
                UrlContext.Live();
            }



            // Find all of the IFubuRegistryExtension's and apply
            // them to the top level FubuRegistry *BEFORE*
            // registering the Fubu application parts into
            // your IoC container
            FindAllExtensions().Each(x => x.Configure(_topRegistry));

            // "Bake" the fubu configuration model into your
            // IoC container for the application
            var graph = _topRegistry.BuildGraph();

            graph.EachService(_facility.Register);
            var factory = _facility.BuildFactory();

            // Register all the Route objects into the routes
            // collection

            // TODO -- need a way to do this with debugging
            graph.VisitRoutes(x =>
            {
                x.Actions += (routeDef, chain) =>
                {
                    var route          = routeDef.ToRoute();
                    route.RouteHandler = new FubuRouteHandler(factory, chain.UniqueId);

                    routes.Add(route);
                };
            });
        }
Пример #30
0
        public void SetUp()
        {
            var registry = new FubuRegistry(x =>
            {
                x.Applies.ToThisAssembly();
                x.Actions.IncludeClassesSuffixedWithController();
            });

            theGraph = registry.BuildGraph();
        }
Пример #31
0
        public void SetUp()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<OrderingPolicyController>();

            registry.Policies.WrapBehaviorChainsWith<OPWrapper1>().Ordering(x =>
            {
                x.MustBeBeforeAuthorization();
            });

            graph = registry.BuildGraph();
        }