diff --git a/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs b/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs new file mode 100644 index 0000000000..5167f317ec --- /dev/null +++ b/src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs @@ -0,0 +1,18 @@ +using JsonApiDotNetCore.Configuration; +using JsonApiDotNetCore.Controllers; +using JsonApiDotNetCore.Services; +using JsonApiDotNetCoreExample.Models; +using Microsoft.Extensions.Logging; + +namespace JsonApiDotNetCoreExample.Controllers +{ + public class TagsController : JsonApiController + { + public TagsController( + IJsonApiOptions jsonApiOptions, + IResourceService resourceService, + ILoggerFactory loggerFactory) + : base(jsonApiOptions, resourceService, loggerFactory) + { } + } +} diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs index 6b6bb526a3..1ef254b8dd 100644 --- a/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs +++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs @@ -122,6 +122,45 @@ public async Task Can_Fetch_Many_To_Many_Through_GetById() Assert.Equal(tag.Name, tagResponse.Name); } + [Fact] + public async Task Can_Fetch_Many_To_Many_Through_Id() + { + // Arrange + var context = _fixture.GetService(); + var article = _articleFaker.Generate(); + var tag = _tagFaker.Generate(); + var articleTag = new ArticleTag + { + Article = article, + Tag = tag + }; + context.ArticleTags.Add(articleTag); + await context.SaveChangesAsync(); + + var route = $"/api/v1/articles/{article.Id}/tags"; + + // @TODO - Use fixture + var builder = new WebHostBuilder() + .UseStartup(); + var server = new TestServer(builder); + var client = server.CreateClient(); + + // Act + var response = await client.GetAsync(route); + + // Assert + var body = await response.Content.ReadAsStringAsync(); + Assert.True(HttpStatusCode.OK == response.StatusCode, $"{route} returned {response.StatusCode} status code with payload: {body}"); + + var document = JsonConvert.DeserializeObject(body); + Assert.Single(document.ManyData); + + var tagResponse = _fixture.GetDeserializer().DeserializeList(body).Data.First(); + Assert.NotNull(tagResponse); + Assert.Equal(tag.Id, tagResponse.Id); + Assert.Equal(tag.Name, tagResponse.Name); + } + [Fact] public async Task Can_Fetch_Many_To_Many_Through_GetById_Relationship_Link() { @@ -160,7 +199,6 @@ public async Task Can_Fetch_Many_To_Many_Through_GetById_Relationship_Link() Assert.Equal(tag.Id, tagResponse.Id); } - [Fact] public async Task Can_Fetch_Many_To_Many_Through_Relationship_Link() {