Skip to content
Closed
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,15 @@
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Controllers
{
public class TagsController : JsonApiController<Tag>
{
public TagsController(
IJsonApiContext jsonApiContext,
IResourceService<Tag> resourceService)
: base(jsonApiContext, resourceService)
{ }
}
}
31 changes: 31 additions & 0 deletions test/JsonApiDotNetCoreExampleTests/Acceptance/ManyToManyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,38 @@ public ManyToManyTests(TestFixture<TestStartup> fixture)
{
_fixture = fixture;
}
[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";
// act
var response = await _fixture.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.NotNull(document.Data);

var tagResponse = _fixture.GetService<IJsonApiDeSerializer>().Deserialize<Tag>(body);
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_All()
{
Expand Down