Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding the very basic 'Chrome' wrapper functionality to FubuMVC.Core

  • Loading branch information...
commit af09d49ce92c8847adb2d20f57f1f05b9ca55ddc 1 parent 1725e29
@jeremydmiller jeremydmiller authored
View
28 src/FubuMVC.Core/Behaviors/Chrome/ChromeAttribute.cs
@@ -0,0 +1,28 @@
+using System;
+using FubuCore;
+using FubuMVC.Core.Registration;
+using FubuMVC.Core.Registration.Nodes;
+
+namespace FubuMVC.Core.Behaviors.Chrome
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
+ public class ChromeAttribute : ModifyChainAttribute
+ {
+ private readonly Type _contentType;
+
+ public ChromeAttribute(Type contentType)
+ {
+ if (!contentType.CanBeCastTo<ChromeContent>())
+ {
+ throw new ArgumentOutOfRangeException("contentType", "contentType must be ChromeContent or a subclass of ChromeContent");
+ }
+
+ _contentType = contentType;
+ }
+
+ public override void Alter(ActionCall call)
+ {
+ call.AddBefore(new ChromeNode(_contentType));
+ }
+ }
+}
View
38 src/FubuMVC.Core/Behaviors/Chrome/ChromeBehavior.cs
@@ -0,0 +1,38 @@
+using FubuMVC.Core.Runtime;
+using FubuMVC.Core.UI;
+
+namespace FubuMVC.Core.Behaviors.Chrome
+{
+ // Look in integration testing for this one.
+ public class ChromeBehavior<T> : IActionBehavior where T : ChromeContent, new()
+ {
+ private readonly IPartialInvoker _partials;
+ private readonly IActionBehavior _inner;
+ private readonly IOutputWriter _writer;
+
+ public ChromeBehavior(IPartialInvoker partials, IActionBehavior inner, IOutputWriter writer)
+ {
+ _partials = partials;
+ _inner = inner;
+ _writer = writer;
+ }
+
+ public void Invoke()
+ {
+ var output = _writer.Record(() => _inner.Invoke());
+
+ var subject = new T{
+ InnerContent = output.GetText()
+ };
+
+ var html = _partials.InvokeObject(subject);
+
+ _writer.WriteHtml(html);
+ }
+
+ public void InvokePartial()
+ {
+ _inner.InvokePartial();
+ }
+ }
+}
View
3  src/FubuMVC.Diagnostics/Chrome/ChromeContent.cs → src/FubuMVC.Core/Behaviors/Chrome/ChromeContent.cs
@@ -1,6 +1,5 @@
-namespace FubuMVC.Diagnostics.Chrome
+namespace FubuMVC.Core.Behaviors.Chrome
{
- // TODO -- make this be an actionless view?
public class ChromeContent
{
public string InnerContent { get; set; }
View
12 src/FubuMVC.Core/Behaviors/Chrome/ChromeNode.cs
@@ -0,0 +1,12 @@
+using System;
+using FubuMVC.Core.Registration.Nodes;
+
+namespace FubuMVC.Core.Behaviors.Chrome
+{
+ public class ChromeNode : Wrapper
+ {
+ public ChromeNode(Type contentType) : base(typeof(ChromeBehavior<>).MakeGenericType(contentType))
+ {
+ }
+ }
+}
View
4 src/FubuMVC.Core/ConfigurationGraph.cs
@@ -66,7 +66,8 @@ public enum ConfigurationType
Reordering,
Navigation,
Instrumentation,
- Services
+ Services,
+ Chrome
}
@@ -153,6 +154,7 @@ private IEnumerable<IConfigurationAction> allActions()
.Union(fullGraphPolicies())
.Union(navigationRegistrations().OfType<IConfigurationAction>())
.Union(new IConfigurationAction[]{new MenuItemAttributeConfigurator(), new CompileNavigationStep()})
+ .Union(_configurations[ConfigurationType.Chrome])
.Union(_configurations[ConfigurationType.Reordering])
.Union(_configurations[ConfigurationType.Instrumentation]);
}
View
4 src/FubuMVC.Core/FubuMVC.Core.csproj
@@ -93,6 +93,10 @@
<Compile Include="Assets\RecordingAssetRegistration.cs" />
<Compile Include="Behaviors\AsyncContinueWithBehavior.cs" />
<Compile Include="Behaviors\AsyncInterceptExceptionBehavior.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeAttribute.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeBehavior.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeContent.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeNode.cs" />
<Compile Include="CanBeMultiplesAttribute.cs" />
<Compile Include="Endpoints\EndpointDriver.cs" />
<Compile Include="Endpoints\EndpointFormatting.cs" />
View
7 src/FubuMVC.Diagnostics/Chrome/ChromeBehavior.cs
@@ -1,10 +1,17 @@
using System;
+using FubuCore;
using FubuMVC.Core.Behaviors;
using FubuMVC.Core.Runtime;
using FubuMVC.Core.UI;
namespace FubuMVC.Diagnostics.Chrome
{
+ public class ChromeContent
+ {
+ public string InnerContent { get; set; }
+ }
+
+ [MarkedForTermination("Going into FubuMVC.Core itself")]
public class ChromeBehavior : IActionBehavior
{
private readonly IPartialInvoker _partials;
View
1  src/FubuMVC.Diagnostics/FubuMVC.Diagnostics.csproj
@@ -268,7 +268,6 @@
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Chrome\ChromeBehavior.cs" />
- <Compile Include="Chrome\ChromeContent.cs" />
<Compile Include="Chrome\FakeEndpoint.cs" />
<Compile Include="Core\AdvancedDiagnosticsFubuExtension.cs" />
<Compile Include="Core\Configuration\ActionCallExtensions.cs" />
View
56 src/FubuMVC.IntegrationTesting/Chrome/ChromeBehaviorIntegrationTester.cs
@@ -0,0 +1,56 @@
+using System;
+using FubuMVC.Core;
+using FubuMVC.Core.Behaviors.Chrome;
+using FubuMVC.IntegrationTesting.Conneg;
+using FubuTestingSupport;
+using NUnit.Framework;
+
+namespace FubuMVC.IntegrationTesting.Chrome
+{
+ [TestFixture]
+ public class ChromeBehaviorIntegrationTester : FubuRegistryHarness
+ {
+ protected override void configure(FubuRegistry registry)
+ {
+ registry.Actions.IncludeType<ChromedEndpoints>();
+ }
+
+ [Test]
+ public void can_fetch_endpoints_that_are_chromed()
+ {
+ endpoints.Get<ChromedEndpoints>(x => x.get_text1())
+ .ReadAsText().ShouldEqual("**text1**");
+
+ endpoints.Get<ChromedEndpoints>(x => x.get_text2())
+ .ReadAsText().ShouldEqual("~~text2~~");
+ }
+ }
+
+ public class ChromedEndpoints
+ {
+ public string First(FirstChrome content)
+ {
+ return "**" + content.InnerContent + "**";
+ }
+
+ public string Second(SecondChrome content)
+ {
+ return "~~" + content.InnerContent + "~~";
+ }
+
+ [Chrome(typeof(FirstChrome))]
+ public string get_text1()
+ {
+ return "text1";
+ }
+
+ [Chrome(typeof(SecondChrome))]
+ public string get_text2()
+ {
+ return "text2";
+ }
+ }
+
+ public class FirstChrome : ChromeContent{}
+ public class SecondChrome : ChromeContent{}
+}
View
1  src/FubuMVC.IntegrationTesting/FubuMVC.IntegrationTesting.csproj
@@ -86,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\writing_asset_tags_with_and_without_bottles.cs" />
+ <Compile Include="Chrome\ChromeBehaviorIntegrationTester.cs" />
<Compile Include="CommandRunner.cs" />
<Compile Include="Conneg\Conneg_Can_Choose_Output_Media_Based_on_Mimetypes.cs" />
<Compile Include="Conneg\FubuRegistryRunner.cs" />
View
45 src/FubuMVC.Tests/Behaviors/Chrome/ChromeAttributeTester.cs
@@ -0,0 +1,45 @@
+using System;
+using FubuMVC.Core.Behaviors.Chrome;
+using FubuMVC.Core.Registration;
+using FubuTestingSupport;
+using NUnit.Framework;
+
+namespace FubuMVC.Tests.Behaviors.Chrome
+{
+ [TestFixture]
+ public class ChromeAttributeTester
+ {
+ [Test]
+ public void attribute_whines_if_you_give_it_the_wrong_type()
+ {
+ Exception<ArgumentOutOfRangeException>.ShouldBeThrownBy(() =>
+ {
+ new ChromeAttribute(GetType());
+ });
+ }
+
+ [Test]
+ public void applies_the_chrome_node()
+ {
+ var graph = BehaviorGraph.BuildFrom(x =>
+ {
+ x.Actions.IncludeType<ChromedEnpoint>();
+ });
+
+ var chain = graph.BehaviorFor<ChromedEnpoint>(x => x.get_stuff());
+
+ chain.IsWrappedBy(typeof(ChromeBehavior<DifferentChrome>)).ShouldBeTrue();
+ }
+ }
+
+ public class ChromedEnpoint
+ {
+ [Chrome(typeof(DifferentChrome))]
+ public string get_stuff()
+ {
+ return "";
+ }
+ }
+
+ public class DifferentChrome : ChromeContent{}
+}
View
33 src/FubuMVC.Tests/Behaviors/Chrome/ChromeNodeTester.cs
@@ -0,0 +1,33 @@
+using FubuCore;
+using FubuMVC.Core.Behaviors.Chrome;
+using FubuMVC.Core.Registration.Nodes;
+using NUnit.Framework;
+using FubuTestingSupport;
+
+namespace FubuMVC.Tests.Behaviors.Chrome
+{
+ [TestFixture]
+ public class ChromeNodeTester
+ {
+ [Test]
+ public void chrome_node_creates_behavior()
+ {
+ var node = new ChromeNode(typeof (ChromeContent));
+ var def = node.As<IContainerModel>().ToObjectDef();
+
+ def.Type.ShouldEqual(typeof (ChromeBehavior<ChromeContent>));
+ }
+
+ [Test]
+ public void chrome_node_creates_behavior_2()
+ {
+ var node = new ChromeNode(typeof(FakeChrome));
+ var def = node.As<IContainerModel>().ToObjectDef();
+
+ def.Type.ShouldEqual(typeof(ChromeBehavior<FakeChrome>));
+ }
+
+ }
+
+ public class FakeChrome : ChromeContent{}
+}
View
2  src/FubuMVC.Tests/FubuMVC.Tests.csproj
@@ -154,6 +154,8 @@
<Compile Include="Assets\Http\AssetWriterTester.cs" />
<Compile Include="Assets\Http\ContentPipelineTester.cs" />
<Compile Include="Assets\Http\ContentWriterTester.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeAttributeTester.cs" />
+ <Compile Include="Behaviors\Chrome\ChromeNodeTester.cs" />
<Compile Include="ConfigurationGraph_DetermineConfigurationType_Tester.cs" />
<Compile Include="Registration\default_action_discovery.cs" />
<Compile Include="Runtime\Dates\DateTimeFormatting_import_integration_testing.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.