Skip to content

Commit 93edba5

Browse files
committed
test(acceptance/no-ef): ensure the database is created
this should be cleaned up by #91
1 parent 84cf741 commit 93edba5

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility/NoEntityFrameworkTests.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,39 @@
88
using System.Threading.Tasks;
99
using System.Net;
1010
using JsonApiDotNetCoreExample.Models;
11+
using JsonApiDotNetCoreExample.Data;
12+
using Microsoft.EntityFrameworkCore;
13+
using Microsoft.Extensions.Configuration;
1114

1215
namespace JsonApiDotNetCoreExampleTests.Acceptance.Extensibility
1316
{
1417
public class NoEntityFrameworkTests
1518
{
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+
1636
[Fact]
1737
public async Task Can_Implement_Custom_IResourceService_Without_EFAsync()
1838
{
1939
// arrange
20-
var builder = new WebHostBuilder()
21-
.UseStartup<Startup>();
40+
_context.TodoItems.Add(new TodoItem());
41+
_context.SaveChanges();
2242

23-
var server = new TestServer(builder);
24-
var client = server.CreateClient();
43+
var client = _server.CreateClient();
2544

2645
var httpMethod = new HttpMethod("GET");
2746
var route = $"/api/v1/custom-todo-items";
@@ -31,7 +50,7 @@ public async Task Can_Implement_Custom_IResourceService_Without_EFAsync()
3150
// act
3251
var response = await client.SendAsync(request);
3352
var responseBody = await response.Content.ReadAsStringAsync();
34-
var deserializedBody = server.GetService<IJsonApiDeSerializer>()
53+
var deserializedBody = _server.GetService<IJsonApiDeSerializer>()
3554
.DeserializeList<TodoItem>(responseBody);
3655

3756
// assert

0 commit comments

Comments
 (0)