Esempio n. 1
0
        public void has_resource_type()
        {
            theChain.HasResourceType().ShouldBeFalse();

            // Void does not count
            theChain.AddToEnd(ActionCall.For <FakeActions>(x => x.Go(null)));
            theChain.HasResourceType().ShouldBeFalse();

            theChain.AddToEnd(none);
            theChain.HasResourceType().ShouldBeFalse();

            theChain.AddToEnd(ints);
            theChain.HasResourceType().ShouldBeTrue();
        }
Esempio n. 2
0
        public static BehaviorChain ReplaceOutputFormatters <T>(this BehaviorChain chain) where T : IFormatter
        {
            var mimeTypes = typeof(T).GetCustomAttribute <MimeTypeAttribute>();

            if (chain.HasResourceType() && !chain.Output.Writers.Any(y => y is ViewNode))
            {
                if (chain.Output.Writers != null && mimeTypes != null)
                {
                    var writer = chain.Output.Writers.FirstOrDefault(
                        x => x.Mimetypes.Any(y => mimeTypes.MimeTypes.Any(z => z == y)));
                    if (writer != null)
                    {
                        writer.Remove();
                    }
                }
                chain.Output.AddFormatter <T>();
            }
            return(chain);
        }
        /// <summary>
        /// Sets up very basic content negotiation for an endpoint.
        /// Accepts http form posts, xml, and json
        /// Returns xml or json
        /// </summary>
        /// <param name="chain"></param>
        public static void ApplyConneg(this BehaviorChain chain)
        {
            chain.RemoveConneg();

            if (chain.InputType() != null)
            {
                chain.Input.ClearAll();
                chain.Input.AllowHttpFormPosts = true;
                chain.Input.AddFormatter <JsonFormatter>();
                chain.Input.AddFormatter <XmlFormatter>();
            }

            if (chain.HasResourceType())
            {
                chain.Output.ClearAll();
                chain.Output.AddFormatter <JsonFormatter>();
                chain.Output.AddFormatter <XmlFormatter>();
            }
        }