Exemplo n.º 1
0
        public void append_when_next_is_null()
        {
            action = ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null));
            var next = new RenderJsonNode(typeof (Model2));

            action.AddToEnd(next);

            action.Next.ShouldBeTheSameAs(next);
        }
Exemplo n.º 2
0
 public bool Equals(RenderJsonNode other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other._modelType, _modelType));
 }
Exemplo n.º 3
0
        public void enrich_puts_the_new_chain_node_directly_behind_the_call()
        {
            action = ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null));
            var next = new RenderJsonNode(typeof (Model2));

            action.AddToEnd(next);

            var enricher = new Wrapper(typeof (string));
            action.AddAfter(enricher);

            action.Next.ShouldBeTheSameAs(enricher);
            enricher.Next.ShouldBeTheSameAs(next);
        }
Exemplo n.º 4
0
        public void write_with_a_single_output()
        {
            var chain = new BehaviorChain();
            var node = new RenderJsonNode(typeof (RouteParameter));
            chain.AddToEnd(node);

            var tag = new HtmlTag("td");

            var column = new OutputColumn();
            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(node.Description);
        }
Exemplo n.º 5
0
        public void append_to_descendent_when_next_is_not_null()
        {
            action = ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null));
            var wrapper = new Wrapper(typeof (FakeBehavior));
            action.AddAfter(wrapper);

            var next = new RenderJsonNode(typeof (Model2));

            action.AddToEnd(next);

            action.Next.ShouldBeTheSameAs(wrapper);
            wrapper.Next.ShouldBeTheSameAs(next);

            action.ShouldHaveTheSameElementsAs(wrapper, next);
        }
Exemplo n.º 6
0
        public void write_with_multiple_outputs()
        {
            var chain = new BehaviorChain();
            var json = new RenderJsonNode(typeof (RouteParameter));
            chain.AddToEnd(json);

            var text = new RenderTextNode<RouteParameter>();
            chain.AddToEnd(text);

            var tag = new HtmlTag("td");

            var column = new OutputColumn();
            column.WriteBody(chain, null, tag);

            tag.Text().ShouldEqual(json.Description + ", " + text.Description);
        }
        public void Configure(BehaviorGraph graph)
        {
            graph.Actions().Where(x => x.HasOutputBehavior() && x.OutputType().CanBeCastTo<IEnumerable>() && getRenderViewNode(x) != null)
                .Each(x =>
                {
                    var modelType = x.OutputType();
                    var view = getRenderViewNode(x);
                    var json = new RenderJsonNode(modelType);
                    var xml = new RenderXmlNode(modelType);

                    var variableOut = new VariableOutputNode();
                    view.ReplaceWith(variableOut);

                    variableOut.AddOutput(a => a.RenderFormat == "json", json);
                    variableOut.AddOutput(a => a.RenderFormat == "xml", xml);
                    variableOut.AddOutput(a => a.AcceptsFormat("text/html"), view);
                    variableOut.AddOutput(a => a.AcceptsFormat("application/xml"), xml);
                    variableOut.AddOutput(a => a.AcceptsFormat("application/json"), json);

                    graph.Observer.RecordCallStatus(x, "Adding variable output behavior");
                });
        }
Exemplo n.º 8
0
        public void Configure(BehaviorGraph graph)
        {
            graph.Actions().Where(x => x.HasOutputBehavior() && x.OutputType().CanBeCastTo<IEnumerable>())
                .Each(x =>
                {
                    OutputNode output = null;

                    var modelType = x.OutputType();
                    var view = getRenderViewNode(x);
                    if (x.HasOutputBehavior())
                    {
                        output = view ?? x.OfType<OutputNode>().FirstOrDefault();
                    }
                    var json = new RenderJsonNode(modelType);

                    var variableOut = new VariableOutputNode();

                    if (output != null)
                        output.ReplaceWith(variableOut);
                    else
                    {
                        x.AddToEnd(variableOut);
                    }

                    variableOut.AddOutput(a => a.RenderFormat == "json", json);
                    variableOut.AddOutput(a => a.AcceptsFormat("application/json"), json);
                    variableOut.AddOutput(a => a.AcceptsFormat("text/javascript"), json);

                    if (view != null)
                    {
                        variableOut.AddOutput(a => a.AcceptsFormat("text/html"), view);
                        variableOut.AddOutput(a => a.AcceptsFormat("*/*"), view);
                    }

                    graph.Observer.RecordCallStatus(x, "Adding variable output behavior");

                });

            graph.Actions().Where(x => x.OutputType().CanBeCastTo<IReturnJson>())
                .Each(x =>
                          {
                              OutputNode output = null;
                              var view = getRenderViewNode(x);

                              if (x.HasOutputBehavior())
                              {
                                  output = view ?? x.OfType<OutputNode>().FirstOrDefault();
                              }

                              var modelType = x.OutputType();

                              var json = new CustomRenderJsonNode(modelType);

                              var variableOut = new VariableOutputNode();

                              if (output != null)
                                  output.ReplaceWith(variableOut);
                              else
                              {
                                  x.AddToEnd(variableOut);
                              }

                              variableOut.AddOutput(a => a.RenderFormat == "json", json);
                              variableOut.AddOutput(a => a.AcceptsFormat("application/json"), json);
                              variableOut.AddOutput(a => a.AcceptsFormat("text/javascript"), json);

                              if (view != null)
                              {
                                  variableOut.AddOutput(a => a.AcceptsFormat("text/html"), view);
                                  variableOut.AddOutput(a => a.AcceptsFormat("*/*"), view);
                              }

                              graph.Observer.RecordCallStatus(x, "Adding variable output behavior");
                          });
        }
Exemplo n.º 9
0
 public bool Equals(RenderJsonNode other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._modelType, _modelType);
 }
Exemplo n.º 10
0
 public void SetUp()
 {
     node = new RenderJsonNode(typeof(FakeJsonModel));
 }