Permalink
Browse files

added that default conneg policy (finally)

  • Loading branch information...
jeremydmiller committed May 20, 2012
1 parent d790bda commit c35263aa6e6871eaef01364a4696b58b7ac43616
@@ -98,6 +98,8 @@ private static IEnumerable<IConfigurationAction> fullGraphPolicies()
yield return new StringOutputPolicy();
yield return new HtmlTagOutputPolicy();
+ yield return new DefaultOutputPolicy();
+
yield return new AttachAuthorizationPolicy();
yield return new AttachInputPolicy();
yield return new AttachOutputPolicy();
@@ -97,6 +97,7 @@
<Compile Include="Endpoints\EndpointInvocation.cs" />
<Compile Include="Endpoints\HttpResponse.cs" />
<Compile Include="Endpoints\WebRequestResponseExtensions.cs" />
+ <Compile Include="Registration\Conventions\DefaultOutputPolicy.cs" />
<Compile Include="Runtime\Conditionals\Always.cs" />
<Compile Include="Behaviors\Conditional\ConditionalBehavior.cs" />
<Compile Include="Behaviors\Conditional\ConditionalBehaviorInvoker.cs" />
@@ -0,0 +1,17 @@
+using System;
+using System.Linq;
+using System.Collections.Generic;
+using FubuMVC.Core.Resources.Conneg;
+
+namespace FubuMVC.Core.Registration.Conventions
+{
+ public class DefaultOutputPolicy : IConfigurationAction
+ {
+ public void Configure(BehaviorGraph graph)
+ {
+ graph.Behaviors
+ .Where(x => x.HasResourceType() && !x.HasOutput())
+ .Each(x => x.ApplyConneg());
+ }
+ }
+}
@@ -237,6 +237,7 @@
<Compile Include="Registration\BehaviorAggregatorTester.cs" />
<Compile Include="Registration\Conventions\actions_that_return_IDictionary_are_json.cs" />
<Compile Include="Registration\Conventions\AsyncContinueWithHandlerConventionTester.cs" />
+ <Compile Include="Registration\Conventions\DefaultConnegOutputIsAppliedToAnyEndpointWithoutAnyPriorOutputTester.cs" />
<Compile Include="Registration\Conventions\Handlers\Posts\PostHandler.cs" />
<Compile Include="Registration\Conventions\JsonAttributeTesting.cs" />
<Compile Include="Registration\Conventions\MediaExpressionAndConnegAttachmentPolicyTester.cs" />
@@ -0,0 +1,39 @@
+using FubuMVC.Core;
+using FubuMVC.Core.Runtime.Formatters;
+using NUnit.Framework;
+using FubuTestingSupport;
+using FubuMVC.Core.Resources.Conneg;
+
+namespace FubuMVC.Tests.Registration.Conventions
+{
+ [TestFixture]
+ public class DefaultConnegOutputIsAppliedToAnyEndpointWithoutAnyPriorOutputTester
+ {
+ [Test]
+ public void applies_conneg()
+ {
+ var registry = new FubuRegistry();
+ registry.Actions.IncludeType<SomeController>();
+
+ var chain = registry.BuildGraph().BehaviorFor<SomeController>(x => x.Go(null));
+
+ chain.Output.UsesFormatter<JsonFormatter>();
+ chain.Output.UsesFormatter<XmlFormatter>();
+
+ chain.Input.AllowHttpFormPosts.ShouldBeTrue();
+ chain.Input.UsesFormatter<JsonFormatter>();
+ chain.Input.UsesFormatter<XmlFormatter>();
+ }
+
+ public class SomeInput{}
+ public class SomeResource{}
+
+ public class SomeController
+ {
+ public SomeResource Go(SomeInput input)
+ {
+ return new SomeResource();
+ }
+ }
+ }
+}
@@ -39,9 +39,7 @@ public void apply_content_by_action()
chainFor(x => x.C()).HasConnegOutput().ShouldBeTrue();
chainFor(x => x.D()).HasConnegOutput().ShouldBeTrue();
chainFor(x => x.E()).HasConnegOutput().ShouldBeTrue();
-
- chainFor(x => x.A()).HasConnegOutput().ShouldBeFalse();
- chainFor(x => x.B()).HasConnegOutput().ShouldBeFalse();
+
}
[Test]
@@ -51,10 +49,11 @@ public void apply_content_by_looking_at_a_chain()
chainFor(x => x.A()).HasConnegOutput().ShouldBeTrue();
- chainFor(x => x.B()).HasConnegOutput().ShouldBeFalse();
- chainFor(x => x.C()).HasConnegOutput().ShouldBeFalse();
- chainFor(x => x.D()).HasConnegOutput().ShouldBeFalse();
- chainFor(x => x.E()).HasConnegOutput().ShouldBeFalse();
+ // Pretty close to killing this altogether
+ //chainFor(x => x.B()).HasConnegOutput().ShouldBeFalse();
+ //chainFor(x => x.C()).HasConnegOutput().ShouldBeFalse();
+ //chainFor(x => x.D()).HasConnegOutput().ShouldBeFalse();
+ //chainFor(x => x.E()).HasConnegOutput().ShouldBeFalse();
}
}
@@ -60,14 +60,6 @@ public void automatically_output_methods_that_return_string_as_text_if_there_is_
behavior.ShouldBeOfType<OutputNode>().Writers.Single().ShouldBeOfType<WriteString>();
}
- [Test]
- public void methods_that_do_not_return_a_json_message_should_not_output_json()
- {
- chainFor(x => x.NotOutputJson1()).Top.Any(x => x.GetType() == typeof (OutputNode)).ShouldBeFalse();
- chainFor(x => x.NotOutputJson2()).Top.Any(x => x.GetType() == typeof (OutputNode)).ShouldBeFalse();
- chainFor(x => x.NotOutputJson3()).Top.Any(x => x.GetType() == typeof (OutputNode)).ShouldBeFalse();
- }
-
[Test]
public void methods_that_do_not_take_in_a_json_message_should_not_have_a_json_deserialization_behavior()
{

0 comments on commit c35263a

Please sign in to comment.