public void SetUp()
        {
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <RestController1>();

            // TODO -- this really needs to be done with a Bottle
            var typePool = new TypePool();

            typePool.AddAssembly(Assembly.GetExecutingAssembly());

            registry.Policies.Add(new ConnegAttachmentPolicy(typePool));
            registry.Services <ResourcesServiceRegistry>();


            registry.Policies.Add(x => {
                x.Where.AnyActionMatches(
                    call => call.HandlerType == typeof(RestController1) && !call.Method.Name.StartsWith("Not"));

                x.Conneg.ApplyConneg();
            });

            theBehaviorGraph = BehaviorGraph.BuildFrom(registry);
            theConnegGraph   = new ConnegGraph(theBehaviorGraph);
        }
コード例 #2
0
        void IResourceRegistration.Modify(ConnegGraph graph, BehaviorGraph behaviorGraph)
        {
            var enumerableType = typeof(IEnumerable <>).MakeGenericType(typeof(T));

            graph.OutputNodesFor(enumerableType).Each(outputNode =>
            {
                outputNode.Writers.AddToEnd(new FeedWriterNode <T>(this, outputNode.ResourceType));
            });
        }
コード例 #3
0
        private void modifyForEnumerableOfTargetType(ConnegGraph graph)
        {
            var enumerableType = typeof(IEnumerable <>).MakeGenericType(typeof(T));

            graph.OutputNodesThatCanBeCastTo(enumerableType).Each(outputNode =>
            {
                outputNode.AddWriter(new FeedWriterNode <T>(this, FeedSourceType.enumerable, outputNode.InputType));
            });
        }
コード例 #4
0
        public void SetUp()
        {
            var registry = new FubuRegistry();

            registry.Actions.IncludeType <RestController1>();

            registry.Media.ApplyContentNegotiationToActions(x => x.HandlerType == typeof(RestController1) && !x.Method.Name.StartsWith("Not"));

            theBehaviorGraph = registry.BuildGraph();
            theConnegGraph   = new ConnegGraph(theBehaviorGraph);
        }
コード例 #5
0
        public void just_having_a_resource_turns_the_formatters_to_none()
        {
            // Default condition first, before the resource is applied
            theBehaviorGraph.BehaviorFor <RestController1>(x => x.Find(null)).RemoveConneg();
            theBehaviorGraph.BehaviorFor <RestController1>(x => x.Find(null)).ApplyConneg();
            theBehaviorGraph.BehaviorFor <RestController1>(x => x.Find(null))
            .ConnegOutputNode().FormatterUsage.ShouldEqual(FormatterUsage.all);

            theConnegGraph = new ConnegGraph(theBehaviorGraph);

            // Now apply a resource
            new Resource <Address>().As <IResourceRegistration>().Modify(theConnegGraph, theBehaviorGraph);

            // Default condition first, before the resource is applied
            theBehaviorGraph.BehaviorFor <RestController1>(x => x.Find(null))
            .ConnegOutputNode().FormatterUsage.ShouldEqual(FormatterUsage.none);
        }
コード例 #6
0
        public void Configure(BehaviorGraph graph)
        {
            _filters.Each(filter =>
            {
                graph.Behaviors.Where(filter.Filter).ToList().Each(chain =>
                {
                    // TODO -- need to do better config logging here
                    chain.ApplyConneg();
                });
            });

            var connegGraph = new ConnegGraph(graph);

            // TODO -- add some config logging here
            _types
                .TypesMatching(x => x.IsConcreteTypeOf<IResourceRegistration>() && !x.IsOpenGeneric())
                .Each(t => t.Create<IResourceRegistration>().Modify(connegGraph, graph));
        }
        public void just_having_a_resource_turns_the_formatters_to_none()
        {
            // Default condition first, before the resource is applied
            var theChain = theBehaviorGraph.BehaviorFor <RestController1>(x => x.Find(null));

            theChain.RemoveConneg();
            theChain.ApplyConneg();
            theChain.Output.UsesFormatter <JsonFormatter>().ShouldBeTrue();
            theChain.Output.UsesFormatter <XmlFormatter>().ShouldBeTrue();

            theConnegGraph = new ConnegGraph(theBehaviorGraph);

            // Now apply a resource
            new Resource <Address>().As <IResourceRegistration>().Modify(theConnegGraph, theBehaviorGraph);

            // Default condition first, before the resource is applied
            theChain.Output.UsesFormatter <JsonFormatter>().ShouldBeFalse();
            theChain.Output.UsesFormatter <XmlFormatter>().ShouldBeFalse();
        }
コード例 #8
0
 private static void applySettings(ConfigGraph config, BehaviorGraph graph)
 {
     config.Imports.Each(x => x.InitializeSettings(graph));
     config.Settings.Each(x => x.Alter(graph.Settings));
     graph.Settings.Alter <ConnegSettings>(x => x.Graph = ConnegGraph.Build(graph));
 }
コード例 #9
0
        void IResourceRegistration.Modify(ConnegGraph graph, BehaviorGraph behaviorGraph)
        {
            modifyForEnumerableOfTargetType(graph);

            modifyForEnumerableOfValuesOfTargetType(graph);
        }
コード例 #10
0
ファイル: ConnegSettings.cs プロジェクト: zzekikaya/fubumvc
 public void ReadConnegGraph(BehaviorGraph graph)
 {
     _graph = ConnegGraph.Build(graph);
 }