-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomWebApplicationFactory.cs
More file actions
28 lines (24 loc) · 1.05 KB
/
CustomWebApplicationFactory.cs
File metadata and controls
28 lines (24 loc) · 1.05 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
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace CarServiceAPI;
public class CustomWebApplicationFactory<TEntryPoint> : WebApplicationFactory<TEntryPoint> where TEntryPoint : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration((context, configBuilder) =>
{
// Adjust the configuration for testing
var projectDir = Directory.GetCurrentDirectory();
configBuilder.AddJsonFile(Path.Combine(projectDir, "appsettings.json"), optional: false);
configBuilder.AddJsonFile("data.json", optional: false, reloadOnChange: false);
});
builder.UseStartup<TestStartup>(); // Use TestStartup instead of the default Startup class
builder.ConfigureServices(services =>
{
// Optionally replace services with mocks or other test-specific implementations
});
}
}