diff --git a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj index 5030f43..7e7cf1f 100644 --- a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj +++ b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index eca708a..ff28d64 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -14,7 +14,7 @@ namespace EstateReportingAPI.BusinessLogic{ public class ReportingManager : IReportingManager{ #region Fields - private readonly Shared.EntityFramework.IDbContextFactory ContextFactory; + private readonly Shared.EntityFramework.IDbContextFactory ContextFactory; private Guid Id; @@ -22,7 +22,7 @@ public class ReportingManager : IReportingManager{ #region Constructors - public ReportingManager(Shared.EntityFramework.IDbContextFactory contextFactory){ + public ReportingManager(Shared.EntityFramework.IDbContextFactory contextFactory){ this.ContextFactory = contextFactory; } @@ -31,8 +31,8 @@ public ReportingManager(Shared.EntityFramework.IDbContextFactory> GetUnsettledFees(Guid estateId, DateTime startDate, DateTime endDate, List merchantIds, List operatorIds, List productIds, GroupByOption? groupByOption, CancellationToken cancellationToken){ - - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); var fees = (from merchantSettlementFee in context.MerchantSettlementFees join transaction in context.Transactions @@ -132,7 +132,7 @@ into grouped } public async Task> GetCalendarComparisonDates(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); DateTime startOfYear = new DateTime(DateTime.Now.Year, 1, 1); @@ -159,7 +159,7 @@ public async Task> GetCalendarComparisonDates(Guid estateId, Canc } public async Task> GetCalendarDates(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List entities = context.Calendar.Where(c => c.Date <= DateTime.Now.Date).ToList(); @@ -184,7 +184,7 @@ public async Task> GetCalendarDates(Guid estateId, CancellationTo } public async Task> GetCalendarYears(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List years = context.Calendar.Where(c => c.Date <= DateTime.Now.Date).GroupBy(c => c.Year).Select(y => y.Key).ToList(); @@ -192,7 +192,7 @@ public async Task> GetCalendarYears(Guid estateId, CancellationToken } public async Task GetLastSettlement(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); DateTime settlementDate = await context.SettlementSummary.Where(s => s.IsCompleted).OrderByDescending(s => s.SettlementDate).Select(s => s.SettlementDate).FirstOrDefaultAsync(cancellationToken); @@ -217,7 +217,7 @@ public async Task GetLastSettlement(Guid estateId, CancellationT } public async Task GetMerchantsTransactionKpis(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); Int32 merchantsWithSaleInLastHour = (from m in context.Merchants where m.LastSaleDate == DateTime.Now.Date @@ -242,7 +242,7 @@ public async Task GetMerchantsTransactionKpis(Guid estateId, Cancel } public async Task> GetMerchantsByLastSale(Guid estateId, DateTime startDateTime, DateTime endDateTime, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List response = new(); @@ -292,7 +292,7 @@ public async Task> GetMerchantsByLastSale(Guid estateId, DateTime } public async Task> GetResponseCodes(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List response = new List(); List responseCodes = await context.ResponseCodes.ToListAsync(cancellationToken); @@ -306,7 +306,7 @@ public async Task> GetResponseCodes(Guid estateId, Cancellati } public async Task GetTodaysFailedSales(Guid estateId, DateTime comparisonDate, String responseCode, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List todaysSales = await (from t in context.TodayTransactions where t.IsAuthorised == false @@ -332,8 +332,8 @@ public async Task GetTodaysFailedSales(Guid estateId, DateTime comp return response; } - private async Task> GetTodaysSales(EstateManagementGenericContext context, - Int32 merchantReportingId, Int32 operatorReportingId, CancellationToken cancellationToken){ + private async Task> GetTodaysSales(EstateManagementContext context, + Int32 merchantReportingId, Int32 operatorReportingId, CancellationToken cancellationToken){ var salesForDate = (from t in context.TodayTransactions where t.IsAuthorised && t.TransactionType == "Sale" && t.TransactionDate == DateTime.Now.Date @@ -352,10 +352,10 @@ private async Task> GetTodaysSales(EstateManagement return salesForDate; } - private async Task> GetSalesForDate(EstateManagementGenericContext context, - DateTime queryDate, - Int32 merchantReportingId, Int32 operatorReportingId, - CancellationToken cancellationToken) + private async Task> GetSalesForDate(EstateManagementContext context, + DateTime queryDate, + Int32 merchantReportingId, Int32 operatorReportingId, + CancellationToken cancellationToken) { var salesForDate = (from t in context.TransactionHistory where t.IsAuthorised && t.TransactionType == "Sale" @@ -377,7 +377,7 @@ private async Task> GetSalesForDate(EstateManagem } public async Task GetTodaysSales(Guid estateId, Int32 merchantReportingId, Int32 operatorReportingId, DateTime comparisonDate, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); IQueryable todaysSales = await GetTodaysSales(context, merchantReportingId, operatorReportingId, cancellationToken); IQueryable comparisonSales = await GetSalesForDate(context, comparisonDate, merchantReportingId, operatorReportingId, cancellationToken); @@ -399,7 +399,7 @@ public async Task GetTodaysSales(Guid estateId, Int32 merchantRepor } public async Task> GetTodaysSalesCountByHour(Guid estateId, Int32 merchantReportingId, Int32 operatorReportingId, DateTime comparisonDate, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); IQueryable todaysSales = await GetTodaysSales(context, merchantReportingId, operatorReportingId, cancellationToken); IQueryable comparisonSales = await GetSalesForDate(context, comparisonDate, merchantReportingId, operatorReportingId, cancellationToken); @@ -435,7 +435,7 @@ on today.Hour equals comparison.Hour } public async Task> GetTodaysSalesValueByHour(Guid estateId, Int32 merchantReportingId, Int32 operatorReportingId, DateTime comparisonDate, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); IQueryable todaysSales = await GetTodaysSales(context, merchantReportingId, operatorReportingId, cancellationToken); IQueryable comparisonSales = await GetSalesForDate(context, comparisonDate, merchantReportingId, operatorReportingId, cancellationToken); @@ -472,7 +472,7 @@ on today.Hour equals comparison.Hour return response; } - private async Task> GetSettlementDataForDate(EstateManagementGenericContext context, Int32 merchantReportingId, Int32 operatorReportingId, DateTime queryDate, CancellationToken cancellationToken) + private async Task> GetSettlementDataForDate(EstateManagementContext context, Int32 merchantReportingId, Int32 operatorReportingId, DateTime queryDate, CancellationToken cancellationToken) { if (queryDate.Date == DateTime.Today.Date) { @@ -498,7 +498,7 @@ join t in context.TransactionHistory on f.TransactionId equals t.TransactionId return settlementData.AsQueryable().Select(s => s.Fees); } - private async Task> GetTodaysSettlement(EstateManagementGenericContext? context, Int32 merchantReportingId, Int32 operatorReportingId, CancellationToken cancellationToken) + private async Task> GetTodaysSettlement(EstateManagementContext? context, Int32 merchantReportingId, Int32 operatorReportingId, CancellationToken cancellationToken) { var settlementData = (from s in context.Settlements join f in context.MerchantSettlementFees on s.SettlementId equals f.SettlementId @@ -520,7 +520,7 @@ join t in context.TodayTransactions on f.TransactionId equals t.TransactionId } public async Task GetTodaysSettlement(Guid estateId, Int32 merchantReportingId, Int32 operatorReportingId, DateTime comparisonDate, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); IQueryable todaySettlementData = await GetTodaysSettlement(context, merchantReportingId, operatorReportingId, cancellationToken); IQueryable comparisonSettlementData = await GetSettlementDataForDate(context, merchantReportingId, operatorReportingId, comparisonDate, cancellationToken); @@ -560,7 +560,7 @@ group f by f.IsSettled into grouped } public async Task> GetTopBottomData(Guid estateId, TopBottom direction, Int32 resultCount, Dimension dimension, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); IQueryable mainQuery = context.TodayTransactions .Where(joined => joined.IsAuthorised == true @@ -642,7 +642,7 @@ public async Task> GetTopBottomData(Guid estateId, TopBottom } public async Task GetMerchantPerformance(Guid estateId, DateTime comparisonDate, List merchantReportingIds, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); // First we need to get a value of todays sales var todaysSalesQuery = (from t in context.TodayTransactions @@ -700,7 +700,7 @@ private Decimal SafeDivide(Decimal number, Int32 divisor) public async Task GetProductPerformance(Guid estateId, DateTime comparisonDate, List productReportingIds, CancellationToken cancellationToken) { - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); // First we need to get a value of todays sales var todaysSalesQuery = (from t in context.TodayTransactions @@ -738,7 +738,7 @@ public async Task GetProductPerformance(Guid estateId, DateTime com } public async Task GetOperatorPerformance(Guid estateId, DateTime comparisonDate, List operatorReportingIds, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); // First we need to get a value of todays sales var todaysSalesQuery = (from t in context.TodayTransactions @@ -777,7 +777,7 @@ public async Task GetOperatorPerformance(Guid estateId, DateTime co public async Task> TransactionSearch(Guid estateId, TransactionSearchRequest searchRequest, PagingRequest pagingRequest, SortingRequest sortingRequest, CancellationToken cancellationToken){ // Base query before any filtering is added - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); var mainQuery = (from txn in context.Transactions join merchant in context.Merchants on txn.MerchantId equals merchant.MerchantId @@ -875,7 +875,7 @@ join product in context.ContractProducts on txn.ContractProductId equals product } public async Task> GetMerchants(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); var merchants = context.Merchants .Select(m => new @@ -931,7 +931,7 @@ public async Task> GetMerchants(Guid estateId, CancellationToken } public async Task> GetOperators(Guid estateId, CancellationToken cancellationToken){ - EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken); List operators = await (from o in context.Operators select new Operator diff --git a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj index 5dc0352..dd86c96 100644 --- a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj +++ b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj @@ -7,9 +7,9 @@ - + - + diff --git a/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs b/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs index 28c83e6..54f38be 100644 --- a/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs +++ b/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs @@ -42,7 +42,7 @@ public virtual async Task InitializeAsync() this.Client = this.factory.CreateClient(); this.ApiClient = new EstateReportingApiClient((s) => "http://localhost", this.Client); - this.context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}")); + this.context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}")); this.helper = new DatabaseHelper(context); await this.helper.CreateStoredProcedures(CancellationToken.None); @@ -53,7 +53,7 @@ public virtual async Task DisposeAsync() { } - protected EstateManagementGenericContext context; + protected EstateManagementContext context; protected abstract Task ClearStandingData(); protected abstract Task SetupStandingData(); @@ -126,7 +126,7 @@ await Retry.For(async () => { public void Dispose() { - EstateManagementGenericContext context = new EstateManagementSqlServerContext(ControllerTestsBase.GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(ControllerTestsBase.GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}")); Console.WriteLine($"About to delete database EstateReportingReadModel{this.TestId.ToString()}"); Boolean result = context.Database.EnsureDeleted(); diff --git a/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs b/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs index d7994b4..8b9db1e 100644 --- a/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs +++ b/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs @@ -38,10 +38,10 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureServices(containerBuilder => { - var context = new EstateManagementSqlServerContext(DatabaseConnectionString); - Func f = connectionString => context; + var context = new EstateManagementContext(DatabaseConnectionString); + Func f = connectionString => context; - IDbContextFactory factory = new DbContextFactory(new TestConnectionStringConfigurationRepository(DatabaseConnectionString), f); + IDbContextFactory factory = new DbContextFactory(new TestConnectionStringConfigurationRepository(DatabaseConnectionString), f); IReportingManager manager = new ReportingManager(factory); diff --git a/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs b/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs index 61239b9..1d8f199 100644 --- a/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs +++ b/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs @@ -18,9 +18,9 @@ namespace EstateReportingAPI.IntegrationTests; using Microsoft.EntityFrameworkCore; public class DatabaseHelper{ - private readonly EstateManagementGenericContext Context; + private readonly EstateManagementContext Context; - public DatabaseHelper(EstateManagementGenericContext context){ + public DatabaseHelper(EstateManagementContext context){ this.Context = context; } diff --git a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs b/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs index 3e7ece4..ffd99fa 100644 --- a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs +++ b/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs @@ -277,7 +277,7 @@ protected override async Task SetupStandingData() public void Dispose() { - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); Console.WriteLine($"About to delete database EstateReportingReadModel{TestId.ToString()}"); bool result = context.Database.EnsureDeleted(); diff --git a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj index a180061..0a02b72 100644 --- a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj +++ b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj @@ -7,9 +7,9 @@ - + - + @@ -21,8 +21,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + diff --git a/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs b/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs index 531b673..4fceaf2 100644 --- a/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs +++ b/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs @@ -297,7 +297,7 @@ public async Task FactSettlementsController_TodaysSettlement_OperatorFilter_Sett [Fact] public async Task FactSettlementsController_LastSettlement_SettlementReturned() { - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -341,7 +341,7 @@ public async Task FactSettlementsController_LastSettlement_SettlementReturned() [Fact] public async Task FactSettlementsController_LastSettlement_NoSettlementRecords_SettlementReturned() { - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -355,7 +355,7 @@ public async Task FactSettlementsController_LastSettlement_NoSettlementRecords_S [Fact] public async Task FactSettlementsController_UnsettledFees_ByOperator_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -407,7 +407,7 @@ public async Task FactSettlementsController_UnsettledFees_ByOperator_SettlementR [Fact] public async Task FactSettlementsController_UnsettledFees_ByOperator_OperatorFilter_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -458,7 +458,7 @@ public async Task FactSettlementsController_UnsettledFees_ByOperator_OperatorFil [Fact] public async Task FactSettlementsController_UnsettledFees_ByMerchant_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -504,7 +504,7 @@ public async Task FactSettlementsController_UnsettledFees_ByMerchant_SettlementR [Fact] public async Task FactSettlementsController_UnsettledFees_ByMerchant_MerchantFilter_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -549,7 +549,7 @@ public async Task FactSettlementsController_UnsettledFees_ByMerchant_MerchantFil [Fact] public async Task FactSettlementsController_UnsettledFees_ByProduct_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); @@ -609,7 +609,7 @@ public async Task FactSettlementsController_UnsettledFees_ByProduct_SettlementRe [Fact] public async Task FactSettlementsController_UnsettledFees_ByProduct_ProductFilter_SettlementReturned() { // Add some fees over a date range for multiple operators - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); DatabaseHelper helper = new DatabaseHelper(context); diff --git a/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs b/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs index aa9a924..6de2635 100644 --- a/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs +++ b/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs @@ -1305,7 +1305,7 @@ public async Task FactTransactionsControllerController_TodaysSalesValueByHour_Sa [Fact] public async Task FactTransactionsControllerController_TodaysFailedSales_SalesReturned() { - EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); var todaysTransactions = new List(); var comparisonDateTransactions = new List(); DatabaseHelper helper = new DatabaseHelper(context); diff --git a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj index c717162..1abfd09 100644 --- a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj +++ b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj @@ -7,7 +7,7 @@ - + @@ -19,6 +19,7 @@ + all diff --git a/EstateReportingAPI/Bootstrapper/RepositoryRegistry.cs b/EstateReportingAPI/Bootstrapper/RepositoryRegistry.cs index 93de6d3..f9ba75c 100644 --- a/EstateReportingAPI/Bootstrapper/RepositoryRegistry.cs +++ b/EstateReportingAPI/Bootstrapper/RepositoryRegistry.cs @@ -35,20 +35,10 @@ public RepositoryRegistry(){ this.AddSingleton(); } - this.AddSingleton, DbContextFactory>(); - - this.AddSingleton>(cont => connectionString => - { - String databaseEngine = - ConfigurationReader.GetValue("AppSettings", "DatabaseEngine"); - - return databaseEngine switch - { - "MySql" => new EstateManagementMySqlContext(connectionString), - "SqlServer" => new EstateManagementSqlServerContext(connectionString), - _ => throw new - NotSupportedException($"Unsupported Database Engine {databaseEngine}") - }; - }); + this.AddSingleton, DbContextFactory>(); + + this.AddSingleton>(cont => connectionString => { + return new EstateManagementContext(connectionString); + }); } } \ No newline at end of file diff --git a/EstateReportingAPI/Common/ConfigurationReaderConnectionStringRepository.cs b/EstateReportingAPI/Common/ConfigurationReaderConnectionStringRepository.cs index cbbf27f..b8ee7ee 100644 --- a/EstateReportingAPI/Common/ConfigurationReaderConnectionStringRepository.cs +++ b/EstateReportingAPI/Common/ConfigurationReaderConnectionStringRepository.cs @@ -1,5 +1,4 @@ using Microsoft.Data.SqlClient; -using MySqlConnector; using Shared.General; using Shared.Repositories; using System.Data.Common; @@ -39,23 +38,11 @@ public async Task GetConnectionString(String externalIdentifier, databaseName = $"{connectionStringIdentifier}{externalIdentifier}"; connectionString = ConfigurationReader.GetConnectionString(connectionStringIdentifier); - DbConnectionStringBuilder builder = null; - - if (databaseEngine == "MySql") - { - builder = new MySqlConnectionStringBuilder(connectionString) - { - Database = databaseName - }; - } - else + DbConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString) { - // Default to SQL Server - builder = new SqlConnectionStringBuilder(connectionString) - { - InitialCatalog = databaseName - }; - } + InitialCatalog = databaseName + }; + return builder.ToString(); } diff --git a/EstateReportingAPI/EstateReportingAPI.csproj b/EstateReportingAPI/EstateReportingAPI.csproj index f8c9566..6f08275 100644 --- a/EstateReportingAPI/EstateReportingAPI.csproj +++ b/EstateReportingAPI/EstateReportingAPI.csproj @@ -12,8 +12,8 @@ - - + + @@ -21,7 +21,7 @@ - + @@ -36,7 +36,7 @@ - + diff --git a/EstateReportingAPI/Program.cs b/EstateReportingAPI/Program.cs index 846b5a2..a120cf7 100644 --- a/EstateReportingAPI/Program.cs +++ b/EstateReportingAPI/Program.cs @@ -1,5 +1,9 @@ -using System.Diagnostics.CodeAnalysis; using Lamar.Microsoft.DependencyInjection; +using NLog; +using System.Diagnostics.CodeAnalysis; +using NLog.Extensions.Logging; +using Shared.Logger; +using Shared.Middleware; namespace EstateReportingAPI; @@ -23,12 +27,27 @@ public static IHostBuilder CreateHostBuilder(string[] args) .AddJsonFile("hosting.development.json", optional: true) .AddEnvironmentVariables().Build(); + String contentRoot = Directory.GetCurrentDirectory(); + String nlogConfigPath = Path.Combine(contentRoot, "nlog.config"); + + LogManager.Setup(b => + { + b.SetupLogFactory(setup => + { + setup.AddCallSiteHiddenAssembly(typeof(NlogLogger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(Shared.Logger.Logger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(TenantMiddleware).Assembly); + }); + b.LoadConfigurationFromFile(nlogConfigPath); + }); + IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args); hostBuilder.UseWindowsService(); hostBuilder.UseLamar(); hostBuilder.ConfigureLogging(logging => { logging.AddConsole(); + logging.AddNLog(); }); hostBuilder.ConfigureWebHostDefaults(webBuilder => { diff --git a/EstateReportingAPI/Startup.cs b/EstateReportingAPI/Startup.cs index 0c982e4..b2cce86 100644 --- a/EstateReportingAPI/Startup.cs +++ b/EstateReportingAPI/Startup.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using EstateReportingAPI.Bootstrapper; using HealthChecks.UI.Client; using Lamar; @@ -7,10 +6,13 @@ using Shared.Extensions; using Shared.General; using Shared.Logger; +using System.Diagnostics.CodeAnalysis; namespace EstateReportingAPI { using BusinessLogic; + using Shared.Middleware; + [ExcludeFromCodeCoverage] public class Startup { @@ -62,28 +64,18 @@ public void ConfigureServices(IServiceCollection services){ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { - string nlogConfigFilename = "nlog.config"; - if (env.IsDevelopment()) { - var developmentNlogConfigFilename = "nlog.development.config"; - if (File.Exists(Path.Combine(env.ContentRootPath, developmentNlogConfigFilename))) - { - nlogConfigFilename = developmentNlogConfigFilename; - } app.UseDeveloperExceptionPage(); } - - loggerFactory.ConfigureNLog(Path.Combine(env.ContentRootPath, nlogConfigFilename)); - loggerFactory.AddNLog(); - + Microsoft.Extensions.Logging.ILogger logger = loggerFactory.CreateLogger("EstateManagement"); Logger.Initialise(logger); Configuration.LogConfiguration(Logger.LogWarning); ConfigurationReader.Initialise(Configuration); - + app.UseMiddleware(); app.AddRequestLogging(); app.AddResponseLogging(); app.AddExceptionHandler(); diff --git a/EstateReportingAPI/nlog.config b/EstateReportingAPI/nlog.config index f400987..67b5f48 100644 --- a/EstateReportingAPI/nlog.config +++ b/EstateReportingAPI/nlog.config @@ -4,7 +4,7 @@