-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphQLTestFactory.cs
More file actions
46 lines (40 loc) · 1.67 KB
/
GraphQLTestFactory.cs
File metadata and controls
46 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using PhantomDave.BankTracking.Data.Context;
namespace PhantomDave.BankTracking.IntegrationTests.Helpers;
public class GraphQLTestFactory : WebApplicationFactory<PhantomDave.BankTracking.Api.Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration((context, config) =>
{
config.AddInMemoryCollection(new Dictionary<string, string?>
{
["ConnectionStrings:DefaultConnection"] = "Host=localhost;Database=banktrackertest;Username=test;Password=test",
["Jwt:Secret"] = "ThisIsASecretKeyForTestingPurposesOnly123456789",
["Jwt:Issuer"] = "BankTrackerTestIssuer",
["Jwt:Audience"] = "BankTrackerTestAudience",
["Jwt:ExpiryMinutes"] = "60"
});
});
builder.ConfigureTestServices(services =>
{
var descriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<BankTrackerDbContext>));
if (descriptor != null)
{
services.Remove(descriptor);
}
services.AddDbContext<BankTrackerDbContext>(options =>
{
options.UseInMemoryDatabase("InMemoryTestDb");
});
});
builder.UseEnvironment("Testing");
}
}