예제 #1
0
        public void SetUp()
        {
            theHttpRequest = OwinHttpRequest.ForTesting();
            theHttpRequest.FullUrl("http://server/fubu");


            var registry = new FubuRegistry();

            registry.Actions.IncludeType <OneController>();
            registry.Actions.IncludeType <TwoController>();
            registry.Actions.IncludeType <QueryStringTestController>();
            registry.Actions.IncludeType <OnlyOneActionController>();


            registry.Configure(x => { x.TypeResolver.AddStrategy <UrlModelForwarder>(); });

            //registry.Routes.HomeIs<DefaultModel>();

            graph = BehaviorGraph.BuildFrom(registry);

            var resolver    = graph.Services.DefaultServiceFor <ITypeResolver>().Value;
            var urlResolver = new ChainUrlResolver(theHttpRequest);

            urls = new UrlRegistry(new ChainResolutionCache((ITypeResolver)resolver, graph), urlResolver,
                                   new JQueryUrlTemplate(), theHttpRequest);
        }
예제 #2
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();
        }
        public void SetUp()
        {
            _theCurrentHttpRequest = new StubCurrentHttpRequest {
                TheApplicationRoot = "http://server/fubu"
            };



            var registry = new FubuRegistry();

            registry.Actions.IncludeType <OneController>();
            registry.Actions.IncludeType <TwoController>();
            registry.Actions.IncludeType <QueryStringTestController>();
            registry.Actions.IncludeType <OnlyOneActionController>();

            registry.Routes
            .IgnoreControllerFolderName()
            .IgnoreNamespaceForUrlFrom <UrlRegistryIntegrationTester>()
            .IgnoreClassSuffix("Controller");


            registry.Configure(x =>
            {
                x.TypeResolver.AddStrategy <UrlModelForwarder>();
            });

            registry.Routes.HomeIs <DefaultModel>();

            graph = BehaviorGraph.BuildFrom(registry);

            var resolver = graph.Services.DefaultServiceFor <ITypeResolver>().Value;

            urls = new UrlRegistry(new ChainResolutionCache((ITypeResolver)resolver, graph), new JQueryUrlTemplate(), _theCurrentHttpRequest);
        }
예제 #4
0
        public void Configure(FubuRegistry registry)
        {
            MimeType.New("text/jsx", ".jsx");

            registry.Services <DiagnosticServiceRegistry>();

            registry.AlterSettings <AssetSettings>(x => x.AllowableExtensions.Add(".jsx"));

            registry.AlterSettings <DiagnosticsSettings>(x =>
            {
                x.TraceLevel = TraceLevel.Verbose;
            });

            registry.Configure(graph => {
                var settings = graph.Settings.Get <DiagnosticsSettings>();

                if (settings.TraceLevel == TraceLevel.Verbose)
                {
                    graph.Services.Clear(typeof(IBindingLogger));
                    graph.Services.AddService <IBindingLogger, RecordingBindingLogger>();

                    graph.Services.Clear(typeof(IBindingHistory));
                    graph.Services.AddService <IBindingHistory, BindingHistory>();

                    graph.Services.AddService <ILogListener, RequestTraceListener>();
                }

                if (settings.TraceLevel == TraceLevel.Production)
                {
                    graph.Services.AddService <ILogListener, ProductionModeTraceListener>();
                }
            });
        }
        public void Configure(FubuRegistry registry)
        {
            registry.Configure(graph => {
                graph.Settings.Get<ViewEngines>().UseGraph(graph);
            });

            
        }
예제 #6
0
 public void Configure(FubuRegistry registry)
 {
     registry.Configure(graph =>
     {
         graph.Behaviors.Where(PassportConfiguration.RestrictedAction).Each(c =>
         {
             var x = new Wrapper(typeof(AuthenticationPolicy));
             c.Prepend(x);
         });
     });
 }
예제 #7
0
        private AuthorizationPreviewService withAuthorizationRules(Action <BehaviorGraph> configure)
        {
            var registry = new FubuRegistry();


            registry.Actions.IncludeType <OneController>();
            registry.Actions.IncludeType <TwoController>();

            registry.Configure(x =>
            {
                x.TypeResolver.AddStrategy <UrlModelForwarder>();
            });

            registry.Configure(configure);

            var container = new Container();

            FubuApplication.For(() => registry).StructureMap(container).Bootstrap();

            return(container.GetInstance <AuthorizationPreviewService>());
        }
예제 #8
0
        private ExtensionsExpression register(Action <ContentExtensionGraph> configure)
        {
            _registry.Services(x => x.SetServiceIfNone(new ContentExtensionGraph()));

            _registry.Configure(graph =>
            {
                var contentGraph = graph.Services.DefaultServiceFor <ContentExtensionGraph>().Value as ContentExtensionGraph;
                configure(contentGraph);
            });

            return(this);
        }
예제 #9
0
        public void Configure(FubuRegistry registry)
        {
            registry.Route("_fubu/getting_started").Calls <StartingController>(x => x.GettingStarted());

            registry.Configure(graph =>
            {
                var chain = graph.FindHomeChain();
                if (chain == null)
                {
                    graph.BehaviorFor <StartingController>(x => x.GettingStarted()).Route = new RouteDefinition(string.Empty);
                }
            });
        }
예제 #10
0
        private ExtensionsExpression register(Action <ContentExtensionGraph> configure)
        {
            // TODO -- Gotta do the registration trick in FubuMVC.Core for the settings collection
            //_registry.AlterSettings(configure);
            _registry.Services(x => x.SetServiceIfNone(new ContentExtensionGraph()));

            _registry.Configure(graph =>
            {
                var contentGraph = graph.Settings.Get <ContentExtensionGraph>();
                configure(contentGraph);
            });

            return(this);
        }
예제 #11
0
        public static void RegisterPartials(this FubuRegistry registry,
                                            Action <IPartialViewTypeRegistrationExpression> registration)
        {
            registry.Configure(x =>
            {
                var services = x.Services;

                services.SetServiceIfNone(typeof(IPartialViewTypeRegistry), ObjectDef.ForValue(new PartialViewTypeRegistry()));
                var partialRegistry = services.FindAllValues <IPartialViewTypeRegistry>().FirstOrDefault();

                var expression = new PartialViewTypeRegistrationExpression(partialRegistry);
                registration(expression);
            });
        }
예제 #12
0
        public void Configure(FubuRegistry registry)
        {
            registry.Configure(graph => {
                graph.Settings.Get <ViewEngines>().UseGraph(graph);
            });

            registry.AlterSettings <CommonViewNamespaces>(x =>
            {
                x.Add(typeof(VirtualPathUtility).Namespace); // System.Web
                x.AddForType <string>();                     // System
                x.AddForType <FileSet>();                    // FubuCore
                x.AddForType <ParallelQuery>();              // System.Linq
                x.AddForType <HtmlTag>();                    // HtmlTags
            });
        }
        public void Configure(FubuRegistry registry)
        {
            registry.Configure(graph => {
                graph.Settings.Get<ViewEngines>().UseGraph(graph);
            });

            registry.AlterSettings<CommonViewNamespaces>(x =>
            {
                x.Add(typeof(VirtualPathUtility).Namespace); // System.Web
                x.AddForType<string>(); // System
                x.AddForType<FileSet>(); // FubuCore
                x.AddForType<ParallelQuery>(); // System.Linq
                x.AddForType<HtmlTag>(); // HtmlTags 
            });
        }
예제 #14
0
        public void Configure(FubuRegistry registry)
        {
            registry.Services(addServices);
            registry.Services(addActivators);
            registry.Services(setupAssetCaching);

            registry.Configure(graph =>
            {
                BehaviorChain chain = createAssetContentChain(graph);
                chain.Filters.Add(new AssetEtagInvocationFilter(_assetCache));

                addCaching(chain);
                addWritingAction(chain);
            });
        }
예제 #15
0
        public void Configure(FubuRegistry registry)
        {
            registry.Services(addServices);
            registry.Services(addActivators);
            registry.Services(setupAssetCaching);

            registry.Configure(graph =>
            {
                var chain = createAssetContentChain(graph);
                chain.Filters.Add(new AssetEtagInvocationFilter(_assetCache));

                addCaching(chain);
                addWritingAction(chain);
            });
        }
예제 #16
0
        private AuthorizationPreviewService withAuthorizationRules(Action <BehaviorGraph> configure)
        {
            var registry = new FubuRegistry();


            registry.Actions.IncludeType <OneController>();
            registry.Actions.IncludeType <TwoController>();

            registry.Configure(configure);


            _runtime = registry.ToRuntime();


            return(_runtime.Get <AuthorizationPreviewService>());
        }
예제 #17
0
        public void use_custom_auth_handler_on_only_one_endpoint()
        {
            var registry = new FubuRegistry();

            registry.Configure(x => {
                x.BehaviorFor <AuthorizedEndpoint>(_ => _.get_authorized_text()).Authorization.FailureHandler <CustomAuthHandler>();
            });

            AuthorizationCheck.IsAuthorized = false;
            using (var server = FubuApplication.For(registry).StructureMap().RunEmbeddedWithAutoPort())
            {
                server.Endpoints.Get <AuthorizedEndpoint>(x => x.get_authorized_text())
                .StatusCodeShouldBe(HttpStatusCode.Forbidden)
                .ReadAsText().ShouldEqual("you are forbidden!");
            }
        }
        public void can_register_new_type_resolution_strategies()
        {
            var registry = new FubuRegistry();

            registry.Configure(x =>
            {
                x.TypeResolver.AddStrategy <ProxyDetector>();
            });

            var graph = BehaviorGraph.BuildFrom(registry);


            var resolver = graph.Services.DefaultServiceFor <ITypeResolver>().Value.ShouldBeOfType <TypeResolver>();

            resolver.ResolveType(new Proxy <UniqueInput>()).ShouldEqual(typeof(UniqueInput));
        }
예제 #19
0
        private BehaviorGraph setupActions()
        {
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <RouteAliasAction1>();

            registry.Configure(x =>
            {
                theRouteDefinitionAlias       = new RouteDefinition("{Client}/");
                theRouteDefinitionAlias.Input = MockRepository.GenerateMock <IRouteInput>();
                theRouteDefinitionAlias.Input.Stub(_ => _.Rank).Return(5);

                x.ChainFor <RouteAliasAction1>(_ => _.M1()).As <RoutedChain>().AddRouteAlias(theRouteDefinitionAlias);
            });

            return(BehaviorGraph.BuildFrom(registry));
        }
        private BehaviorGraph setupActions()
        {
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <Action1>();
            registry.Actions.IncludeType <Action2>();
            registry.Actions.IncludeType <Action3>();
            registry.Actions.DisableDefaultActionSource();

            registry.Configure(x => {
                var routeDefinition   = new RouteDefinition("{Client}/");
                routeDefinition.Input = MockRepository.GenerateMock <IRouteInput>();
                routeDefinition.Input.Stub(_ => _.Rank).Return(5);

                x.ChainFor <Action1>(_ => _.M1()).As <RoutedChain>().AddRouteAlias(routeDefinition);
            });

            return(BehaviorGraph.BuildFrom(registry));
        }
        private AuthorizationPreviewService withAuthorizationRules(Action <BehaviorGraph> configure)
        {
            var registry = new FubuRegistry();


            registry.Actions.IncludeType <OneController>();
            registry.Actions.IncludeType <TwoController>();

            registry.ResolveTypes(x => x.AddStrategy <UrlModelForwarder>());

            registry.Configure(configure);

            var container    = new Container();
            var bootstrapper = new StructureMapBootstrapper(container, registry);

            bootstrapper.Bootstrap(new List <RouteBase>());

            return(container.GetInstance <AuthorizationPreviewService>());
        }
예제 #22
0
        public void adds_the_authentication_node_if_it_exists()
        {
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <AuthenticatedEndpoint>();
            registry.Configure(
                graph => { graph.Chains.OfType <RoutedChain>().Each(x => x.Authentication = new AuthNode()); });

            using (var runtime = registry.ToRuntime())
            {
                runtime.Behaviors.ChainFor <AuthenticatedEndpoint>(x => x.get_hello())
                .First().ShouldBeOfType <AuthNode>();
            }


            var chain = new RoutedChain("something");
            var auth  = new AuthNode();

            chain.Authentication = auth;
        }
예제 #23
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;
        }
        void IFubuRegistryExtension.Configure(FubuRegistry registry)
        {
            registry.Configure(graph =>
            {
                Type runnerType = DetermineRunnerType();


                var method = runnerType.GetMethod("Run");

                var call  = new ActionCall(runnerType, method);
                var chain = new BehaviorChain();
                chain.AddToEnd(call);
                chain.Route = new RouteDefinition(DiagnosticConstants.UrlPrefix);
                chain.Route.Append("_data");
                chain.Route.Append(typeof(T).Name);

                chain.MakeAsymmetricJson();

                graph.AddChain(chain);
            });
        }
예제 #25
0
        public void use_custom_auth_handler_on_only_one_endpoint()
        {
            var registry = new FubuRegistry();

            registry.Configure(
                x =>
            {
                x.ChainFor <AuthorizedEndpoint>(_ => _.get_authorized_text())
                .Authorization.FailureHandler <CustomAuthHandler>();
            });

            AuthorizationCheck.IsAuthorized = false;
            using (var server = registry.ToRuntime())
            {
                server.Scenario(_ =>
                {
                    _.Get.Action <AuthorizedEndpoint>(x => x.get_authorized_text());

                    _.StatusCodeShouldBe(HttpStatusCode.Redirect);
                    _.Header(HttpResponseHeaders.Location).SingleValueShouldEqual("/403");
                });
            }
        }
예제 #26
0
        void IFubuRegistryExtension.Configure(FubuRegistry registry)
        {
            var graph    = new HandlerGraph();
            var allCalls = allSources().SelectMany(x => x.FindCalls()).Distinct();

            graph.Add(allCalls);

            graph.ApplyPolicies(_localPolicies);

            registry.AlterSettings <HandlerGraph>(x => x.Import(graph));

            registry.AlterSettings <ChannelGraph>(channels => {
                _channelAlterations.Each(x => x(channels));
            });

            registry.Configure(behaviorGraph => {
                var channels = behaviorGraph.Settings.Get <ChannelGraph>();
                behaviorGraph.Services.Clear(typeof(ChannelGraph));
                behaviorGraph.Services.AddService(typeof(ChannelGraph), ObjectDef.ForValue(channels).AsSingleton());
            });

            _alterations.Each(x => x(registry));
        }
        public void SetUp()
        {
            var registry = new FubuRegistry();

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

            registry.Features.Diagnostics.Enable(TraceLevel.Verbose);


            BehaviorGraph.BuildFrom(registry);
        }
예제 #28
0
        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>();

            BehaviorGraph.BuildFrom(registry);
        }
        public void action_without_json_attributes_or_JsonMessage_input_model_has_no_conneg()
        {
            // You have to make the endpoint get some sort of reader/writer to test the negative case,
            // otherwise the default "use json & xml if nothing else is provided" convention
            // takes over
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <JsonController>();
            registry.Configure(graph =>
            {
                graph.Behaviors.Where(x => x.InputType() == typeof(Input1)).Each(chain =>
                {
                    chain.Input.AddFormatter <XmlFormatter>();
                    chain.Output.AddFormatter <XmlFormatter>();
                });
            });

            theGraph = BehaviorGraph.BuildFrom(registry);

            var theChain = theGraph.BehaviorFor(typeof(Input1));

            theChain.Input.UsesFormatter <JsonFormatter>().ShouldBeFalse();
            theChain.Output.UsesFormatter <JsonFormatter>().ShouldBeFalse();
        }
 public void Configure(FubuRegistry registry)
 {
     registry.Configure(graph => {
         graph.Settings.Get <ViewEngines>().UseGraph(graph);
     });
 }
예제 #31
0
        void IFeatureSettings.Apply(FubuRegistry registry)
        {
            if (!Enabled)
            {
                return;
            }

            registry.Actions.FindWith <SendsMessageActionSource>();
            registry.Policies.Global.Add <SendsMessageConvention>();

            registry.Policies.Global.Add <ApplyScheduledJobRouting>();
            registry.Services.IncludeRegistry <ScheduledJobServicesRegistry>();
            registry.Services.IncludeRegistry <MonitoringServiceRegistry>();
            registry.Policies.ChainSource <SystemLevelHandlers>();
            registry.Services.IncludeRegistry(new FubuTransportServiceRegistry(registry.Mode));
            registry.Services.IncludeRegistry <PollingServicesRegistry>();
            registry.Policies.Global.Add <StatefulSagaConvention>();

            // Just forcing it to get spun up.
            registry.AlterSettings <ChannelGraph>(x => {});
            registry.Handlers.Include <SystemLevelHandlers>();

            registry.Configure(graph =>
            {
                graph.Handlers.Each(chain =>
                {
                    // Apply the error handling node
                    chain.InsertFirst(new ExceptionHandlerNode(chain));

                    // Hate how we're doing this, but disable tracing
                    // on the polling job requests here.
                    if (chain.InputType().Closes(typeof(JobRequest <>)))
                    {
                        chain.Tags.Add(BehaviorChain.NoTracing);
                    }
                });
            });

            if (InMemoryTransport == InMemoryTransportMode.AllInMemory)
            {
                registry.Services.For <ITransport>().ClearAll();
                registry.Services.AddService <ITransport, InMemoryTransport>();

                SettingTypes.Each(settingType =>
                {
                    var settings = InMemory.InMemoryTransport.ToInMemory(settingType);
                    registry.Services.ReplaceService(settingType, new ObjectInstance(settings));
                });
            }

            if (InMemoryTransport != InMemoryTransportMode.Disabled)
            {
                registry.Services.AddService <ITransport, InMemoryTransport>();
            }

            registry.Policies.Global.Add <ReorderBehaviorsPolicy>(x =>
            {
                x.ThisNodeMustBeBefore <StatefulSagaNode>();
                x.ThisNodeMustBeAfter <HandlerCall>();
            });
        }
 public void Configure(FubuRegistry registry)
 {
     registry.Configure(graph => {
         graph.Services.AddService(graph.Settings.Get<CommonViewNamespaces>());
     });
 }
예제 #33
0
        void IFeatureSettings.Apply(FubuRegistry registry)
        {
            if (!Enabled) return;

            registry.Actions.FindWith<SendsMessageActionSource>();
            registry.Policies.Global.Add<SendsMessageConvention>();

            registry.Policies.Global.Add<ApplyScheduledJobRouting>();
            registry.Services.IncludeRegistry<ScheduledJobServicesRegistry>();
            registry.Services.IncludeRegistry<MonitoringServiceRegistry>();
            registry.Policies.ChainSource<SystemLevelHandlers>();
            registry.Services.IncludeRegistry(new FubuTransportServiceRegistry(registry.Mode));
            registry.Services.IncludeRegistry<PollingServicesRegistry>();
            registry.Policies.Global.Add<StatefulSagaConvention>();
            registry.Policies.Global.Add<AsyncHandlingConvention>();

            // Just forcing it to get spun up.
            registry.AlterSettings<ChannelGraph>(x => {});
            registry.Handlers.Include<SystemLevelHandlers>();

            registry.Configure(graph =>
            {
                graph.Handlers.Each(chain =>
                {
                    // Apply the error handling node
                    chain.InsertFirst(new ExceptionHandlerNode(chain));

                    // Hate how we're doing this, but disable tracing
                    // on the polling job requests here.
                    if (chain.InputType().Closes(typeof (JobRequest<>)))
                    {
                        chain.Tags.Add(BehaviorChain.NoTracing);
                    }
                });
            });

            if (InMemoryTransport == InMemoryTransportMode.AllInMemory)
            {
                registry.Services.For<ITransport>().ClearAll();
                registry.Services.AddService<ITransport, InMemoryTransport>();

                SettingTypes.Each(settingType =>
                {
                    var settings = InMemory.InMemoryTransport.ToInMemory(settingType);
                    registry.Services.ReplaceService(settingType, new ObjectInstance(settings));
                });
            }

            if (InMemoryTransport != InMemoryTransportMode.Disabled)
            {
                registry.Services.AddService<ITransport, InMemoryTransport>();
            }

            registry.Policies.Global.Add<ReorderBehaviorsPolicy>(x =>
            {
                x.ThisNodeMustBeBefore<StatefulSagaNode>();
                x.ThisNodeMustBeAfter<HandlerCall>();
            });
        }