using System; using System.IO; using System.Net.Http; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Moq; using Serilog; using Xunit; using CRIF.ACTion.Services.Crif; using Landmark.OLA.Application; using Landmark.OLA.Application.DataAccess; using Landmark.OLA.Application.DataAccessLayer; using Landmark.OLA.Application.Services; using Landmark.OLA.Models.Vendor; using OnlineBankingAuth.Tokens; namespace Landmark.OLA.Integration.Tests { public class OlaIntegrationTest : IClassFixture> { protected readonly HttpClient _client; protected readonly Mock mockBranchDataAccess; protected readonly Mock mockConfigurationAccess; protected readonly Mock mockVendorClient; protected readonly Mock mockLoanApplicationDataAccess; protected readonly Mock mockBlobStorageAccess; protected readonly Mock mockUspsVendorClient; protected readonly Mock mockTokenService; protected readonly Mock mockCoreService; public OlaIntegrationTest() { mockBranchDataAccess = new Mock(); mockConfigurationAccess = new Mock(); mockVendorClient = new Mock(); mockLoanApplicationDataAccess = new Mock(); mockBlobStorageAccess = new Mock(); mockUspsVendorClient = new Mock(); mockTokenService = new Mock(); mockCoreService = new Mock(); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var contentRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "Landmark.OLA.Application")); var host = new HostBuilder() .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(); }) .ConfigureWebHost(web => { web.UseContentRoot(contentRoot); web.UseEnvironment("Development"); web.UseStartup(); web.UseTestServer(); web.ConfigureTestServices(s => { s.AddSingleton(mockBranchDataAccess.Object); s.AddSingleton(mockConfigurationAccess.Object); s.AddSingleton(mockVendorClient.Object); s.AddSingleton(mockLoanApplicationDataAccess.Object); s.AddSingleton(mockBlobStorageAccess.Object); s.AddSingleton(mockUspsVendorClient.Object); s.AddSingleton(mockTokenService.Object); s.AddSingleton(mockCoreService.Object); }); }) .UseSerilog((ctx, services, lc) => lc .ReadFrom.Configuration(ctx.Configuration) .ReadFrom.Services(services) .Enrich.FromLogContext()) .Build(); host.Start(); var server = host.GetTestServer(); _client = server.CreateClient(); } } }