8
8
using System . Threading . Tasks ;
9
9
using System . Net ;
10
10
using JsonApiDotNetCoreExample . Models ;
11
+ using JsonApiDotNetCoreExample . Data ;
12
+ using Microsoft . EntityFrameworkCore ;
13
+ using Microsoft . Extensions . Configuration ;
11
14
12
15
namespace JsonApiDotNetCoreExampleTests . Acceptance . Extensibility
13
16
{
14
17
public class NoEntityFrameworkTests
15
18
{
19
+ private readonly TestServer _server ;
20
+ private readonly IConfiguration _config ;
21
+ private readonly AppDbContext _context ;
22
+
23
+ public NoEntityFrameworkTests ( )
24
+ {
25
+ var builder = new WebHostBuilder ( )
26
+ . UseStartup < Startup > ( ) ;
27
+ _server = new TestServer ( builder ) ;
28
+ _config = _server . GetService < IConfiguration > ( ) ;
29
+
30
+ var optionsBuilder = new DbContextOptionsBuilder < AppDbContext > ( ) ;
31
+ optionsBuilder . UseNpgsql ( _config . GetValue < string > ( "Data:DefaultConnection" ) ) ;
32
+ _context = new AppDbContext ( optionsBuilder . Options ) ;
33
+ _context . Database . EnsureCreated ( ) ;
34
+ }
35
+
16
36
[ Fact ]
17
37
public async Task Can_Implement_Custom_IResourceService_Without_EFAsync ( )
18
38
{
19
39
// arrange
20
- var builder = new WebHostBuilder ( )
21
- . UseStartup < Startup > ( ) ;
40
+ _context . TodoItems . Add ( new TodoItem ( ) ) ;
41
+ _context . SaveChanges ( ) ;
22
42
23
- var server = new TestServer ( builder ) ;
24
- var client = server . CreateClient ( ) ;
43
+ var client = _server . CreateClient ( ) ;
25
44
26
45
var httpMethod = new HttpMethod ( "GET" ) ;
27
46
var route = $ "/api/v1/custom-todo-items";
@@ -31,7 +50,7 @@ public async Task Can_Implement_Custom_IResourceService_Without_EFAsync()
31
50
// act
32
51
var response = await client . SendAsync ( request ) ;
33
52
var responseBody = await response . Content . ReadAsStringAsync ( ) ;
34
- var deserializedBody = server . GetService < IJsonApiDeSerializer > ( )
53
+ var deserializedBody = _server . GetService < IJsonApiDeSerializer > ( )
35
54
. DeserializeList < TodoItem > ( responseBody ) ;
36
55
37
56
// assert
0 commit comments