Files
2026-03-11 11:18:25 -05:00

40 lines
1.5 KiB
C#

using System;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Landmark.OLA.Application;
using Landmark.OLA.Application.DataAccess;
using Landmark.OLA.Models.Loan;
namespace Landmark.OLA.Integration.Tests
{
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<Startup>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
var contentRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "Landmark.OLA.Application"));
builder.UseEnvironment("Development");
builder.UseContentRoot(contentRoot);
builder.ConfigureAppConfiguration((context, config) =>
{
config.Sources.Clear();
config.SetBasePath(contentRoot);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
config.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: false);
config.AddEnvironmentVariables();
});
builder.ConfigureServices(services =>
{
var mockRepo = new Mock<IBranchDataAccess>();
mockRepo.Setup(repo => repo.GetBranchConfig()).Returns(new BranchConfig());
services.AddScoped<IBranchDataAccess>(_ => mockRepo.Object);
});
}
}
}