public static void AlterConnegOutput(this BehaviorChain chain, Action <ConnegOutputNode> configure) { var node = chain.ConnegOutputNode(); if (node != null) { configure(node); } }
public void methods_that_return_a_json_message_should_output_json() { BehaviorChain chain = chainFor(x => x.OutputJson1()); chain.ConnegOutputNode().SelectedFormatterTypes.ShouldHaveTheSameElementsAs(typeof(JsonFormatter)); chainFor(x => x.OutputJson2()).Top.Any(x => x.GetType() == typeof(ConnegOutputNode)).ShouldBeTrue(); chainFor(x => x.OutputJson3()).Top.Any(x => x.GetType() == typeof(ConnegOutputNode)).ShouldBeTrue(); }
public static bool IsAsymmetricJson(this BehaviorChain chain) { if (chain.ConnegInputNode() == null && chain.ConnegOutputNode() == null) { return(false); } if (chain.ActionOutputType() != null) { var output = chain.ConnegOutputNode(); if (output.SelectedFormatterTypes.Count() != 1) { return(false); } if (output.SelectedFormatterTypes.Single() != typeof(JsonFormatter)) { return(false); } } if (chain.InputType() != null) { var input = chain.ConnegInputNode(); if (!input.AllowHttpFormPosts) { return(false); } if (input.SelectedFormatterTypes.Count() != 1) { return(false); } if (input.SelectedFormatterTypes.Single() != typeof(JsonFormatter)) { return(false); } } return(true); }
// This should not do anything if there are conneg nodes public static void ApplyConneg(this BehaviorChain chain) { var inputType = chain.InputType(); if (chain.ConnegInputNode() == null && inputType != null) { var inputNode = new ConnegInputNode(inputType); var action = chain.FirstCall(); action.AddBefore(inputNode); } var actionOutputType = chain.ActionOutputType(); if (chain.ConnegOutputNode() == null && actionOutputType != null && actionOutputType != typeof(void) && actionOutputType != typeof(HttpStatusCode)) { var outputNode = new ConnegOutputNode(actionOutputType); var action = chain.Last(x => x is ActionCall); action.AddAfter(outputNode); } }
public static void OutputXml(this BehaviorChain chain) { chain.ApplyConneg(); chain.ConnegOutputNode().UseFormatter <XmlFormatter>(); }
public static bool HasConnegOutput(this BehaviorChain chain) { return(chain.ConnegOutputNode() != null); }