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,18 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;
using Microsoft.Extensions.Logging;

namespace JsonApiDotNetCoreExample.Controllers
{
public class TagsController : JsonApiController<Tag>
{
public TagsController(
IJsonApiOptions jsonApiOptions,
IResourceService<Tag> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
{ }
}
}
40 changes: 39 additions & 1 deletion test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppDbContext>();
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<Startup>();
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<Document>(body);
Assert.Single(document.ManyData);

var tagResponse = _fixture.GetDeserializer().DeserializeList<Tag>(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()
{
Expand Down Expand Up @@ -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()
{
Expand Down