Пример #1
0
        public void has_input_depends_on_the_input_node_now()
        {
            var chain = new BehaviorChain();

            chain.AddToEnd(ActionCall.For <OneController>(x => x.Query(null)));

            chain.HasReaders().ShouldBeFalse();

            chain.Input.AddFormatter <JsonFormatter>();

            chain.HasReaders().ShouldBeTrue();
        }
Пример #2
0
        // SAMPLE: conneg-manipulation
        public static void MessWithConneg(BehaviorChain chain)
        {
            // Remove all readers
            chain.Input.ClearAll();

            // Accept 'application/x-www-form-urlencoded' with model binding
            chain.Input.Add(typeof(ModelBindingReader <>));

            // Add basic Json reading
            chain.Input.Add(new NewtonsoftJsonFormatter());

            // Query whether or not the chain uses the basic Json reading
            var readsJson = chain.Input.CanRead(MimeType.Json);

            // Add a completely custom Reader
            chain.Input
            .Add(new SpecialContentMediaReader());

            // Are there any Readers?
            chain.HasReaders();

            // Is there any output?
            chain.HasOutput();

            // Remove all writers
            chain.Output.ClearAll();
        }
        public void remove_conneg()
        {
            theChain.RemoveConneg();

            theChain.HasReaders().ShouldBeFalse();
            theChain.Output.Writers.Any().ShouldBeFalse();
        }
Пример #4
0
        // SAMPLE: conneg-manipulation
        public static void MessWithConneg(BehaviorChain chain)
        {
            // Remove all readers
            chain.Input.ClearAll();

            // Accept 'application/x-www-form-urlencoded' with model binding
            chain.Input.AllowHttpFormPosts = true;

            // Add basic Json reading
            chain.Input.AddFormatter <JsonFormatter>();

            // Query whether or not the chain uses the basic Json reading
            bool readsJson = chain.Input.UsesFormatter <JsonFormatter>();

            // Add a completely custom Reader
            var specialReader = chain.Input
                                .AddReader <SpecialContentMediaReader>();

            // Reorder the special reader to move it to the first
            // as the default
            specialReader.MoveToFront();

            // Add a new Reader as the last reader
            chain.Input.Readers.AddToEnd(new ModelBind(chain.InputType()));

            // Are there any Readers?
            chain.HasReaders();

            // Is there any output?
            chain.HasOutput();


            // Add the default Conneg policies to this chain
            // model binding, json, or xml in and json or xml out
            chain.ApplyConneg();

            // Manipulate an existing writer
            var writer = chain.Output.Writers.First();

            manipulateWriter(writer);

            // Remove all writers
            chain.Output.ClearAll();

            // Add the HtmlStringWriter
            chain.Output.AddHtml();

            // Add basic Json output
            chain.OutputJson();

            // Add basic Xml output
            chain.OutputXml();
        }
        public static void RemoveConneg(this BehaviorChain chain)
        {
            if (chain.HasReaders())
            {
                chain.Input.ClearAll();
            }

            if (chain.HasOutput())
            {
                chain.Output.ClearAll();
            }
        }
Пример #6
0
        public void has_input_depends_on_the_input_node_now()
        {
            var chain = new BehaviorChain();
            chain.AddToEnd(ActionCall.For<OneController>(x => x.Query(null)));

            chain.HasReaders().ShouldBeFalse();

            chain.Input.AddFormatter<JsonFormatter>();

            chain.HasReaders().ShouldBeTrue();
        }