1
- using System . Collections . Generic ;
2
- using GettingStarted . Models ;
3
- using GettingStarted . ResourceDefinitionExample ;
4
- using JsonApiDotNetCore . Builders ;
1
+ using System . Collections . Generic ;
2
+ using GettingStarted . Models ;
3
+ using GettingStarted . ResourceDefinitionExample ;
4
+ using JsonApiDotNetCore . Builders ;
5
5
using JsonApiDotNetCore . Configuration ;
6
- using JsonApiDotNetCore . Data ;
7
- using JsonApiDotNetCore . Graph ;
6
+ using JsonApiDotNetCore . Data ;
7
+ using JsonApiDotNetCore . Graph ;
8
8
using JsonApiDotNetCore . Hooks ;
9
9
using JsonApiDotNetCore . Internal . Contracts ;
10
10
using JsonApiDotNetCore . Internal . Generics ;
11
11
using JsonApiDotNetCore . Managers . Contracts ;
12
- using JsonApiDotNetCore . Models ;
12
+ using JsonApiDotNetCore . Models ;
13
13
using JsonApiDotNetCore . Query ;
14
14
using JsonApiDotNetCore . Serialization ;
15
15
using JsonApiDotNetCore . Serialization . Server . Builders ;
16
- using JsonApiDotNetCore . Services ;
16
+ using JsonApiDotNetCore . Services ;
17
17
using Microsoft . EntityFrameworkCore ;
18
- using Microsoft . Extensions . DependencyInjection ;
18
+ using Microsoft . Extensions . DependencyInjection ;
19
19
using Microsoft . Extensions . Logging ;
20
- using Moq ;
21
- using Xunit ;
22
-
23
- namespace DiscoveryTests
24
- {
25
- public class ServiceDiscoveryFacadeTests
26
- {
27
- private readonly IServiceCollection _services = new ServiceCollection ( ) ;
20
+ using Moq ;
21
+ using Xunit ;
22
+
23
+ namespace DiscoveryTests
24
+ {
25
+ public class ServiceDiscoveryFacadeTests
26
+ {
27
+ private readonly IServiceCollection _services = new ServiceCollection ( ) ;
28
28
private readonly ResourceGraphBuilder _resourceGraphBuilder = new ResourceGraphBuilder ( ) ;
29
29
30
30
public ServiceDiscoveryFacadeTests ( )
31
31
{
32
- var contextMock = new Mock < DbContext > ( ) ;
33
- var dbResolverMock = new Mock < IDbContextResolver > ( ) ;
34
- dbResolverMock . Setup ( m => m . GetContext ( ) ) . Returns ( new Mock < DbContext > ( ) . Object ) ;
32
+ var contextMock = new Mock < DbContext > ( ) ;
33
+ var dbResolverMock = new Mock < IDbContextResolver > ( ) ;
34
+ dbResolverMock . Setup ( m => m . GetContext ( ) ) . Returns ( new Mock < DbContext > ( ) . Object ) ;
35
35
TestModelRepository . _dbContextResolver = dbResolverMock . Object ;
36
- _services . AddSingleton < IJsonApiOptions > ( new JsonApiOptions ( ) ) ;
36
+ _services . AddSingleton < IJsonApiOptions > ( new JsonApiOptions ( ) ) ;
37
37
_services . AddScoped ( ( _ ) => new Mock < ILinkBuilder > ( ) . Object ) ;
38
- _services . AddScoped ( ( _ ) => new Mock < ICurrentRequest > ( ) . Object ) ;
39
- _services . AddScoped ( ( _ ) => new Mock < ITargetedFields > ( ) . Object ) ;
38
+ _services . AddScoped ( ( _ ) => new Mock < ICurrentRequest > ( ) . Object ) ;
39
+ _services . AddScoped ( ( _ ) => new Mock < ITargetedFields > ( ) . Object ) ;
40
40
_services . AddScoped ( ( _ ) => new Mock < IResourceGraph > ( ) . Object ) ;
41
41
_services . AddScoped ( ( _ ) => new Mock < IGenericServiceFactory > ( ) . Object ) ;
42
42
_services . AddScoped ( ( _ ) => new Mock < IResourceContextProvider > ( ) . Object ) ;
43
43
}
44
44
45
- private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade ( _services , _resourceGraphBuilder ) ;
46
-
47
- [ Fact ]
48
- public void AddAssembly_Adds_All_Resources_To_Graph ( )
49
- {
50
- // arrange, act
51
- _facade . AddAssembly ( typeof ( Person ) . Assembly ) ;
52
-
53
- // assert
54
- var resourceGraph = _resourceGraphBuilder . Build ( ) ;
55
- var personResource = resourceGraph . GetResourceContext ( typeof ( Person ) ) ;
56
- var articleResource = resourceGraph . GetResourceContext ( typeof ( Article ) ) ;
57
- var modelResource = resourceGraph . GetResourceContext ( typeof ( Model ) ) ;
58
-
59
- Assert . NotNull ( personResource ) ;
60
- Assert . NotNull ( articleResource ) ;
61
- Assert . NotNull ( modelResource ) ;
62
- }
63
-
64
- [ Fact ]
65
- public void AddCurrentAssembly_Adds_Resources_To_Graph ( )
66
- {
67
- // arrange, act
68
- _facade . AddCurrentAssembly ( ) ;
69
-
70
- // assert
71
- var resourceGraph = _resourceGraphBuilder . Build ( ) ;
72
- var testModelResource = resourceGraph . GetResourceContext ( typeof ( TestModel ) ) ;
73
- Assert . NotNull ( testModelResource ) ;
74
- }
75
-
76
- [ Fact ]
77
- public void AddCurrentAssembly_Adds_Services_To_Container ( )
45
+ private ServiceDiscoveryFacade _facade => new ServiceDiscoveryFacade ( _services , _resourceGraphBuilder ) ;
46
+
47
+ [ Fact ]
48
+ public void AddAssembly_Adds_All_Resources_To_Graph ( )
49
+ {
50
+ // Arrange, act
51
+ _facade . AddAssembly ( typeof ( Person ) . Assembly ) ;
52
+
53
+ // Assert
54
+ var resourceGraph = _resourceGraphBuilder . Build ( ) ;
55
+ var personResource = resourceGraph . GetResourceContext ( typeof ( Person ) ) ;
56
+ var articleResource = resourceGraph . GetResourceContext ( typeof ( Article ) ) ;
57
+ var modelResource = resourceGraph . GetResourceContext ( typeof ( Model ) ) ;
58
+
59
+ Assert . NotNull ( personResource ) ;
60
+ Assert . NotNull ( articleResource ) ;
61
+ Assert . NotNull ( modelResource ) ;
62
+ }
63
+
64
+ [ Fact ]
65
+ public void AddCurrentAssembly_Adds_Resources_To_Graph ( )
66
+ {
67
+ // Arrange, act
68
+ _facade . AddCurrentAssembly ( ) ;
69
+
70
+ // Assert
71
+ var resourceGraph = _resourceGraphBuilder . Build ( ) ;
72
+ var testModelResource = resourceGraph . GetResourceContext ( typeof ( TestModel ) ) ;
73
+ Assert . NotNull ( testModelResource ) ;
74
+ }
75
+
76
+ [ Fact ]
77
+ public void AddCurrentAssembly_Adds_Services_To_Container ( )
78
+ {
79
+ // Arrange, act
80
+ _facade . AddCurrentAssembly ( ) ;
81
+
82
+ // Assert
83
+ var services = _services . BuildServiceProvider ( ) ;
84
+ var service = services . GetService < IResourceService < TestModel > > ( ) ;
85
+ Assert . IsType < TestModelService > ( service ) ;
86
+ }
87
+
88
+ [ Fact ]
89
+ public void AddCurrentAssembly_Adds_Repositories_To_Container ( )
90
+ {
91
+ // Arrange, act
92
+ _facade . AddCurrentAssembly ( ) ;
93
+
94
+ // Assert
95
+ var services = _services . BuildServiceProvider ( ) ;
96
+ Assert . IsType < TestModelRepository > ( services . GetService < IResourceRepository < TestModel > > ( ) ) ;
97
+ }
98
+
99
+ public class TestModel : Identifiable { }
100
+
101
+ public class TestModelService : DefaultResourceService < TestModel >
78
102
{
79
- // arrange, act
80
- _facade . AddCurrentAssembly ( ) ;
81
-
82
- // assert
83
- var services = _services . BuildServiceProvider ( ) ;
84
- var service = services . GetService < IResourceService < TestModel > > ( ) ;
85
- Assert . IsType < TestModelService > ( service ) ;
86
- }
87
-
88
- [ Fact ]
89
- public void AddCurrentAssembly_Adds_Repositories_To_Container ( )
90
- {
91
- // arrange, act
92
- _facade . AddCurrentAssembly ( ) ;
93
-
94
- // assert
95
- var services = _services . BuildServiceProvider ( ) ;
96
- Assert . IsType < TestModelRepository > ( services . GetService < IResourceRepository < TestModel > > ( ) ) ;
97
- }
98
-
99
- public class TestModel : Identifiable { }
100
-
101
- public class TestModelService : DefaultResourceService < TestModel >
102
- {
103
103
private static IResourceRepository < TestModel > _repo = new Mock < IResourceRepository < TestModel > > ( ) . Object ;
104
104
105
105
public TestModelService ( IEnumerable < IQueryParameterService > queryParameters ,
@@ -109,16 +109,16 @@ public TestModelService(IEnumerable<IQueryParameterService> queryParameters,
109
109
IResourceHookExecutor hookExecutor = null ,
110
110
ILoggerFactory loggerFactory = null )
111
111
: base ( queryParameters , options , repository , provider , hookExecutor , loggerFactory ) { }
112
- }
113
-
114
- public class TestModelRepository : DefaultResourceRepository < TestModel >
115
- {
112
+ }
113
+
114
+ public class TestModelRepository : DefaultResourceRepository < TestModel >
115
+ {
116
116
internal static IDbContextResolver _dbContextResolver ;
117
117
118
118
public TestModelRepository ( ITargetedFields targetedFields ,
119
119
IResourceGraph resourceGraph ,
120
120
IGenericServiceFactory genericServiceFactory )
121
121
: base ( targetedFields , _dbContextResolver , resourceGraph , genericServiceFactory ) { }
122
- }
123
- }
124
- }
122
+ }
123
+ }
124
+ }
0 commit comments