-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported existing tests from #846 to verify they still work against the…
… new implementation in #1142
- Loading branch information
Bart Koelman
committed
Mar 31, 2022
1 parent
d12eec7
commit 2621afd
Showing
12 changed files
with
543 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Animal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public abstract class Animal : Identifiable<long> | ||
{ | ||
[Attr] | ||
public bool Feline { get; set; } | ||
|
||
[Attr] | ||
public bool IsDomesticated { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Book.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public sealed class Book : Content | ||
{ | ||
[Attr] | ||
public int PageCount { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Cat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
public sealed class Cat : Animal | ||
{ | ||
[Attr] | ||
public bool ScaredOfDogs { get; set; } | ||
|
||
public Cat() | ||
{ | ||
Feline = true; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Content.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public abstract class Content : Identifiable<long> | ||
{ | ||
[HasMany] | ||
public List<Person> Author { get; set; } = new(); | ||
} |
12 changes: 12 additions & 0 deletions
12
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Dog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public sealed class Dog : Animal | ||
{ | ||
[Attr] | ||
public bool RespondsToName { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Female.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public sealed class Female : Person | ||
{ | ||
[Attr] | ||
public bool IsPregnant { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Male.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public sealed class Male : Person | ||
{ | ||
[Attr] | ||
public bool HasBeard { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Person.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public abstract class Person : Identifiable<long> | ||
{ | ||
[Attr] | ||
public bool Retired { get; set; } | ||
|
||
[HasOne] | ||
public Animal? Pet { get; set; } | ||
|
||
[HasMany] | ||
public List<Person> Parents { get; set; } = new(); | ||
|
||
[HasMany] | ||
public List<Content> FavoriteContent { get; set; } = new(); | ||
} |
12 changes: 12 additions & 0 deletions
12
test/JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance/Models/Video.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCore.Resources.Annotations; | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
[Resource(ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance")] | ||
public sealed class Video : Content | ||
{ | ||
[Attr] | ||
public int Duration { get; set; } | ||
} |
45 changes: 45 additions & 0 deletions
45
...otNetCoreTests/IntegrationTests/LegacyResourceInheritance/ResourceInheritanceDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using JetBrains.Annotations; | ||
using JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
// @formatter:wrap_chained_method_calls chop_always | ||
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance; | ||
|
||
[UsedImplicitly(ImplicitUseTargetFlags.Members)] | ||
public sealed class ResourceInheritanceDbContext : DbContext | ||
{ | ||
public DbSet<Person> People => Set<Person>(); | ||
public DbSet<Cat> Cats => Set<Cat>(); | ||
public DbSet<Dog> Dogs => Set<Dog>(); | ||
public DbSet<Female> Females => Set<Female>(); | ||
public DbSet<Male> Males => Set<Male>(); | ||
public DbSet<Book> FictionBooks => Set<Book>(); | ||
public DbSet<Video> NonFictionBooks => Set<Video>(); | ||
|
||
public ResourceInheritanceDbContext(DbContextOptions<ResourceInheritanceDbContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Person>() | ||
.ToTable("Persons") | ||
.HasDiscriminator<int>("Type") | ||
.HasValue<Male>(1) | ||
.HasValue<Female>(2); | ||
|
||
modelBuilder.Entity<Animal>() | ||
.ToTable("Animals") | ||
.HasDiscriminator<int>("Type") | ||
.HasValue<Cat>(1) | ||
.HasValue<Dog>(2); | ||
|
||
modelBuilder.Entity<Content>() | ||
.ToTable("Books") | ||
.HasDiscriminator<int>("Type") | ||
.HasValue<Video>(1) | ||
.HasValue<Book>(2); | ||
} | ||
} |
Oops, something went wrong.