92 lines
4.0 KiB
C#
92 lines
4.0 KiB
C#
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<CustomWebApplicationFactory<Startup>>
|
|
{
|
|
protected readonly HttpClient _client;
|
|
protected readonly Mock<IBranchDataAccess> mockBranchDataAccess;
|
|
protected readonly Mock<IConfigurationAccess> mockConfigurationAccess;
|
|
protected readonly Mock<ICrifVendorClient> mockVendorClient;
|
|
protected readonly Mock<ILoanApplicationDataAccess> mockLoanApplicationDataAccess;
|
|
protected readonly Mock<IBlobStorageAccess> mockBlobStorageAccess;
|
|
protected readonly Mock<IUspsVendorClient> mockUspsVendorClient;
|
|
protected readonly Mock<ITokenService> mockTokenService;
|
|
protected readonly Mock<ICoreService> mockCoreService;
|
|
|
|
public OlaIntegrationTest()
|
|
{
|
|
mockBranchDataAccess = new Mock<IBranchDataAccess>();
|
|
mockConfigurationAccess = new Mock<IConfigurationAccess>();
|
|
mockVendorClient = new Mock<ICrifVendorClient>();
|
|
mockLoanApplicationDataAccess = new Mock<ILoanApplicationDataAccess>();
|
|
mockBlobStorageAccess = new Mock<IBlobStorageAccess>();
|
|
mockUspsVendorClient = new Mock<IUspsVendorClient>();
|
|
mockTokenService = new Mock<ITokenService>();
|
|
mockCoreService = new Mock<ICoreService>();
|
|
|
|
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<Startup>();
|
|
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();
|
|
}
|
|
}
|
|
}
|