@@ -7,81 +7,81 @@ namespace ClassLibrary.EFCore.Tests;
7
7
public class Tests : InMemoryDbContext
8
8
{
9
9
[ Fact ]
10
- public void GetAllEntities ( )
10
+ public async Task GetAllEntities ( )
11
11
{
12
12
using var dbContext = GetDbContext ( ) ;
13
- Repository < Person , int > repository = new ( dbContext ) ;
13
+ var repository = new Repository < Person , int > ( dbContext ) ;
14
14
15
- dbContext . Database . EnsureDeletedAsync ( ) ;
16
- dbContext . Database . EnsureCreatedAsync ( ) ;
15
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
16
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
17
17
18
- var entities = repository . GetAllAsync ( ) ;
18
+ var entities = await repository . GetAllAsync ( ) ;
19
19
20
20
Assert . NotNull ( entities ) ;
21
21
}
22
22
23
23
[ Fact ]
24
- public void GetAllEntitiesWithPredicate ( )
24
+ public async Task GetAllEntitiesWithPredicateAsync ( )
25
25
{
26
26
using var dbContext = GetDbContext ( ) ;
27
- Repository < Person , int > repository = new ( dbContext ) ;
27
+ var repository = new Repository < Person , int > ( dbContext ) ;
28
28
29
- dbContext . Database . EnsureDeletedAsync ( ) ;
30
- dbContext . Database . EnsureCreatedAsync ( ) ;
29
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
30
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
31
31
32
- var entities = repository . GetAllEntitiesAsync ( predicate : x => x . Id is >= 3 and <= 8 ) ;
32
+ var entities = await repository . GetAllEntitiesAsync ( predicate : x => x . Id is >= 3 and <= 8 ) ;
33
33
34
- Assert . Equal ( 6 , entities ? . Result . Count ) ;
34
+ Assert . Equal ( 6 , entities . Count ) ;
35
35
Assert . NotNull ( entities ) ;
36
36
}
37
37
38
38
[ Fact ]
39
- public void GetEntityById ( )
39
+ public async Task GetEntityByIdAsync ( )
40
40
{
41
41
using var dbContext = GetDbContext ( ) ;
42
- Repository < Person , int > repository = new ( dbContext ) ;
42
+ var repository = new Repository < Person , int > ( dbContext ) ;
43
43
44
- dbContext . Database . EnsureDeletedAsync ( ) ;
45
- dbContext . Database . EnsureCreatedAsync ( ) ;
44
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
45
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
46
46
47
- var entity = repository . GetByIdAsync ( 2 ) ;
47
+ var entity = await repository . GetByIdAsync ( 2 ) ;
48
48
49
49
Assert . NotNull ( entity ) ;
50
- Assert . Equal ( 2 , Assert . IsType < Person > ( entity ? . Result ) . Id ) ;
51
- Assert . Equal ( "Nome2" , Assert . IsType < Person > ( entity ? . Result ) . Nome ) ;
52
- Assert . Equal ( "Cognome2" , Assert . IsType < Person > ( entity ? . Result ) . Cognome ) ;
50
+ Assert . Equal ( 2 , Assert . IsType < Person > ( entity ) . Id ) ;
51
+ Assert . Equal ( "Nome2" , Assert . IsType < Person > ( entity ) . Nome ) ;
52
+ Assert . Equal ( "Cognome2" , Assert . IsType < Person > ( entity ) . Cognome ) ;
53
53
}
54
54
55
55
[ Fact ]
56
- public void GetEntityByIdNotFound ( )
56
+ public async Task GetEntityByIdNotFoundAsync ( )
57
57
{
58
58
using var dbContext = GetDbContext ( ) ;
59
- Repository < Person , int > repository = new ( dbContext ) ;
59
+ var repository = new Repository < Person , int > ( dbContext ) ;
60
60
61
- dbContext . Database . EnsureDeletedAsync ( ) ;
62
- dbContext . Database . EnsureCreatedAsync ( ) ;
61
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
62
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
63
63
64
- var entity = repository . GetByIdAsync ( 30 ) ? . Result ;
64
+ var entity = await repository . GetByIdAsync ( 30 ) ;
65
65
66
66
Assert . Null ( entity ) ;
67
67
}
68
68
69
69
[ Fact ]
70
- public void CreateEntity ( )
70
+ public async Task CreateEntityAsync ( )
71
71
{
72
72
using var dbContext = GetDbContext ( ) ;
73
- Repository < Person , int > repository = new ( dbContext ) ;
73
+ var repository = new Repository < Person , int > ( dbContext ) ;
74
74
75
- dbContext . Database . EnsureDeletedAsync ( ) ;
76
- dbContext . Database . EnsureCreatedAsync ( ) ;
75
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
76
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
77
77
78
78
var entity = new Person
79
79
{
80
80
Nome = "Nome11" ,
81
81
Cognome = "Cognome11"
82
82
} ;
83
83
84
- repository ? . CreateAsync ( entity ) ;
84
+ await repository . CreateAsync ( entity ) ;
85
85
86
86
Assert . NotNull ( entity ) ;
87
87
Assert . Equal ( 11 , entity . Id ) ;
@@ -90,20 +90,20 @@ public void CreateEntity()
90
90
}
91
91
92
92
[ Fact ]
93
- public void UpdateEntity ( )
93
+ public async Task UpdateEntityAsync ( )
94
94
{
95
95
using var dbContext = GetDbContext ( ) ;
96
- Repository < Person , int > repository = new ( dbContext ) ;
96
+ var repository = new Repository < Person , int > ( dbContext ) ;
97
97
98
- dbContext . Database . EnsureDeletedAsync ( ) ;
99
- dbContext . Database . EnsureCreatedAsync ( ) ;
98
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
99
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
100
100
101
- var entity = repository . GetByIdAsync ( 2 ) ? . Result ;
101
+ var entity = await repository . GetByIdAsync ( 2 ) ;
102
102
103
- entity ! . Nome = "Nome2-bis" ;
104
- entity ! . Cognome = "Cognome2-bis" ;
103
+ entity . Nome = "Nome2-bis" ;
104
+ entity . Cognome = "Cognome2-bis" ;
105
105
106
- repository ? . UpdateAsync ( entity ) ;
106
+ await repository . UpdateAsync ( entity ) ;
107
107
108
108
Assert . NotNull ( entity ) ;
109
109
Assert . Equal ( 2 , entity . Id ) ;
@@ -112,102 +112,102 @@ public void UpdateEntity()
112
112
}
113
113
114
114
[ Fact ]
115
- public void DeleteEntity ( )
115
+ public async Task DeleteEntityAsync ( )
116
116
{
117
117
using var dbContext = GetDbContext ( ) ;
118
- Repository < Person , int > repository = new ( dbContext ) ;
118
+ var repository = new Repository < Person , int > ( dbContext ) ;
119
119
120
- dbContext . Database . EnsureDeletedAsync ( ) ;
121
- dbContext . Database . EnsureCreatedAsync ( ) ;
120
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
121
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
122
122
123
- var entity = repository . GetByIdAsync ( 4 ) ? . Result ;
124
- repository ? . DeleteAsync ( entity ! ) ;
123
+ var entity = await repository . GetByIdAsync ( 4 ) ;
124
+ await repository . DeleteAsync ( entity ! ) ;
125
125
126
- var entities = repository ? . GetAllAsync ( ) ;
126
+ var entities = await repository . GetAllAsync ( ) ;
127
127
128
128
Assert . NotNull ( entities ) ;
129
- Assert . Equal ( 9 , entities ? . Result . Count ) ;
129
+ Assert . Equal ( 9 , entities . Count ) ;
130
130
}
131
131
132
132
[ Fact ]
133
- public void DeleteByIdEntity ( )
133
+ public async Task DeleteByIdEntityAsync ( )
134
134
{
135
135
using var dbContext = GetDbContext ( ) ;
136
- Repository < Person , int > repository = new ( dbContext ) ;
136
+ var repository = new Repository < Person , int > ( dbContext ) ;
137
137
138
- dbContext . Database . EnsureDeletedAsync ( ) ;
139
- dbContext . Database . EnsureCreatedAsync ( ) ;
138
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
139
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
140
140
141
- repository ? . DeleteByIdAsync ( 4 ) ;
141
+ await repository . DeleteByIdAsync ( 4 ) ;
142
142
143
- var entities = repository ? . GetAllAsync ( ) ;
143
+ var entities = await repository . GetAllAsync ( ) ;
144
144
145
145
Assert . NotNull ( entities ) ;
146
- Assert . Equal ( 9 , entities ? . Result . Count ) ;
146
+ Assert . Equal ( 9 , entities . Count ) ;
147
147
}
148
148
149
149
[ Fact ]
150
- public void GetPaginatedEntities ( )
150
+ public async Task GetPaginatedEntitiesAsync ( )
151
151
{
152
152
using var dbContext = GetDbContext ( ) ;
153
- Repository < Person , int > repository = new ( dbContext ) ;
153
+ var repository = new Repository < Person , int > ( dbContext ) ;
154
154
155
- dbContext . Database . EnsureDeletedAsync ( ) ;
156
- dbContext . Database . EnsureCreatedAsync ( ) ;
155
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
156
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
157
157
158
- var entities = repository . GetPaginatedAsync ( null ! , x => x . Id <= 10 , x => x . Id , true , 2 , 5 ) ;
158
+ var entities = await repository . GetPaginatedAsync ( null ! , x => x . Id <= 10 , x => x . Id , true , 2 , 5 ) ;
159
159
160
160
Assert . NotNull ( entities ) ;
161
- Assert . Equal ( 5 , entities ? . Result . Count ) ;
162
- Assert . Contains ( entities ! . Result , x => x . Id == 8 ) ;
161
+ Assert . Equal ( 5 , entities . Count ) ;
162
+ Assert . Contains ( entities , x => x . Id == 8 ) ;
163
163
}
164
164
165
165
[ Fact ]
166
- public void GetPaginatedEntitiesWithoutInclude ( )
166
+ public async Task GetPaginatedEntitiesWithoutIncludeAsync ( )
167
167
{
168
168
using var dbContext = GetDbContext ( ) ;
169
- Repository < Person , int > repository = new ( dbContext ) ;
169
+ var repository = new Repository < Person , int > ( dbContext ) ;
170
170
171
- dbContext . Database . EnsureDeletedAsync ( ) ;
172
- dbContext . Database . EnsureCreatedAsync ( ) ;
171
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
172
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
173
173
174
- var entities = repository . GetPaginatedAsync ( null ! , x => x . Id <= 10 , x => x . Id , true , 2 , 5 ) ;
174
+ var entities = await repository . GetPaginatedAsync ( null ! , x => x . Id <= 10 , x => x . Id , true , 2 , 5 ) ;
175
175
176
176
Assert . NotNull ( entities ) ;
177
- Assert . Equal ( 5 , entities ? . Result . Count ) ;
178
- Assert . Contains ( entities ! . Result , x => x . Id == 8 ) ;
177
+ Assert . Equal ( 5 , entities . Count ) ;
178
+ Assert . Contains ( entities , x => x . Id == 8 ) ;
179
179
}
180
180
181
181
[ Fact ]
182
- public void GetPaginatedEntitiesWithoutWhere ( )
182
+ public async Task GetPaginatedEntitiesWithoutWhereAsync ( )
183
183
{
184
184
using var dbContext = GetDbContext ( ) ;
185
- Repository < Person , int > repository = new ( dbContext ) ;
185
+ var repository = new Repository < Person , int > ( dbContext ) ;
186
186
187
- dbContext . Database . EnsureDeletedAsync ( ) ;
188
- dbContext . Database . EnsureCreatedAsync ( ) ;
187
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
188
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
189
189
190
- var entities = repository . GetPaginatedAsync ( null ! , null ! , x => x . Id , true , 1 , 5 ) ;
190
+ var entities = await repository . GetPaginatedAsync ( null ! , null ! , x => x . Id , true , 1 , 5 ) ;
191
191
192
192
Assert . NotNull ( entities ) ;
193
- Assert . Equal ( 5 , entities ? . Result . Count ) ;
194
- Assert . Contains ( entities ! . Result , x => x . Id == 3 ) ;
193
+ Assert . Equal ( 5 , entities . Count ) ;
194
+ Assert . Contains ( entities , x => x . Id == 3 ) ;
195
195
}
196
196
197
197
[ Fact ]
198
- public void GetPaginatedEntitiesDescendingOrderType ( )
198
+ public async Task GetPaginatedEntitiesDescendingOrderTypeAsync ( )
199
199
{
200
200
using var dbContext = GetDbContext ( ) ;
201
- Repository < Person , int > repository = new ( dbContext ) ;
201
+ var repository = new Repository < Person , int > ( dbContext ) ;
202
202
203
- dbContext . Database . EnsureDeletedAsync ( ) ;
204
- dbContext . Database . EnsureCreatedAsync ( ) ;
203
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
204
+ await dbContext . Database . EnsureCreatedAsync ( ) ;
205
205
206
- var entities = repository . GetPaginatedAsync ( null ! , null ! , x => x . Id , false , 1 , 5 ) ;
206
+ var entities = await repository . GetPaginatedAsync ( null ! , null ! , x => x . Id , false , 1 , 5 ) ;
207
207
208
208
Assert . NotNull ( entities ) ;
209
- Assert . Equal ( 5 , entities ? . Result . Count ) ;
210
- Assert . Equal ( 10 , Assert . IsType < Person > ( entities ? . Result . First ( ) ) . Id ) ;
211
- Assert . Contains ( entities ! . Result , x => x . Id == 8 ) ;
209
+ Assert . Equal ( 5 , entities . Count ) ;
210
+ Assert . Equal ( 10 , Assert . IsType < Person > ( entities . First ( ) ) . Id ) ;
211
+ Assert . Contains ( entities , x => x . Id == 8 ) ;
212
212
}
213
213
}
0 commit comments