Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

brought back all the media ut's, about to rip them out though

  • Loading branch information...
commit 97028c8ed8b4c02c635e7080b78b4db978d5452e 1 parent 4ebe06b
@jeremydmiller jeremydmiller authored
View
38 src/FubuMVC.Media.Testing/Atom/FeedTester.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.ServiceModel.Syndication;
using FubuCore;
using FubuLocalization;
@@ -26,6 +27,7 @@ public void SetUp()
var registry = new FubuRegistry();
registry.Actions.IncludeType<Controller1>();
registry.Media.ApplyContentNegotiationToActions(call => true);
+ registry.Policies.Add(new ConnegAttachmentPolicy(new TypePool(Assembly.GetExecutingAssembly())));
theGraph = registry.BuildGraph();
}
@@ -33,42 +35,21 @@ public void SetUp()
[Test]
public void should_apply_a_media_output_node_to_enumerables_of_the_target_type()
{
- var outputNode = theGraph.BehaviorFor<Controller1>(x => x.M1())
+ var writers = theGraph.BehaviorFor<Controller1>(x => x.M1())
.Output
- .Writers.Single()
+ .Writers;
+ var outputNode = writers.Last()
.ShouldBeOfType<FeedWriterNode<TargetClass>>();
outputNode.Feed.ShouldBeOfType<TargetClassFeed>();
}
- [Test]
- public void should_apply_a_media_output_node_to_enumerables_of_values_of_the_target_type()
- {
- var outputNode = theGraph.BehaviorFor<Controller1>(x => x.M2())
- .Output
- .Writers.Single()
- .ShouldBeOfType<FeedWriterNode<TargetClass>>();
-
- outputNode.Feed.ShouldBeOfType<TargetClassFeed>();
- }
public class TargetClassFeed : Feed<TargetClass>
{
}
- public class EnumerableOutput : IEnumerable<TargetClass>
- {
- IEnumerator<TargetClass> IEnumerable<TargetClass>.GetEnumerator()
- {
- throw new NotImplementedException();
- }
-
- public IEnumerator GetEnumerator()
- {
- throw new NotImplementedException();
- }
- }
public class EnumerableValuesOutput : IEnumerable<IValues<TargetClass>>
{
@@ -87,15 +68,12 @@ public class TargetClass{}
public class Controller1
{
- public EnumerableOutput M1()
+ public IEnumerable<TargetClass> M1()
{
- return new EnumerableOutput();
+ yield return new TargetClass();
}
- public EnumerableValuesOutput M2()
- {
- return null;
- }
+
}
}
View
7 src/FubuMVC.Media.Testing/Atom/FeedWriterNodeTester.cs
@@ -4,6 +4,7 @@
using FubuMVC.Core;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Registration.ObjectGraph;
+using FubuMVC.Core.Resources.Conneg.New;
using FubuMVC.Media.Atom;
using FubuMVC.Media.Projections;
using FubuMVC.Media.Testing.Xml;
@@ -58,7 +59,8 @@ public void build_object_def_has_correct_feed_writer_type()
{
var objectDef = new FeedWriterNode<Address>(new Feed<Address>(), typeof (AddressEnumerable))
.As<IContainerModel>()
- .ToObjectDef(DiagnosticLevel.None);
+ .ToObjectDef(DiagnosticLevel.None)
+ .FindDependencyDefinitionFor<IMediaWriter<IEnumerable<Address>>>();
objectDef.Type.ShouldEqual(typeof (FeedWriter<Address>));
@@ -70,7 +72,8 @@ public void has_a_dependency_for_the_ifeeddefinition()
var theFeed = new Feed<Address>();
var objectDef = new FeedWriterNode<Address>(theFeed,typeof (AddressEnumerable))
.As<IContainerModel>()
- .ToObjectDef(DiagnosticLevel.None);
+ .ToObjectDef(DiagnosticLevel.None)
+ .FindDependencyDefinitionFor<IMediaWriter<IEnumerable<Address>>>();
objectDef.DependencyFor<IFeedDefinition<Address>>()
View
9 src/FubuMVC.Media.Testing/Atom/FeedWriter_integrated_Tester.cs
@@ -92,7 +92,7 @@ public void SetUp()
theUrls = new ValidStubUrlRegistry();
output = new InMemoryOutputWriter();
- var theWriter = new FeedWriter<FeedTarget>(
+ theWriter = new FeedWriter<FeedTarget>(
new FeedWithExtension(),
new FeedTargetLinks(),
theUrls,
@@ -123,11 +123,10 @@ public void the_resulting_feed_should_have_the_extensions()
[Platform(Exclude="Mono")]
public void the_resulting_feed_does_manage_to_write_some_xml()
{
- var outputWriter = new InMemoryOutputWriter();
- theWriter.Write("text/plain", new FeedTargetSource());
+ theWriter.Write("application/atom+xml", new FeedTargetSource());
- outputWriter.ContentType.ShouldEqual(new FeedWithExtension().ContentType);
- outputWriter.ToString().ShouldContain("<Item xmlns=\"\"><City>Dallas</City><Name>The second item</Name></Item>");
+ output.ContentType.ShouldEqual("application/atom+xml");
+ output.ToString().ShouldContain("<Item xmlns=\"\"><City>Dallas</City><Name>The second item</Name></Item>");
}
}
View
2  src/FubuMVC.Media.Testing/FubuMVC.Media.Testing.csproj
@@ -35,7 +35,7 @@
<HintPath>..\packages\FubuCore.0.9.8.130\lib\FubuCore.dll</HintPath>
</Reference>
<Reference Include="FubuLocalization">
- <HintPath>..\packages\FubuLocalization.0.9.5.17\lib\FubuLocalization.dll</HintPath>
+ <HintPath>..\packages\FubuLocalization.0.9.5.14\lib\FubuLocalization.dll</HintPath>
</Reference>
<Reference Include="FubuTestingSupport">
<HintPath>..\packages\FubuTestingSupport.0.9.8.130\lib\FubuTestingSupport.dll</HintPath>
View
8 src/FubuMVC.Media.Testing/Projections/EnumerableProjectionIntegratedTester.cs
@@ -1,9 +1,11 @@
using System.Xml;
+using FubuMVC.Core;
using FubuMVC.Media.Projections;
using FubuMVC.Media.Xml;
using FubuMVC.StructureMap;
using NUnit.Framework;
using FubuTestingSupport;
+using StructureMap;
namespace FubuMVC.Media.Testing.Projections
{
@@ -24,7 +26,11 @@ public void SetUp()
}
};
- var container = StructureMapContainerFacility.GetBasicFubuContainer();
+ var container = new Container();
+ var registry = new FubuRegistry();
+ registry.Services<ResourcesServiceRegistry>();
+ FubuApplication.For(registry).StructureMap(container).Bootstrap();
+
runner = container.GetInstance<IProjectionRunner>();
}
View
28 src/FubuMVC.Media.Testing/Resource_integrated_registration_tester.cs
@@ -1,9 +1,11 @@
+using System.Reflection;
using FubuCore;
using FubuMVC.Core;
using FubuMVC.Core.Registration;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Registration.ObjectGraph;
using FubuMVC.Core.Resources.Conneg;
+using FubuMVC.Core.Resources.Conneg.New;
using FubuMVC.Core.Runtime.Formatters;
using FubuMVC.Media.Projections;
using FubuMVC.Media.Testing.Xml;
@@ -26,6 +28,10 @@ public void SetUp()
var registry = new FubuRegistry();
registry.Actions.IncludeType<RestController1>();
+ // TODO -- this really needs to be done with a Bottle
+ registry.Policies.Add(new ConnegAttachmentPolicy(new TypePool(Assembly.GetExecutingAssembly())));
+ registry.Services<ResourcesServiceRegistry>();
+
registry.Media.ApplyContentNegotiationToActions(x => x.HandlerType == typeof (RestController1) && !x.Method.Name.StartsWith("Not"));
theBehaviorGraph = registry.BuildGraph();
@@ -50,10 +56,10 @@ public void resource_also_registers_the_link_source_configuration()
[Test]
public void conneg_graph_can_find_all_the_output_nodes_for_a_type()
{
- theConnegGraph.OutputNodesFor<Address>().Select(x => x.Previous.As<ActionCall>().Method.Name)
+ theConnegGraph.OutputNodesFor<Address>().Where(x => x.ParentChain() != null).Select(x => x.Previous.As<ActionCall>().Method.Name)
.ShouldHaveTheSameElementsAs("Find", "put_city", "Method3");
- theConnegGraph.OutputNodesFor<Output1>().Select(x => x.Previous.As<ActionCall>().Method.Name)
+ theConnegGraph.OutputNodesFor<Output1>().Where(x => x.ParentChain() != null).Select(x => x.Previous.As<ActionCall>().Method.Name)
.ShouldHaveTheSameElementsAs("Method4");
}
@@ -61,7 +67,8 @@ public void conneg_graph_can_find_all_the_output_nodes_for_a_type()
[Test]
public void conneg_graph_can_find_all_input_nodes_for_a_type()
{
- theConnegGraph.InputNodesFor<Input1>().Select(x => x.Next.As<ActionCall>().Method.Name)
+ var nodes = theConnegGraph.InputNodesFor<Input1>();
+ nodes.Where(x => x.ParentChain() != null).Select(x => x.Next.As<ActionCall>().Method.Name)
.ShouldHaveTheSameElementsAs("Find", "Method4");
}
@@ -148,7 +155,8 @@ public void create_a_media_write_node_for_xml()
var writerNode = connegOutput.Writers.Last().As<MediaWriterNode>();
// Assert the xml media
- var objectDef = writerNode.As<IContainerModel>().ToObjectDef(DiagnosticLevel.None);
+ var objectDef = writerNode.As<IContainerModel>().ToObjectDef(DiagnosticLevel.None)
+ .FindDependencyDefinitionFor<IMediaWriter<Address>>();
var document = objectDef.DependencyFor<IMediaDocument>().ShouldBeOfType<ConfiguredDependency>();
@@ -169,9 +177,16 @@ public void create_a_media_write_node_for_xml()
public void conneg_attachement_policy_finds_and_applies_resource_configuration()
{
var registry = new FubuRegistry();
+
+ var typePool = new TypePool(Assembly.GetExecutingAssembly());
+
+ registry.Media.ApplyContentNegotiationToActions(x => true);
+ registry.Policies.Add(new ConnegAttachmentPolicy(typePool));
+ registry.Services<ResourcesServiceRegistry>();
+
registry.Applies.ToThisAssembly();
registry.Actions.IncludeType<RestController1>();
- registry.Media.ApplyContentNegotiationToActions(x => true);
+
var graph = registry.BuildGraph();
@@ -182,7 +197,8 @@ public void conneg_attachement_policy_finds_and_applies_resource_configuration()
var writerNode = connegOutput.Writers.Single().As<MediaWriterNode>();
// Assert the xml media
- var objectDef = writerNode.As<IContainerModel>().ToObjectDef(DiagnosticLevel.None);
+ var objectDef = writerNode.As<IContainerModel>().ToObjectDef(DiagnosticLevel.None)
+ .FindDependencyDefinitionFor <IMediaWriter<Address>>();
var document = objectDef.DependencyFor<IMediaDocument>().ShouldBeOfType<ConfiguredDependency>();
View
2  src/FubuMVC.Media.Testing/Xml/XmlMediaWriterIntegratedTester.cs
@@ -92,7 +92,7 @@ public void has_the_links()
}
links.Select(x => x.GetAttribute("href"))
- .ShouldHaveTheSameElementsAs("url for FubuMVC.Tests.UI.Address", "url for Action/change", "url for Action/delete");
+ .ShouldHaveTheSameElementsAs("url for FubuMVC.Media.Testing.Xml.Address", "url for Action/change", "url for Action/delete");
}
}
View
32 src/FubuMVC.Media.Testing/default_service_registrations.cs
@@ -1,3 +1,7 @@
+using FubuMVC.Core;
+using FubuMVC.Core.Registration;
+using FubuMVC.Media.Projections;
+using FubuTestingSupport;
using NUnit.Framework;
namespace FubuMVC.Media.Testing
@@ -5,26 +9,27 @@ namespace FubuMVC.Media.Testing
[TestFixture]
public class default_service_registrations
{
- [Test]
- public void fix_these()
- {
- Assert.Fail("Do.");
- }
+ private ServiceGraph theServices;
+ [SetUp]
+ public void SetUp()
+ {
+ var registry = new FubuRegistry();
+ registry.Services<ResourcesServiceRegistry>();
- /*
+ theServices = registry.BuildGraph().Services;
+ }
+
[Test]
public void value_source_is_registered()
{
- var services = new FubuRegistry().BuildGraph().Services;
- services.DefaultServiceFor(typeof (IValueSource<>)).Type.ShouldEqual(typeof (ValueSource<>));
+ theServices.DefaultServiceFor(typeof (IValueSource<>)).Type.ShouldEqual(typeof (ValueSource<>));
}
[Test]
public void values_is_registered()
{
- var services = new FubuRegistry().BuildGraph().Services;
- services.DefaultServiceFor(typeof (IValues<>)).Type.ShouldEqual(typeof (SimpleValues<>));
+ theServices.DefaultServiceFor(typeof (IValues<>)).Type.ShouldEqual(typeof (SimpleValues<>));
}
@@ -32,15 +37,14 @@ public void values_is_registered()
[Test]
public void projection_runner_is_registered()
{
- registeredTypeIs<IProjectionRunner, ProjectionRunner>();
+ theServices.DefaultServiceFor(typeof (IProjectionRunner)).Type.ShouldEqual(typeof (ProjectionRunner));
}
[Test]
public void generic_projection_runner_is_registered()
{
- var services = new FubuRegistry().BuildGraph().Services;
- services.DefaultServiceFor(typeof(IProjectionRunner<>)).Type.ShouldEqual(typeof(ProjectionRunner<>));
+ theServices.DefaultServiceFor(typeof(IProjectionRunner<>)).Type.ShouldEqual(typeof(ProjectionRunner<>));
}
- */
+
}
}
View
2  src/FubuMVC.Media.Testing/packages.config
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FubuCore" version="0.9.8.130" />
- <package id="FubuLocalization" version="0.9.5.17" />
+ <package id="FubuLocalization" version="0.9.5.14" />
<package id="FubuTestingSupport" version="0.9.8.130" />
<package id="NUnit" version="2.5.10.11092" />
<package id="RhinoMocks" version="3.6" />
View
19 src/FubuMVC.Media/Atom/Feed.cs
@@ -75,25 +75,8 @@ void IFeedDefinition<T>.ConfigureItem(SyndicationItem item, IValues<T> values)
void IResourceRegistration.Modify(ConnegGraph graph, BehaviorGraph behaviorGraph)
{
- modifyForEnumerableOfTargetType(graph);
-
- modifyForEnumerableOfValuesOfTargetType(graph);
- }
-
- private void modifyForEnumerableOfValuesOfTargetType(ConnegGraph graph)
- {
- var valueType = typeof(IValues<>).MakeGenericType(typeof(T));
- var enumerableValueType = typeof(IEnumerable<>).MakeGenericType(valueType);
- graph.OutputNodesThatCanBeCastTo(enumerableValueType).Each(outputNode =>
- {
- outputNode.Writers.AddToEnd(new FeedWriterNode<T>(this, outputNode.ResourceType));
- });
- }
-
- private void modifyForEnumerableOfTargetType(ConnegGraph graph)
- {
var enumerableType = typeof(IEnumerable<>).MakeGenericType(typeof(T));
- graph.OutputNodesThatCanBeCastTo(enumerableType).Each(outputNode =>
+ graph.OutputNodesFor(enumerableType).Each(outputNode =>
{
outputNode.Writers.AddToEnd(new FeedWriterNode<T>(this, outputNode.ResourceType));
});
View
3  src/FubuMVC.Media/FubuMVC.Media.csproj
@@ -35,7 +35,7 @@
<HintPath>..\packages\FubuCore.0.9.8.130\lib\FubuCore.dll</HintPath>
</Reference>
<Reference Include="FubuLocalization">
- <HintPath>..\packages\FubuLocalization.0.9.5.17\lib\FubuLocalization.dll</HintPath>
+ <HintPath>..\packages\FubuLocalization.0.9.5.14\lib\FubuLocalization.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -66,6 +66,7 @@
<Compile Include="LinkExpression.cs" />
<Compile Include="LinkSource.cs" />
<Compile Include="LinksSource.cs" />
+ <Compile Include="MediaBottleRegistrations.cs" />
<Compile Include="MediaDependency.cs" />
<Compile Include="MediaWriter.cs" />
<Compile Include="MediaWriterNode.cs" />
View
13 src/FubuMVC.Media/MediaBottleRegistrations.cs
@@ -0,0 +1,13 @@
+using System;
+using FubuMVC.Core;
+
+namespace FubuMVC.Media
+{
+ public class MediaBottleRegistrations : IFubuRegistryExtension
+ {
+ public void Configure(FubuRegistry registry)
+ {
+ registry.Services<ResourcesServiceRegistry>();
+ }
+ }
+}
View
3  src/FubuMVC.Media/Properties/AssemblyInfo.cs
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using FubuMVC.Core;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@@ -34,3 +35,5 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+
+[assembly: FubuModule]
View
5 src/FubuMVC.Media/Resource.cs
@@ -19,7 +19,10 @@ public class Resource<T> : IResourceRegistration
public Resource()
{
- modify = node => node.Where(x => x is WriteWithFormatter).ToList().Each(x => x.Remove());
+ modify = node =>
+ {
+ node.Writers.OfType<WriteWithFormatter>().ToList().Each(x => x.Remove());
+ };
}
private Action<OutputNode> modify
View
2  src/FubuMVC.Media/packages.config
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FubuCore" version="0.9.8.130" />
- <package id="FubuLocalization" version="0.9.5.17" />
+ <package id="FubuLocalization" version="0.9.5.14" />
</packages>
Please sign in to comment.
Something went wrong with that request. Please try again.