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 : WebApplicationFactory { 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(); mockRepo.Setup(repo => repo.GetBranchConfig()).Returns(new BranchConfig()); services.AddScoped(_ => mockRepo.Object); }); } } }