Permalink
Browse files

Renamed Resource to Representation, Removed Linkers

  • Loading branch information...
Jake Ginnivan
Jake Ginnivan committed Jul 30, 2012
1 parent f6b31d2 commit 6a1f5eda4574183f579ca91937f6b26237ea04c1
Showing with 559 additions and 545 deletions.
  1. +6 −12 WebApi.Hal.Tests/HalResourceListTests.cs
  2. +0 −4 WebApi.Hal.Tests/HalResourceTest.cs
  3. +2 −6 WebApi.Hal.Tests/HalResourceWithPeopleTest.cs
  4. +3 −3 WebApi.Hal.Tests/HalResourceWithPeopleTest.organisation_get_json_test.approved.txt
  5. +0 −14 WebApi.Hal.Tests/Linkers/OrganisationLinker.cs
  6. +0 −19 WebApi.Hal.Tests/Linkers/OrganisationListLinker.cs
  7. +0 −19 WebApi.Hal.Tests/Linkers/OrganisationWithPeopleLinker.cs
  8. +19 −0 WebApi.Hal.Tests/Representations/OrganisationListRepresentation.cs
  9. +7 −1 WebApi.Hal.Tests/Representations/OrganisationRepresentation.cs
  10. +30 −0 WebApi.Hal.Tests/Representations/OrganisationWithPeopleRepresentation.cs
  11. +0 −33 WebApi.Hal.Tests/ResourceLinkerTests.cs
  12. +2 −4 WebApi.Hal.Tests/WebApi.Hal.Tests.csproj
  13. +19 −0 WebApi.Hal.Tests/WebApi.Hal.Tests.ncrunchproject
  14. +13 −16 WebApi.Hal.Web/Api/BeersController.cs
  15. +10 −13 WebApi.Hal.Web/Api/BreweriesController.cs
  16. +0 −20 WebApi.Hal.Web/Api/Linkers/BeerLinker.cs
  17. +0 −23 WebApi.Hal.Web/Api/Linkers/BeerListLinker.cs
  18. +0 −15 WebApi.Hal.Web/Api/Linkers/BeerStyleLinker.cs
  19. +0 −20 WebApi.Hal.Web/Api/Linkers/BeerStyleListLinker.cs
  20. +0 −15 WebApi.Hal.Web/Api/Linkers/BreweryLinker.cs
  21. +0 −20 WebApi.Hal.Web/Api/Linkers/BreweryListLinker.cs
  22. +23 −0 WebApi.Hal.Web/Api/Resources/BeerListRepresentation.cs
  23. +0 −13 WebApi.Hal.Web/Api/Resources/BeerListResource.cs
  24. +26 −0 WebApi.Hal.Web/Api/Resources/BeerRepresentation.cs
  25. +0 −14 WebApi.Hal.Web/Api/Resources/BeerResource.cs
  26. +19 −0 WebApi.Hal.Web/Api/Resources/BeerStyleListRepresentation.cs
  27. +0 −12 WebApi.Hal.Web/Api/Resources/BeerStyleListResource.cs
  28. +15 −0 WebApi.Hal.Web/Api/Resources/BeerStyleRepresentation.cs
  29. +0 −8 WebApi.Hal.Web/Api/Resources/BeerStyleResource.cs
  30. +19 −0 WebApi.Hal.Web/Api/Resources/BreweryListRepresentation.cs
  31. +0 −12 WebApi.Hal.Web/Api/Resources/BreweryListResource.cs
  32. +16 −0 WebApi.Hal.Web/Api/Resources/BreweryRepresentation.cs
  33. +0 −9 WebApi.Hal.Web/Api/Resources/BreweryResource.cs
  34. +11 −14 WebApi.Hal.Web/Api/StylesController.cs
  35. +4 −4 WebApi.Hal.Web/Data/Queries/GetBeersQuery.cs
  36. +2 −10 WebApi.Hal.Web/Global.asax.cs
  37. +6 −12 WebApi.Hal.Web/WebApi.Hal.Web.csproj
  38. +19 −0 WebApi.Hal.Web/WebApi.Hal.Web.ncrunchproject
  39. +2 −2 WebApi.Hal.ncrunchsolution
  40. +88 −0 WebApi.Hal/HypermediaList.cs
  41. +8 −0 WebApi.Hal/Interfaces/IRepresentationList.cs
  42. +1 −1 WebApi.Hal/Interfaces/IResource.cs
  43. +0 −7 WebApi.Hal/Interfaces/IResourceLinker.cs
  44. +0 −7 WebApi.Hal/Interfaces/IResourceLinker`1.cs
  45. +0 −8 WebApi.Hal/Interfaces/IResourceList.cs
  46. +2 −2 WebApi.Hal/JsonConverters/LinksConverter.cs
  47. +4 −4 WebApi.Hal/JsonConverters/ResourceConverter.cs
  48. +5 −5 WebApi.Hal/JsonConverters/ResourceListConverter.cs
  49. +2 −2 WebApi.Hal/JsonHalMediaTypeFormatter.cs
  50. +2 −1 WebApi.Hal/Link.cs
  51. +2 −7 WebApi.Hal/ReflectionExtensions.cs
  52. +103 −0 WebApi.Hal/Representation.cs
  53. +2 −7 WebApi.Hal/{ResourceList.cs → RepresentationList.cs}
  54. +0 −26 WebApi.Hal/Resource.cs
  55. +0 −56 WebApi.Hal/ResourceLinker.cs
  56. +4 −6 WebApi.Hal/WebApi.Hal.csproj
  57. +19 −0 WebApi.Hal/WebApi.Hal.ncrunchproject
  58. +44 −39 WebApi.Hal/XmlHalMediaTypeFormatter.cs
@@ -3,29 +3,23 @@
using System.Net.Http;
using ApprovalTests;
using ApprovalTests.Reporters;
-using WebApi.Hal.Tests.Linkers;
using WebApi.Hal.Tests.Representations;
using Xunit;
namespace WebApi.Hal.Tests
{
public class HalResourceListTests
{
- readonly ResourceLinker resourceLinker;
- readonly ResourceList<OrganisationRepresentation> resource;
+ readonly RepresentationList<OrganisationRepresentation> representation;
public HalResourceListTests()
{
- resourceLinker = new ResourceLinker();
- resourceLinker.AddLinker(new OrganisationListLinker());
- resourceLinker.AddLinker(new OrganisationLinker());
- resource = new ResourceList<OrganisationRepresentation>(
+ representation = new OrganisationListRepresentation(
new List<OrganisationRepresentation>
{
new OrganisationRepresentation(1, "Org1"),
new OrganisationRepresentation(2, "Org2")
});
- resourceLinker.CreateLinks(resource);
}
[Fact]
@@ -35,12 +29,12 @@ public void organisation_list_get_xml_test()
// arrange
var mediaFormatter = new XmlHalMediaTypeFormatter();
var contentHeaders = new StringContent(string.Empty).Headers;
- var type = resource.GetType();
+ var type = representation.GetType();
// act
using (var stream = new MemoryStream())
{
- mediaFormatter.WriteToStream(type, resource, stream, contentHeaders);
+ mediaFormatter.WriteToStream(type, representation, stream, contentHeaders);
stream.Seek(0, SeekOrigin.Begin);
var serialisedResult = new StreamReader(stream).ReadToEnd();
@@ -56,12 +50,12 @@ public void organisation_list_get_json_test()
// arrange
var mediaFormatter = new JsonHalMediaTypeFormatter { Indent = true };
var contentHeaders = new StringContent(string.Empty).Headers;
- var type = resource.GetType();
+ var type = representation.GetType();
// act
using (var stream = new MemoryStream())
{
- mediaFormatter.WriteToStreamAsync(type, resource, stream, contentHeaders, null).Wait();
+ mediaFormatter.WriteToStreamAsync(type, representation, stream, contentHeaders, null).Wait();
stream.Seek(0, SeekOrigin.Begin);
var serialisedResult = new StreamReader(stream).ReadToEnd();
@@ -2,7 +2,6 @@
using System.Net.Http;
using ApprovalTests;
using ApprovalTests.Reporters;
-using WebApi.Hal.Tests.Linkers;
using WebApi.Hal.Tests.Representations;
using Xunit;
@@ -15,9 +14,6 @@ public class HalResourceTest
public HalResourceTest()
{
resource = new OrganisationRepresentation(1, "Org Name");
- var linker = new ResourceLinker();
- linker.AddLinker(new OrganisationLinker());
- linker.CreateLinks(resource);
}
[Fact]
@@ -2,22 +2,18 @@
using System.Net.Http;
using ApprovalTests;
using ApprovalTests.Reporters;
-using WebApi.Hal.Tests.Linkers;
using WebApi.Hal.Tests.Representations;
using Xunit;
namespace WebApi.Hal.Tests
{
public class HalResourceWithPeopleTest
{
- readonly OrganisationRepresentation resource;
+ readonly OrganisationWithPeopleRepresentation resource;
public HalResourceWithPeopleTest()
{
- resource = new OrganisationRepresentation(1, "Org Name");
- var linker = new ResourceLinker();
- linker.AddLinker(new OrganisationWithPeopleLinker());
- linker.CreateLinks(resource);
+ resource = new OrganisationWithPeopleRepresentation(1, "Org Name");
}
[Fact]
@@ -2,11 +2,11 @@
"Id": 1,
"Name": "Org Name",
"_links": {
- "people": {
- "href": "/api/organisations/1/people"
- },
"self": {
"href": "/api/organisations/1"
+ },
+ "people": {
+ "href": "/api/organisations/1/people"
}
}
}
@@ -1,14 +0,0 @@
-using WebApi.Hal.Interfaces;
-using WebApi.Hal.Tests.Representations;
-
-namespace WebApi.Hal.Tests.Linkers
-{
- public class OrganisationLinker : IResourceLinker<OrganisationRepresentation>
- {
- public void CreateLinks(OrganisationRepresentation resource, IResourceLinker resourceLinker)
- {
- resource.Rel = "organisation";
- resource.Href = string.Format("/api/organisations/{0}", resource.Id);
- }
- }
-}
@@ -1,19 +0,0 @@
-using WebApi.Hal.Interfaces;
-using WebApi.Hal.Tests.Representations;
-
-namespace WebApi.Hal.Tests.Linkers
-{
- public class OrganisationListLinker : IResourceLinker<ResourceList<OrganisationRepresentation>>
- {
- public void CreateLinks(ResourceList<OrganisationRepresentation> resource, IResourceLinker resourceLinker)
- {
- resource.Rel = "organisations";
- resource.Href = "/api/organisations";
-
- foreach (var organisationRepresentation in resource)
- {
- resourceLinker.CreateLinks(organisationRepresentation);
- }
- }
- }
-}
@@ -1,19 +0,0 @@
-using WebApi.Hal.Interfaces;
-using WebApi.Hal.Tests.Representations;
-
-namespace WebApi.Hal.Tests.Linkers
-{
- public class OrganisationWithPeopleLinker : IResourceLinker<OrganisationRepresentation>
- {
- public void CreateLinks(OrganisationRepresentation resource, IResourceLinker resourceLinker)
- {
- resource.Rel = "organisation";
- resource.Href = string.Format("/api/organisations/{0}", resource.Id);
- resource.Links.Add(new Link
- {
- Rel = "people",
- Href = string.Format("/api/organisations/{0}/people", resource.Id)
- });
- }
- }
-}
@@ -0,0 +1,19 @@
+using System.Collections.Generic;
+
+namespace WebApi.Hal.Tests.Representations
+{
+ public class OrganisationListRepresentation : RepresentationList<OrganisationRepresentation>
+ {
+ public OrganisationListRepresentation(IList<OrganisationRepresentation> organisationRepresentations) :
+ base(organisationRepresentations)
+ {
+
+ }
+
+ protected override void CreateHypermedia()
+ {
+ Rel = "organisations";
+ Href = "/api/organisations";
+ }
+ }
+}
@@ -1,6 +1,6 @@
namespace WebApi.Hal.Tests.Representations
{
- public class OrganisationRepresentation : Resource
+ public class OrganisationRepresentation : Representation
{
public OrganisationRepresentation()
{
@@ -14,5 +14,11 @@ public OrganisationRepresentation(int id, string name)
public int Id { get; set; }
public string Name { get; set; }
+
+ protected override void CreateHypermedia()
+ {
+ Rel = "organisation";
+ Href = string.Format("/api/organisations/{0}", Id);
+ }
}
}
@@ -0,0 +1,30 @@
+namespace WebApi.Hal.Tests.Representations
+{
+ public class OrganisationWithPeopleRepresentation : Representation
+ {
+ public OrganisationWithPeopleRepresentation()
+ {
+ }
+
+ public OrganisationWithPeopleRepresentation(int id, string name)
+ {
+ Id = id;
+ Name = name;
+ }
+
+ public int Id { get; set; }
+ public string Name { get; set; }
+
+ protected override void CreateHypermedia()
+ {
+ Rel = "organisation";
+ Href = string.Format("/api/organisations/{0}", Id);
+
+ Links.Add(new Link
+ {
+ Rel = "people",
+ Href = string.Format("/api/organisations/{0}/people", Id)
+ });
+ }
+ }
+}
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-using ApprovalTests;
-using ApprovalTests.Reporters;
-using Xunit;
-
-namespace WebApi.Hal.Tests
-{
- public class ResourceLinkerTests
- {
- [Fact]
- [UseReporter(typeof(DiffReporter))]
- public void throws_meaningful_exception_when_cannot_find_linker()
- {
- // arrange
- var resourceLinker = new ResourceLinker();
- Exception exception = null;
-
- // act
- try
- {
- resourceLinker.CreateLinks(new List<Resource>());
- }
- catch (ArgumentException ex)
- {
- exception = ex;
- }
-
- // assert
- Approvals.Verify(exception.Message);
- }
- }
-}
@@ -55,13 +55,11 @@
<ItemGroup>
<Compile Include="HalResourceWithPeopleTest.cs" />
<Compile Include="HalResourceTest.cs" />
- <Compile Include="Linkers\OrganisationLinker.cs" />
- <Compile Include="Linkers\OrganisationListLinker.cs" />
- <Compile Include="Linkers\OrganisationWithPeopleLinker.cs" />
+ <Compile Include="Representations\OrganisationListRepresentation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="HalResourceListTests.cs" />
<Compile Include="Representations\OrganisationRepresentation.cs" />
- <Compile Include="ResourceLinkerTests.cs" />
+ <Compile Include="Representations\OrganisationWithPeopleRepresentation.cs" />
<Compile Include="UriBuilderTests.cs" />
</ItemGroup>
<ItemGroup>
@@ -0,0 +1,19 @@
+<ProjectConfiguration>
+ <CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
+ <ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
+ <PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
+ <AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
+ <AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
+ <IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
+ <RunPreBuildEvents>false</RunPreBuildEvents>
+ <RunPostBuildEvents>false</RunPostBuildEvents>
+ <PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
+ <InstrumentAssembly>true</InstrumentAssembly>
+ <PreventSigningOfAssembly>false</PreventSigningOfAssembly>
+ <AnalyseExecutionTimes>true</AnalyseExecutionTimes>
+ <IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
+ <DefaultTestTimeout>60000</DefaultTestTimeout>
+ <UseBuildConfiguration />
+ <ProxyProcessPath />
+ <UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
+</ProjectConfiguration>
Oops, something went wrong.

0 comments on commit 6a1f5ed

Please sign in to comment.