File tree 12 files changed +543
-0
lines changed
JsonApiDotNetCoreTests/IntegrationTests/LegacyResourceInheritance
12 files changed +543
-0
lines changed Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources ;
3
+ using JsonApiDotNetCore . Resources . Annotations ;
4
+
5
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
6
+
7
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
8
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
9
+ public abstract class Animal : Identifiable < long >
10
+ {
11
+ [ Attr ]
12
+ public bool Feline { get ; set ; }
13
+
14
+ [ Attr ]
15
+ public bool IsDomesticated { get ; set ; }
16
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
7
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
8
+ public sealed class Book : Content
9
+ {
10
+ [ Attr ]
11
+ public int PageCount { get ; set ; }
12
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
7
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
8
+ public sealed class Cat : Animal
9
+ {
10
+ [ Attr ]
11
+ public bool ScaredOfDogs { get ; set ; }
12
+
13
+ public Cat ( )
14
+ {
15
+ Feline = true ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources ;
3
+ using JsonApiDotNetCore . Resources . Annotations ;
4
+
5
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
6
+
7
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
8
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
9
+ public abstract class Content : Identifiable < long >
10
+ {
11
+ [ HasMany ]
12
+ public List < Person > Author { get ; set ; } = new ( ) ;
13
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
7
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
8
+ public sealed class Dog : Animal
9
+ {
10
+ [ Attr ]
11
+ public bool RespondsToName { get ; set ; }
12
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
7
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
8
+ public sealed class Female : Person
9
+ {
10
+ [ Attr ]
11
+ public bool IsPregnant { get ; set ; }
12
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
7
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
8
+ public sealed class Male : Person
9
+ {
10
+ [ Attr ]
11
+ public bool HasBeard { get ; set ; }
12
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources ;
3
+ using JsonApiDotNetCore . Resources . Annotations ;
4
+
5
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
6
+
7
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
8
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
9
+ public abstract class Person : Identifiable < long >
10
+ {
11
+ [ Attr ]
12
+ public bool Retired { get ; set ; }
13
+
14
+ [ HasOne ]
15
+ public Animal ? Pet { get ; set ; }
16
+
17
+ [ HasMany ]
18
+ public List < Person > Parents { get ; set ; } = new ( ) ;
19
+
20
+ [ HasMany ]
21
+ public List < Content > FavoriteContent { get ; set ; } = new ( ) ;
22
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCore . Resources . Annotations ;
3
+
4
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
5
+
6
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
7
+ [ Resource ( ControllerNamespace = "JsonApiDotNetCoreTests.IntegrationTests.LegacyResourceInheritance" ) ]
8
+ public sealed class Video : Content
9
+ {
10
+ [ Attr ]
11
+ public int Duration { get ; set ; }
12
+ }
Original file line number Diff line number Diff line change
1
+ using JetBrains . Annotations ;
2
+ using JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance . Models ;
3
+ using Microsoft . EntityFrameworkCore ;
4
+
5
+ // @formatter:wrap_chained_method_calls chop_always
6
+
7
+ namespace JsonApiDotNetCoreTests . IntegrationTests . LegacyResourceInheritance ;
8
+
9
+ [ UsedImplicitly ( ImplicitUseTargetFlags . Members ) ]
10
+ public sealed class ResourceInheritanceDbContext : DbContext
11
+ {
12
+ public DbSet < Person > People => Set < Person > ( ) ;
13
+ public DbSet < Cat > Cats => Set < Cat > ( ) ;
14
+ public DbSet < Dog > Dogs => Set < Dog > ( ) ;
15
+ public DbSet < Female > Females => Set < Female > ( ) ;
16
+ public DbSet < Male > Males => Set < Male > ( ) ;
17
+ public DbSet < Book > FictionBooks => Set < Book > ( ) ;
18
+ public DbSet < Video > NonFictionBooks => Set < Video > ( ) ;
19
+
20
+ public ResourceInheritanceDbContext ( DbContextOptions < ResourceInheritanceDbContext > options )
21
+ : base ( options )
22
+ {
23
+ }
24
+
25
+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
26
+ {
27
+ modelBuilder . Entity < Person > ( )
28
+ . ToTable ( "Persons" )
29
+ . HasDiscriminator < int > ( "Type" )
30
+ . HasValue < Male > ( 1 )
31
+ . HasValue < Female > ( 2 ) ;
32
+
33
+ modelBuilder . Entity < Animal > ( )
34
+ . ToTable ( "Animals" )
35
+ . HasDiscriminator < int > ( "Type" )
36
+ . HasValue < Cat > ( 1 )
37
+ . HasValue < Dog > ( 2 ) ;
38
+
39
+ modelBuilder . Entity < Content > ( )
40
+ . ToTable ( "Books" )
41
+ . HasDiscriminator < int > ( "Type" )
42
+ . HasValue < Video > ( 1 )
43
+ . HasValue < Book > ( 2 ) ;
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments