Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Id,ChildDescription,MasterId
7500,"Child 1 Description",1500
7501,"Child 2 Description",1501
7502,"Child 3 Description",1501
7503,"Child 4 Description",1503
7504,"Child 5 Description",1503
7505,"Child 6 Description",1503
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Id,Description
1500,"Master 1 Description"
1501,"Master 2 Description"
1502,"Master 3 Description"
1503,"Master 4 Description"
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,18 @@ await AssertResponseContent(response,
HttpStatusCode.OK);
}
}

[TestMethod]
[DeploymentItem(@"Data\Master.csv", @"Data")]
[DeploymentItem(@"Data\Child.csv", @"Data")]
public async Task Get_related_to_many_integer_key()
{
using (var effortConnection = GetEffortConnection())
{
var response = await SubmitGet(effortConnection, "masters/1501/children");

await AssertResponseContent(response, @"Fixtures\FetchingResources\Get_related_to_many_integer_key_response.json", HttpStatusCode.OK);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"data": [
{
"type": "children",
"id": "7501",
"attributes": {
"child-description": "Child 2 Description"
},
"relationships": {
"master": {
"links": {
"self": "https://www.example.com/children/7501/relationships/master",
"related": "https://www.example.com/children/7501/master"
}
}
}
},
{
"type": "children",
"id": "7502",
"attributes": {
"child-description": "Child 3 Description"
},
"relationships": {
"master": {
"links": {
"self": "https://www.example.com/children/7502/relationships/master",
"related": "https://www.example.com/children/7502/master"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<EmbeddedResource Include="Fixtures\CreatingResources\Responses\Post_with_client_provided_id_Response.json" />
<EmbeddedResource Include="Fixtures\CreatingResources\Responses\Post_with_empty_id_Response.json" />
<None Include="App.config" />
<None Include="Data\Child.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Data\Master.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Data\Officer.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -233,6 +239,7 @@
<EmbeddedResource Include="Fixtures\Mapped\Responses\Get_resource_by_id_that_doesnt_exist.json" />
<EmbeddedResource Include="Fixtures\Mapped\Responses\Get_related_to_one_response.json" />
<EmbeddedResource Include="Fixtures\Mapped\Responses\Get_related_to_many_response.json" />
<EmbeddedResource Include="Fixtures\FetchingResources\Get_related_to_many_integer_key_response.json" />
<None Include="packages.config" />
</ItemGroup>
<Choose>
Expand Down

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp/Models/Child.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;

namespace JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp.Models
{
public class Child
{
public int Id { get; set; }

public string ChildDescription { get; set; }

[Required]
[JsonIgnore]
public int MasterId { get; set; }

[ForeignKey("MasterId")]
public Master Master { get; set; }
}
}
16 changes: 16 additions & 0 deletions JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp/Models/Master.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp.Models
{
public class Master
{
public int Id { get; set; }

public string Description { get; set; }

public virtual ICollection<Child> Children { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
public DbSet<StarshipClass> StarshipClasses { get; set; }
public DbSet<Officer> Officers { get; set; }
public DbSet<StarshipOfficerLink> StarshipOfficerLinks { get; set; }
public DbSet<Master> Masters { get; set; }
public DbSet<Child> Children { get; set; }
}
}
7 changes: 6 additions & 1 deletion JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using JSONAPI.EntityFramework;
using JSONAPI.EntityFramework.Configuration;
using Owin;
using System.Collections.Generic;

namespace JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp
{
Expand All @@ -33,7 +34,9 @@ public Startup(Func<TestDbContext> dbContextFactory)

public void Configuration(IAppBuilder app)
{
var configuration = new JsonApiConfiguration();
var configuration = new JsonApiConfiguration(
new Core.PluralizationService(
new Dictionary<string, string> { { "Child", "Children" } }));
configuration.RegisterEntityFrameworkResourceType<Building>();
configuration.RegisterEntityFrameworkResourceType<City>();
configuration.RegisterEntityFrameworkResourceType<Comment>();
Expand All @@ -58,6 +61,8 @@ public void Configuration(IAppBuilder app)
rc => rc.UseMaterializer<StarshipShipCounselorRelatedResourceMaterializer>());
}); // Example of a resource that is mapped from a DB entity
configuration.RegisterResourceType<StarshipOfficerDto>();
configuration.RegisterEntityFrameworkResourceType<Master>();
configuration.RegisterEntityFrameworkResourceType<Child>();

var configurator = new JsonApiHttpAutofacConfigurator();
configurator.OnApplicationLifetimeScopeCreating(builder =>
Expand Down
2 changes: 1 addition & 1 deletion JSONAPI/Core/ResourceTypeRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public IResourceTypeRegistration BuildRegistration(Type type, string resourceTyp
filterByIdFactory = (param, id) =>
{
var propertyExpr = Expression.Property(param, idProperty);
var idExpr = Expression.Constant(id);
var idExpr = Expression.Constant(Convert.ChangeType(id, idProperty.PropertyType));
return Expression.Equal(propertyExpr, idExpr);
};
}
Expand Down