diff --git a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj
index 6f4d479..23c0c1c 100644
--- a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj
+++ b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/EstateReportingAPI.BusinessLogic/ModelFactory.cs b/EstateReportingAPI.BusinessLogic/ModelFactory.cs
index dc1db27..e62e4ab 100644
--- a/EstateReportingAPI.BusinessLogic/ModelFactory.cs
+++ b/EstateReportingAPI.BusinessLogic/ModelFactory.cs
@@ -1,10 +1,12 @@
namespace EstateReportingAPI.BusinessLogic;
+using TransactionProcessor.Database.Entities;
using Merchant = EstateReportingAPI.Models.Merchant;
internal static class ModelFactory {
internal static Merchant ConvertFrom(MerchantData merchant,
- decimal balance) {
+ decimal balance,
+ List openingHours) {
return new Merchant {
Balance = balance,
CreatedDateTime = merchant.CreatedDateTime,
@@ -23,7 +25,8 @@ internal static Merchant ConvertFrom(MerchantData merchant,
ContactId = merchant.ContactInfo.ContactId,
ContactName = merchant.ContactInfo.Name,
ContactEmail = merchant.ContactInfo.EmailAddress,
- ContactPhone = merchant.ContactInfo.PhoneNumber
+ ContactPhone = merchant.ContactInfo.PhoneNumber,
+
};
}
diff --git a/EstateReportingAPI.BusinessLogic/Queries/MerchantQueries.cs b/EstateReportingAPI.BusinessLogic/Queries/MerchantQueries.cs
index 4f42e68..4fdf5e2 100644
--- a/EstateReportingAPI.BusinessLogic/Queries/MerchantQueries.cs
+++ b/EstateReportingAPI.BusinessLogic/Queries/MerchantQueries.cs
@@ -14,6 +14,7 @@ public record GetMerchantQuery(Guid EstateId, Guid MerchantId) : IRequest>>;
public record GetMerchantContractsQuery(Guid EstateId, Guid MerchantId) : IRequest>>;
public record GetMerchantDevicesQuery(Guid EstateId, Guid MerchantId) : IRequest>>;
-
+ public record GetMerchantOpeningHoursQuery(Guid EstateId, Guid MerchantId) : IRequest>>;
+ public record GetMerchantScheduleQuery(Guid EstateId, Guid MerchantId, Int32 Year) : IRequest>;
public record MerchantQueryOptions(String Name,String Reference,Int32? SettlementSchedule,String Region, String PostCode);
}
\ No newline at end of file
diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs
index 565c73f..c6a8dfb 100644
--- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs
+++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs
@@ -43,6 +43,7 @@ public interface IReportingManager
Task>> GetMerchantOperators(MerchantQueries.GetMerchantOperatorsQuery request, CancellationToken cancellationToken);
Task>> GetMerchantContracts(MerchantQueries.GetMerchantContractsQuery request, CancellationToken cancellationToken);
Task>> GetMerchantDevices(MerchantQueries.GetMerchantDevicesQuery request, CancellationToken cancellationToken);
+ Task>> GetMerchantOpeningHours(MerchantQueries.GetMerchantOpeningHoursQuery request, CancellationToken cancellationToken);
Task> GetOperator(OperatorQueries.GetOperatorQuery request, CancellationToken cancellationToken);
Task> GetTransactionDetailReport(TransactionQueries.TransactionDetailReportQuery request,
CancellationToken cancellationToken);
@@ -58,6 +59,9 @@ Task>> GetTodaysSalesByHour(TransactionQueries.To
Task> GetTodaysSettlement(SettlementQueries.TodaysSettlementQuery request,
CancellationToken cancellationToken);
#endregion
+
+ Task> GetMerchantSchedule(MerchantQueries.GetMerchantScheduleQuery request,
+ CancellationToken cancellationToken);
}
public class ReportingManager : IReportingManager {
@@ -625,6 +629,47 @@ public async Task>> GetOperators(OperatorQueries.GetOperat
return Result.Success(operators);
}
+ public async Task>> GetMerchantOpeningHours(MerchantQueries.GetMerchantOpeningHoursQuery request,
+ CancellationToken cancellationToken) {
+ using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
+ await using EstateManagementContext context = resolvedContext.Context;
+
+ var openingHoursQuery = (from mo in context.MerchantOpeningHours
+ where mo.MerchantId == request.MerchantId
+ select new {
+ SundayOpen = mo.SundayOpening,
+ SundayClose = mo.SundayClosing,
+ MondayOpen = mo.MondayOpening,
+ MondayClose = mo.MondayClosing,
+ TuesdayOpen = mo.TuesdayOpening,
+ TuesdayClose = mo.TuesdayClosing,
+ WednesdayOpen = mo.WednesdayOpening,
+ WednesdayClose = mo.WednesdayClosing,
+ ThursdayOpen = mo.ThursdayOpening,
+ ThursdayClose = mo.ThursdayClosing,
+ FridayOpen = mo.FridayOpening,
+ FridayClose = mo.FridayClosing,
+ SaturdayOpen = mo.SaturdayOpening,
+ SaturdayClose = mo.SaturdayClosing,
+ });
+
+ var openingHoursResult = await ExecuteQuerySafeSingleOrDefault(openingHoursQuery, cancellationToken, "Error retrieving merchant opening hours");
+
+ if (openingHoursResult.IsFailed)
+ return ResultHelpers.CreateFailure(openingHoursResult);
+
+ List openingHours = new List();
+ openingHours.Add(new MerchantOpeningHour {OpeningTime = openingHoursResult.Data.SundayOpen, ClosingTime = openingHoursResult.Data.SundayClose, DayOfWeek = DayOfWeek.Sunday, MerchantId = request.MerchantId});
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.MondayOpen, ClosingTime = openingHoursResult.Data.MondayClose, DayOfWeek = DayOfWeek.Monday, MerchantId = request.MerchantId });
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.TuesdayOpen, ClosingTime = openingHoursResult.Data.TuesdayClose, DayOfWeek = DayOfWeek.Tuesday, MerchantId = request.MerchantId });
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.WednesdayOpen, ClosingTime = openingHoursResult.Data.WednesdayClose, DayOfWeek = DayOfWeek.Wednesday, MerchantId = request.MerchantId });
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.ThursdayOpen, ClosingTime = openingHoursResult.Data.ThursdayClose, DayOfWeek = DayOfWeek.Thursday, MerchantId = request.MerchantId });
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.FridayOpen, ClosingTime = openingHoursResult.Data.FridayClose, DayOfWeek = DayOfWeek.Friday, MerchantId = request.MerchantId });
+ openingHours.Add(new MerchantOpeningHour { OpeningTime = openingHoursResult.Data.SaturdayOpen, ClosingTime = openingHoursResult.Data.SaturdayClose, DayOfWeek = DayOfWeek.Saturday, MerchantId = request.MerchantId });
+
+ return Result.Success(openingHours);
+ }
+
public async Task> GetOperator(OperatorQueries.GetOperatorQuery request,
CancellationToken cancellationToken) {
using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
@@ -966,16 +1011,19 @@ public async Task> GetMerchant(MerchantQueries.GetMerchantQuery
using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
await using EstateManagementContext context = resolvedContext.Context;
- var merchantQuery = BuildMerchantQuery(context, request.MerchantId);
- var merchantQueryResult = await ExecuteQuerySafeSingleOrDefault(merchantQuery, cancellationToken, "Error getting merchant");
+ IQueryable merchantQuery = BuildMerchantQuery(context, request.MerchantId);
+ Result merchantQueryResult = await ExecuteQuerySafeSingleOrDefault(merchantQuery, cancellationToken, "Error getting merchant");
if (merchantQueryResult.IsFailed) {
return ResultHelpers.CreateFailure(merchantQueryResult);
}
- var merchantStateQueryResult = await ExecuteQuerySafeSingleOrDefault(context.MerchantBalanceProjectionState.Where(ms => ms.MerchantId == request.MerchantId), cancellationToken, "Error getting merchant state");
+ Result> openingHoursQueryResult = await ExecuteQuerySafeToList(context.MerchantOpeningHours.Where(m => m.MerchantId == request.MerchantId), cancellationToken, "Error getting merchant opening hours");
+ if (openingHoursQueryResult.IsFailed) return ResultHelpers.CreateFailure(openingHoursQueryResult);
+
+ Result merchantStateQueryResult = await ExecuteQuerySafeSingleOrDefault(context.MerchantBalanceProjectionState.Where(ms => ms.MerchantId == request.MerchantId), cancellationToken, "Error getting merchant state");
if (merchantStateQueryResult.IsFailed) return ResultHelpers.CreateFailure(merchantStateQueryResult);
- return Result.Success(ModelFactory.ConvertFrom(merchantQueryResult.Data, merchantStateQueryResult.Data.Balance));
+ return Result.Success(ModelFactory.ConvertFrom(merchantQueryResult.Data, merchantStateQueryResult.Data.Balance, openingHoursQueryResult.Data));
}
private static IQueryable BuildMerchantQuery(EstateManagementContext context,
@@ -1303,8 +1351,47 @@ public async Task> GetTodaysSettlement(SettlementQuerie
return response;
}
- private async Task GetSettlementSummary(IQueryable query,
- CancellationToken cancellationToken) {
+ public async Task> GetMerchantSchedule(MerchantQueries.GetMerchantScheduleQuery request,
+ CancellationToken cancellationToken) {
+ using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
+ await using EstateManagementContext context = resolvedContext.Context;
+
+ var merchantScheduleQuery = from s in context.MerchantSchedules
+ join d in context.MerchantScheduleMonths on s.MerchantScheduleId equals d.MerchantScheduleId
+ where s.MerchantId == request.MerchantId && s.Year == request.Year
+ select new {
+ s.MerchantId,
+ s.MerchantScheduleId,
+ s.Year,
+ d.Month,
+ d.ClosedDays
+ };
+
+ var merchantScheduleQueryResult = await ExecuteQuerySafeToList(merchantScheduleQuery, cancellationToken, "Error getting merchant schedule");
+ if (merchantScheduleQueryResult.IsFailed)
+ return ResultHelpers.CreateFailure(merchantScheduleQueryResult);
+
+ MerchantScheduleResponse response = new MerchantScheduleResponse();
+ foreach (var item in merchantScheduleQueryResult.Data) {
+
+ List closedDaysList = item.ClosedDays
+ .Split(',', StringSplitOptions.RemoveEmptyEntries)
+ .Select(s => int.TryParse(s, out var n) ? n : (int?)null)
+ .Where(n => n.HasValue)
+ .Select(n => n.Value)
+ .ToList();
+
+ MerchantScheduleMonthResponse? monthSchedule = new() { ClosedDays = closedDaysList, Month = item.Month };
+
+ response.Months.Add(monthSchedule);
+ }
+ response.Year = request.Year;
+
+ return response;
+ }
+
+ private async Task GetSettlementSummary(IQueryable query,
+ CancellationToken cancellationToken) {
// Get the settleed fees summary
DatabaseProjections.SettlementGroupProjection summary = await BuildSettlementSummaryQuery(query).SingleOrDefaultAsync(cancellationToken);
diff --git a/EstateReportingAPI.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs b/EstateReportingAPI.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs
index bd46bd6..13607e0 100644
--- a/EstateReportingAPI.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs
+++ b/EstateReportingAPI.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs
@@ -11,7 +11,9 @@ public class MerchantRequestHandler : IRequestHandler>,
IRequestHandler>>,
IRequestHandler>>,
- IRequestHandler>>
+ IRequestHandler>>,
+ IRequestHandler>>,
+ IRequestHandler>
{
private readonly IReportingManager Manager;
public MerchantRequestHandler(IReportingManager manager)
@@ -53,4 +55,14 @@ public async Task>> Handle(MerchantQueries.GetMercha
CancellationToken cancellationToken) {
return await this.Manager.GetMerchantDevices(request, cancellationToken);
}
+
+ public async Task>> Handle(MerchantQueries.GetMerchantOpeningHoursQuery request,
+ CancellationToken cancellationToken) {
+ return await this.Manager.GetMerchantOpeningHours(request, cancellationToken);
+ }
+
+ public async Task> Handle(MerchantQueries.GetMerchantScheduleQuery request,
+ CancellationToken cancellationToken) {
+ return await this.Manager.GetMerchantSchedule(request, cancellationToken);
+ }
}
\ No newline at end of file
diff --git a/EstateReportingAPI.DataTrasferObjects/Merchant.cs b/EstateReportingAPI.DataTrasferObjects/Merchant.cs
index eb3d192..19b1549 100644
--- a/EstateReportingAPI.DataTrasferObjects/Merchant.cs
+++ b/EstateReportingAPI.DataTrasferObjects/Merchant.cs
@@ -45,10 +45,21 @@ public class Merchant{
[JsonProperty("contact_phone")]
public String ContactPhone { get; set; }
-
#endregion
}
+ public class OpeningHoursResponse
+ {
+ [JsonProperty("day_of_week")]
+ public Int32 DayOfWeek { get; set; }
+
+ [JsonProperty("opening")]
+ public string Opening { get; set; }
+
+ [JsonProperty("closing")]
+ public string Closing { get; set; }
+ }
+
public class MerchantOperator
{
[JsonProperty("merchant_id")]
@@ -110,4 +121,34 @@ public class MerchantDevice
[JsonProperty("is_deleted")]
public Boolean IsDeleted { get; set; }
}
+
+ public class MerchantOpeningHour
+ {
+ [JsonProperty("merchant_id")]
+ public Guid MerchantId { get; set; }
+ [JsonProperty("day_of_week")]
+ public DayOfWeek DayOfWeek { get; set; }
+ [JsonProperty("opening_time")]
+ public String OpeningTime { get; set; }
+ [JsonProperty("closing_time")]
+ public String ClosingTime { get; set; }
+ }
+
+ public class MerchantScheduleResponse
+ {
+ [JsonProperty("year")]
+ public int Year { get; set; }
+
+ [JsonProperty("months")]
+ public List Months { get; set; }
+ }
+
+ public class MerchantScheduleMonthResponse
+ {
+ [JsonProperty("month")]
+ public int Month { get; set; }
+
+ [JsonProperty("closed_days")]
+ public List ClosedDays { get; set; }
+ }
}
\ No newline at end of file
diff --git a/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs b/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs
index d109ff5..b6018cb 100644
--- a/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs
+++ b/EstateReportingAPI.IntegrationTests/DatabaseHelper.cs
@@ -5,12 +5,25 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using EstateReportingAPI.Models;
using JasperFx.Core;
using Microsoft.Data.SqlClient;
using Shared.Logger;
+using SimpleResults;
using TransactionProcessor.Database.Contexts;
using TransactionProcessor.Database.Entities;
using TransactionProcessor.ProjectionEngine.Database.Database.Entities;
+using Calendar = TransactionProcessor.Database.Entities.Calendar;
+using Contract = TransactionProcessor.Database.Entities.Contract;
+using ContractProduct = TransactionProcessor.Database.Entities.ContractProduct;
+using ContractProductTransactionFee = TransactionProcessor.Database.Entities.ContractProductTransactionFee;
+using Estate = TransactionProcessor.Database.Entities.Estate;
+using EstateOperator = TransactionProcessor.Database.Entities.EstateOperator;
+using Merchant = TransactionProcessor.Database.Entities.Merchant;
+using MerchantContract = TransactionProcessor.Database.Entities.MerchantContract;
+using MerchantDevice = TransactionProcessor.Database.Entities.MerchantDevice;
+using MerchantOperator = TransactionProcessor.Database.Entities.MerchantOperator;
+using Operator = TransactionProcessor.Database.Entities.Operator;
namespace EstateReportingAPI.IntegrationTests;
@@ -369,7 +382,8 @@ public async Task AddMerchant(String estateName,
(String contactName, String contactEmail, String contactPhone) contact,
List operators = null,
List contracts = null,
- List devices = null) {
+ List devices = null,
+ Dictionary openingHours = null) {
Estate? estate = await this.Context.Estates.SingleOrDefaultAsync(e => e.Name == estateName);
if (estate == null) {
@@ -449,7 +463,63 @@ await this.Context.MerchantContracts.AddAsync(new MerchantContract {
}
}
- MerchantBalanceProjectionState state = new MerchantBalanceProjectionState {
+ if (openingHours != null && openingHours.Any()) {
+ var sunday = openingHours.TryGetValue(DayOfWeek.Sunday, out MerchantOpeningHour sundayHour) ? sundayHour : null;
+ var monday = openingHours.TryGetValue(DayOfWeek.Monday, out MerchantOpeningHour mondayHour) ? mondayHour : null;
+ var tuesday = openingHours.TryGetValue(DayOfWeek.Tuesday, out MerchantOpeningHour tuesdayHour) ? tuesdayHour : null;
+ var wednesday = openingHours.TryGetValue(DayOfWeek.Wednesday, out MerchantOpeningHour wednesdayHour) ? wednesdayHour : null;
+ var thursday = openingHours.TryGetValue(DayOfWeek.Thursday, out MerchantOpeningHour thursdayHour) ? thursdayHour : null;
+ var friday = openingHours.TryGetValue(DayOfWeek.Friday, out MerchantOpeningHour fridayHour) ? fridayHour : null;
+ var saturday = openingHours.TryGetValue(DayOfWeek.Saturday, out MerchantOpeningHour saturdayHour) ? saturdayHour : null;
+
+ MerchantOpeningHours merchantOpeningHours = new MerchantOpeningHours {
+ MerchantId = savedMerchant.MerchantId,
+ SundayOpening = sunday?.OpeningTime,
+ SundayClosing = sunday?.ClosingTime,
+ MondayOpening = monday?.OpeningTime,
+ MondayClosing = monday?.ClosingTime,
+ TuesdayOpening = tuesday?.OpeningTime,
+ TuesdayClosing = tuesday?.ClosingTime,
+ WednesdayOpening = wednesday?.OpeningTime,
+ WednesdayClosing = wednesday?.ClosingTime,
+ ThursdayOpening = thursday?.OpeningTime,
+ ThursdayClosing = thursday?.ClosingTime,
+ FridayOpening = friday?.OpeningTime,
+ FridayClosing = friday?.ClosingTime,
+ SaturdayOpening = saturday?.OpeningTime,
+ SaturdayClosing = saturday?.ClosingTime
+ };
+ await this.Context.MerchantOpeningHours.AddAsync(merchantOpeningHours);
+ }
+
+ MerchantSchedule schedule = new MerchantSchedule {
+ MerchantId = savedMerchant.MerchantId,
+ Year = 2026,
+ MerchantScheduleId = Guid.NewGuid()
+ };
+
+ List months = new();
+ months.Add(new MerchantScheduleMonth {
+ ClosedDays = "1,2,15",
+ MerchantScheduleId = schedule.MerchantScheduleId,
+ Month = 1
+ });
+ months.Add(new MerchantScheduleMonth
+ {
+ ClosedDays = "10,14,28",
+ MerchantScheduleId = schedule.MerchantScheduleId,
+ Month = 2 });
+ months.Add(new MerchantScheduleMonth
+ {
+ ClosedDays = "24,25,26,31",
+ MerchantScheduleId = schedule.MerchantScheduleId,
+ Month = 12
+ });
+
+ await this.Context.MerchantSchedules.AddAsync(schedule);
+ await this.Context.MerchantScheduleMonths.AddRangeAsync(months);
+
+ MerchantBalanceProjectionState state = new() {
Balance = balance,
MerchantId = savedMerchant.MerchantId,
MerchantName = savedMerchant.Name,
diff --git a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs b/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs
deleted file mode 100644
index 90492c6..0000000
--- a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs
+++ /dev/null
@@ -1,287 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using SimpleResults;
-using TransactionProcessor.Database.Contexts;
-
-namespace EstateReportingAPI.IntegrationTests;
-
-using EstateReportingAPI.DataTrasferObjects;
-using Shouldly;
-using Xunit;
-using Merchant = DataTransferObjects.Merchant;
-using Operator = DataTransferObjects.Operator;
-using ResponseCode = DataTrasferObjects.ResponseCode;
-
-/*public class DimensionsControllerTests : ControllerTestsBase
-{
- [Fact]
- public async Task DimensionsController_GetCalendarYears_NoDataInDatabase()
- {
- var yearsResult = await ApiClient.GetCalendarYears(string.Empty, this.TestId, CancellationToken.None);
- yearsResult.IsFailed.ShouldBeTrue();
- }
-
- [Fact]
- public async Task DimensionsController_GetCalendarYears_YearsReturned()
- {
-
- List yearList = new(){
- 2024,
- 2023,
- 2022,
- 2021
- };
-
- foreach (int year in yearList)
- {
- await helper.AddCalendarYear(year);
- }
-
- var result = await ApiClient.GetCalendarYears(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var years = result.Data;
- years.ShouldNotBeNull();
- years.Count.ShouldBe(yearList.Count);
- }
-
- [Fact]
- public async Task DimensionsController_GetCalendarComparisonDates_DatesReturned()
- {
- List datesInPreviousYear = helper.GetDatesForYear(DateTime.Now.Year - 1);
- await helper.AddCalendarDates(datesInPreviousYear);
- List datesInYear = helper.GetDatesForYear(DateTime.Now.Year);
- await helper.AddCalendarDates(datesInYear);
-
- Result> result = await ApiClient.GetComparisonDates(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List dates = result.Data;
- List expectedDates = datesInYear.Where(d => d <= DateTime.Now.Date.AddDays(-1)).ToList();
- dates.ShouldNotBeNull();
- foreach (DateTime date in expectedDates)
- {
- dates.Select(d => d.Date).Contains(date.Date).ShouldBeTrue();
- }
-
- dates.Select(d => d.Description).Contains("Yesterday");
- dates.Select(d => d.Description).Contains("Last Week");
- dates.Select(d => d.Description).Contains("Last Month");
- }
-
- [Fact]
- public async Task DimensionsController_GetCalendarComparisonDates_NoDataInDatabase()
- {
- var result= await ApiClient.GetComparisonDates(string.Empty, this.TestId, CancellationToken.None);
- result.IsFailed.ShouldBeTrue();;
- }
-
- [Fact]
- public async Task DimensionsController_GetCalendarDates_DatesReturned()
- {
- List datesInYear = helper.GetDatesForYear(2023);
- await helper.AddCalendarDates(datesInYear);
-
- var datesResult = await ApiClient.GetCalendarDates(string.Empty, this.TestId, 2023, CancellationToken.None);
-
- datesResult.IsSuccess.ShouldBeTrue();
- var dates = datesResult.Data;
- dates.ShouldNotBeNull();
- dates.Count.ShouldBe(datesInYear.Where(d => d <= DateTime.Now.Date).ToList().Count);
-
- foreach (DateTime date in datesInYear.Where(d => d <= DateTime.Now.Date).ToList())
- {
- CalendarDate? x = dates.SingleOrDefault(d => d.Date == date);
- x.ShouldNotBeNull();
- }
- }
-
- [Fact]
- public async Task DimensionsController_GetCalendarDates_NoDataInDatabase()
- {
- var datesResult = await ApiClient.GetCalendarDates(string.Empty, this.TestId, 2023, CancellationToken.None);
- datesResult.IsFailed.ShouldBeTrue();
- }
-
- [Fact]
- public async Task DimensionsController_GetMerchants_NoData_NoMerchantsReturned() {
- var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
- result.IsFailed.ShouldBeTrue();
- }
-
- [Fact]
- public async Task DimensionsController_GetMerchants_NoAddresses_MerchantsReturned()
- {
- await helper.AddEstate("Test Estate", "Ref1");
-
- for (int i = 0; i < 10; i++)
- {
- await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now);
- }
-
- var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var merchants = result.Data;
-
- merchants.ShouldNotBeNull();
- merchants.Count.ShouldBe(10);
- merchants.Any(m => string.IsNullOrEmpty(m.Region) == false || string.IsNullOrEmpty(m.Town) == false ||
- string.IsNullOrEmpty(m.PostCode) == false).ShouldBeFalse();
-
- for (int i = 0; i < 10; i++)
- {
- Merchant? expected = merchants.SingleOrDefault(m => m.Name == $"Test Merchant {i}");
- expected.ShouldNotBeNull();
- }
- }
-
- [Fact]
- public async Task DimensionsController_GetMerchants_EachMerchantHasOneAddress_MerchantsReturned()
- {
- await helper.AddEstate("Test Estate", "Ref1");
-
- for (int i = 0; i < 10; i++)
- {
- List<(string addressLine1, string town, string postCode, string region)> addressList = [
- ("Address Line 1", $"Test Town {i}", $"TE57 {i}NG", $"Region {i}")
- ];
-
- await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now, addressList);
- }
-
- var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var merchants = result.Data;
-
- merchants.ShouldNotBeNull();
- merchants.Count.ShouldBe(10);
- merchants.Any(m => string.IsNullOrEmpty(m.Region) == false || string.IsNullOrEmpty(m.Town) == false ||
- string.IsNullOrEmpty(m.PostCode) == false).ShouldBeTrue();
-
- for (int i = 0; i < 10; i++)
- {
- Merchant? expected = merchants.SingleOrDefault(m => m.Name == $"Test Merchant {i}");
- expected.ShouldNotBeNull();
- }
- }
-
- [Fact]
- public async Task DimensionsController_GetMerchants_EachMerchantHasTwoAddress_MerchantsReturned()
- {
- await helper.AddEstate("Test Estate", "Ref1");
-
- for (int i = 0; i < 10; i++)
- {
- List<(string addressLine1, string town, string postCode, string region)> addressList = [];
- for (int j = 0; j < 2; j++)
- {
- addressList.Add(("Address Line 1", $"Test Town {i}{j}", $"TE5{j} {i}NG", $"Region {i}{j}"));
- }
- await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now, addressList);
- }
-
- var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var merchants = result.Data;
-
- merchants.ShouldNotBeNull();
- merchants.Count.ShouldBe(10);
- merchants.Any(m => string.IsNullOrEmpty(m.Region) == false || string.IsNullOrEmpty(m.Town) == false ||
- string.IsNullOrEmpty(m.PostCode) == false).ShouldBeTrue();
-
- for (int i = 0; i < 10; i++)
- {
- Merchant? expected = merchants.SingleOrDefault(m => m.Name == $"Test Merchant {i}");
- expected.ShouldNotBeNull();
- }
- }
-
- [Fact]
- public async Task DimensionsController_GetOperators_NoData_NoOperatorsReturned()
- {
- Result> result = await ApiClient.GetOperators(string.Empty, this.TestId, CancellationToken.None);
- result.IsFailed.ShouldBeTrue();
- }
-
- [Fact]
- public async Task DimensionsController_GetOperators_OperatorsReturned()
- {
- int estateReportingId = await helper.AddEstate("Test Estate", "Ref1");
-
- Int32 operator1ReportingId = await this.helper.AddOperator("Test Estate", "Operator1");
- Int32 operator2ReportingId = await this.helper.AddOperator("Test Estate", "Operator2");
- Int32 operator3ReportingId = await this.helper.AddOperator("Test Estate", "Operator3");
-
- var result = await ApiClient.GetOperators(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
-
- List operators = result.Data;
- operators.ShouldNotBeNull();
- operators.Count.ShouldBe(3);
- var operator1 = operators.SingleOrDefault(o => o.Name == "Operator1");
- operator1.ShouldNotBeNull();
- operator1.EstateReportingId.ShouldBe(estateReportingId);
- operator1.OperatorReportingId.ShouldBe(operator1ReportingId);
- var operator2 = operators.SingleOrDefault(o => o.Name == "Operator2");
- operator2.ShouldNotBeNull();
- operator2.EstateReportingId.ShouldBe(estateReportingId);
- operator2.OperatorReportingId.ShouldBe(operator2ReportingId);
- var operator3 = operators.SingleOrDefault(o => o.Name == "Operator3");
- operator3.ShouldNotBeNull();
- operator3.EstateReportingId.ShouldBe(estateReportingId);
- operator3.OperatorReportingId.ShouldBe(operator3ReportingId);
-
-
- }
-
- [Fact]
- public async Task DimensionsController_GetResponseCodes_ResponseCodesReturned()
- {
- await helper.AddResponseCode(0, "Success");
- await helper.AddResponseCode(1000, "Unknown Device");
- await helper.AddResponseCode(1001, "Unknown Estate");
- await helper.AddResponseCode(1002, "Unknown Merchant");
- await helper.AddResponseCode(1003, "No Devices Configured");
-
- var result = await ApiClient.GetResponseCodes(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
-
- var responseCodes = result.Data;
-
- responseCodes.ShouldNotBeNull();
- responseCodes.Count.ShouldBe(5);
- responseCodes.Any(o => o.Code == 0).ShouldBeTrue();
- responseCodes.Any(o => o.Code == 1000).ShouldBeTrue();
- responseCodes.Any(o => o.Code == 1001).ShouldBeTrue();
- responseCodes.Any(o => o.Code == 1002).ShouldBeTrue();
- responseCodes.Any(o => o.Code == 1003).ShouldBeTrue();
- }
-
- [Fact]
- public async Task DimensionsController_GetResponseCodes_NoData_NoResponseCodesReturned()
- {
- var result = await ApiClient.GetResponseCodes(string.Empty, this.TestId, CancellationToken.None);
- result.IsFailed.ShouldBeTrue();
- }
-
- protected override async Task ClearStandingData()
- {
-
- }
-
- protected override async Task SetupStandingData()
- {
-
- }
-
- public void Dispose()
- {
- //EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}"));
-
- //Console.WriteLine($"About to delete database EstateReportingReadModel{TestId.ToString()}");
- //bool result = context.Database.EnsureDeleted();
- //Console.WriteLine($"Delete result is {result}");
- //result.ShouldBeTrue();
- }
-}*/
\ No newline at end of file
diff --git a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj
index f077d50..1133794 100644
--- a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj
+++ b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs b/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs
deleted file mode 100644
index 4bbb84c..0000000
--- a/EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs
+++ /dev/null
@@ -1,661 +0,0 @@
-/*using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using TransactionProcessor.Database.Contexts;
-using TransactionProcessor.Database.Entities;
-
-namespace EstateReportingAPI.IntegrationTests {
- using EstateReportingAPI.DataTransferObjects;
- using Microsoft.EntityFrameworkCore;
- using Shouldly;
- using System.Diagnostics.Contracts;
- using Xunit;
- using System.Linq;
-
- public class FactSettlementsControllerTests : ControllerTestsBase {
-
- protected override async Task ClearStandingData() {
- await helper.DeleteAllContracts();
- await helper.DeleteAllMerchants();
- }
-
- protected override async Task SetupStandingData() {
- await helper.AddCalendarYear(2024);
- await helper.AddCalendarYear(2025);
-
- // Estates
- await helper.AddEstate("Test Estate", "Ref1");
-
- // Operators
- Int32 safaricomReportingId = await this.helper.AddOperator("Test Estate", "Safaricom");
- Int32 voucherReportingId = await this.helper.AddOperator("Test Estate", "Voucher");
- Int32 pataPawaPostPayReportingId = await this.helper.AddOperator("Test Estate", "PataPawa PostPay");
- Int32 pataPawaPrePay = await this.helper.AddOperator("Test Estate", "PataPawa PrePay");
-
- // Merchants
- await helper.AddMerchant("Test Estate", "Test Merchant 1", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 2", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 3", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 4", DateTime.MinValue);
-
- // Contracts & Products
- List<(string productName, int productType, decimal? value)> safaricomProductList = new() { ("200 KES Topup", 0, 200.00m), ("100 KES Topup", 0, 100.00m), ("50 KES Topup", 0, 50.00m), ("Custom", 0, null) };
- await helper.AddContractWithProducts("Test Estate", "Safaricom Contract", "Safaricom", safaricomProductList);
-
- List<(string productName, int productType, decimal? value)> voucherProductList = new() { ("10 KES Voucher", 0, 10.00m), ("Custom", 0, null) };
- await helper.AddContractWithProducts("Test Estate", "Healthcare Centre 1 Contract", "Voucher", voucherProductList);
-
- List<(string productName, int productType, decimal? value)> postPayProductList = new() { ("Post Pay Bill Pay", 0, null) };
- await helper.AddContractWithProducts("Test Estate", "PataPawa PostPay Contract", "PataPawa PostPay", postPayProductList);
-
- List<(string productName, int productType, decimal? value)> prePayProductList = new() { ("Pre Pay Bill Pay", 0, null) };
- await helper.AddContractWithProducts("Test Estate", "PataPawa PrePay Contract", "PataPawa PrePay", prePayProductList);
-
- // Response Codes
- await helper.AddResponseCode(0, "Success");
- await helper.AddResponseCode(1000, "Unknown Device");
- await helper.AddResponseCode(1001, "Unknown Estate");
- await helper.AddResponseCode(1002, "Unknown Merchant");
- await helper.AddResponseCode(1003, "No Devices Configured");
-
- merchantsList = context.Merchants.Select(m => m).ToList();
-
- contractList = context.Contracts.Join(context.Operators, c => c.OperatorId, o => o.OperatorId, (c,
- o) => new { c.ContractId, c.Description, o.OperatorId, o.Name }).ToList().Select(x => (x.ContractId, x.Description, x.OperatorId, x.Name)).ToList();
-
- var query1 = context.Contracts.GroupJoin(context.ContractProducts, c => c.ContractId, cp => cp.ContractId, (c,
- productGroup) => new { c.ContractId, Products = productGroup.Select(p => new { p.ContractProductId, p.ProductName, p.Value }).OrderBy(p => p.ContractProductId).Select(p => new { p.ContractProductId, p.ProductName, p.Value }).ToList() }).ToList();
-
- contractProducts = query1.ToDictionary(item => item.ContractId, item => item.Products.Select(i => (i.ContractProductId, i.ProductName, i.Value)).ToList());
- }
-
- [Fact]
- public async Task FactSettlementsController_TodaysSettlement_SettlementReturned() {
- int overallTodaysSettlementTransactionCount = 0;
- int overallTodaysPendingSettlementTransactionCount = 0;
-
- int overallComparisonSettlementTransactionCount = 0;
- int overallComparisonPendingSettlementTransactionCount = 0;
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> todayOverallTotals = new();
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> comparisonOverallTotals = new();
-
- DateTime todaysDate = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1);
- foreach (var merchant in merchantsList) {
- int todaysSettlementTransactionCount = 5;
- int todaysPendingSettlementTransactionCount = 9;
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- (decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees) todayTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, todaysDate, todaysSettlementTransactionCount, todaysPendingSettlementTransactionCount);
- todayOverallTotals.Add(todayTotals);
-
- overallTodaysSettlementTransactionCount += todaysSettlementTransactionCount;
- ;
- overallTodaysPendingSettlementTransactionCount += todaysPendingSettlementTransactionCount;
-
- int comparisonSettlementTransactionCount = 12;
- int comparisonPendingSettlementTransactionCount = 15;
- var comparisonTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, comparisonDate, comparisonSettlementTransactionCount, comparisonPendingSettlementTransactionCount);
- comparisonOverallTotals.Add(comparisonTotals);
-
- overallComparisonSettlementTransactionCount += comparisonSettlementTransactionCount;
- overallComparisonPendingSettlementTransactionCount += comparisonPendingSettlementTransactionCount;
- }
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDate.Date.AddDays(-1));
- await helper.RunSettlementSummaryProcessing(comparisonDate.Date);
-
- var result = await ApiClient.GetTodaysSettlement(string.Empty, this.TestId, 0, 0, DateTime.Now.AddDays(-1), CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSettlement = result.Data;
- todaysSettlement.ShouldNotBeNull();
- todaysSettlement.ComparisonSettlementCount.ShouldBe(overallComparisonSettlementTransactionCount);
- todaysSettlement.ComparisonSettlementValue.ShouldBe(comparisonOverallTotals.Sum(c => c.settlementFees));
- todaysSettlement.ComparisonPendingSettlementCount.ShouldBe(overallComparisonPendingSettlementTransactionCount);
- todaysSettlement.ComparisonPendingSettlementValue.ShouldBe(comparisonOverallTotals.Sum(c => c.pendingSettlementFees));
-
- todaysSettlement.TodaysSettlementCount.ShouldBe(overallTodaysSettlementTransactionCount);
- todaysSettlement.TodaysSettlementValue.ShouldBe(todayOverallTotals.Sum(c => c.settlementFees));
- todaysSettlement.TodaysPendingSettlementCount.ShouldBe(overallTodaysPendingSettlementTransactionCount);
- todaysSettlement.TodaysPendingSettlementValue.ShouldBe(todayOverallTotals.Sum(c => c.pendingSettlementFees));
- }
-
- [Fact]
- public async Task FactSettlementsController_TodaysSettlement_MerchantFilter_SettlementReturned()
- {
- int overallTodaysSettlementTransactionCount = 0;
- int overallTodaysPendingSettlementTransactionCount = 0;
-
- int overallComparisonSettlementTransactionCount = 0;
- int overallComparisonPendingSettlementTransactionCount = 0;
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> todayOverallTotals = new();
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> comparisonOverallTotals = new();
-
- DateTime todaysDate = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1);
- Dictionary merchantTodaysSettlementFees = new();
- Dictionary merchantTodaysPendingSettlementFees = new();
- Dictionary merchantComparisonSettlementFees = new();
- Dictionary merchantComparisonPendingSettlementFees = new();
-
- Dictionary merchantTodaysSettlementTransactionCount = new();
- Dictionary merchantTodaysPendingSettlementTransactionCount = new();
- Dictionary merchantComparisonSettlementTransactionCount = new();
- Dictionary merchantComparisonPendingSettlementTransactionCount = new();
-
- foreach (var merchant in merchantsList)
- {
- merchantTodaysSettlementTransactionCount.Add(merchant.MerchantReportingId, 0);
- merchantTodaysPendingSettlementTransactionCount.Add(merchant.MerchantReportingId, 0);
- merchantComparisonSettlementTransactionCount.Add(merchant.MerchantReportingId, 0);
- merchantComparisonPendingSettlementTransactionCount.Add(merchant.MerchantReportingId, 0);
-
- merchantTodaysSettlementFees.Add(merchant.MerchantReportingId, 0);
- merchantTodaysPendingSettlementFees.Add(merchant.MerchantReportingId, 0);
- merchantComparisonSettlementFees.Add(merchant.MerchantReportingId, 0);
- merchantComparisonPendingSettlementFees.Add(merchant.MerchantReportingId, 0);
-
- int todaysSettlementTransactionCount = 5;
- int todaysPendingSettlementTransactionCount = 9;
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- (decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees) todayTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, todaysDate, todaysSettlementTransactionCount, todaysPendingSettlementTransactionCount);
- todayOverallTotals.Add(todayTotals);
-
- overallTodaysSettlementTransactionCount += todaysSettlementTransactionCount;
- overallTodaysPendingSettlementTransactionCount += todaysPendingSettlementTransactionCount;
-
- merchantTodaysSettlementTransactionCount[merchant.MerchantReportingId] = todaysSettlementTransactionCount;
- merchantTodaysPendingSettlementTransactionCount[merchant.MerchantReportingId] = todaysPendingSettlementTransactionCount;
-
- merchantTodaysSettlementFees[merchant.MerchantReportingId] = todayTotals.settlementFees;
- merchantTodaysPendingSettlementFees[merchant.MerchantReportingId] = todayTotals.pendingSettlementFees;
-
- int comparisonSettlementTransactionCount = 12;
- int comparisonPendingSettlementTransactionCount = 15;
- var comparisonTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, comparisonDate, comparisonSettlementTransactionCount, comparisonPendingSettlementTransactionCount);
- comparisonOverallTotals.Add(comparisonTotals);
-
- overallComparisonSettlementTransactionCount += comparisonSettlementTransactionCount;
- overallComparisonPendingSettlementTransactionCount += comparisonPendingSettlementTransactionCount;
-
- merchantComparisonSettlementTransactionCount[merchant.MerchantReportingId] = comparisonSettlementTransactionCount;
- merchantComparisonPendingSettlementTransactionCount[merchant.MerchantReportingId] = comparisonPendingSettlementTransactionCount;
-
- merchantComparisonSettlementFees[merchant.MerchantReportingId] = comparisonTotals.settlementFees;
- merchantComparisonPendingSettlementFees[merchant.MerchantReportingId] = comparisonTotals.pendingSettlementFees;
- }
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDate.Date.AddDays(-1));
- await helper.RunSettlementSummaryProcessing(comparisonDate.Date);
-
- var result = await ApiClient.GetTodaysSettlement(string.Empty, this.TestId, 1, 0, DateTime.Now.AddDays(-1), CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSettlement = result.Data;
- todaysSettlement.ShouldNotBeNull();
- todaysSettlement.ComparisonSettlementCount.ShouldBe(merchantComparisonSettlementTransactionCount[1]);
- todaysSettlement.ComparisonSettlementValue.ShouldBe(merchantComparisonSettlementFees[1]);
- todaysSettlement.ComparisonPendingSettlementCount.ShouldBe(merchantComparisonPendingSettlementTransactionCount[1]);
- todaysSettlement.ComparisonPendingSettlementValue.ShouldBe(merchantComparisonPendingSettlementFees[1]);
-
- todaysSettlement.TodaysSettlementCount.ShouldBe(merchantTodaysSettlementTransactionCount[1]);
- todaysSettlement.TodaysSettlementValue.ShouldBe(merchantTodaysSettlementFees[1]);
- todaysSettlement.TodaysPendingSettlementCount.ShouldBe(merchantTodaysPendingSettlementTransactionCount[1]);
- todaysSettlement.TodaysPendingSettlementValue.ShouldBe(merchantTodaysPendingSettlementFees[1]);
- }
-
- [Fact]
- public async Task FactSettlementsController_TodaysSettlement_OperatorFilter_SettlementReturned()
- {
- int overallTodaysSettlementTransactionCount = 0;
- int overallTodaysPendingSettlementTransactionCount = 0;
-
- int overallComparisonSettlementTransactionCount = 0;
- int overallComparisonPendingSettlementTransactionCount = 0;
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> todayOverallTotals = new();
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> comparisonOverallTotals = new();
-
- DateTime todaysDate = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1);
- Dictionary operatorTodaysSettlementFees = new();
- Dictionary operatorTodaysPendingSettlementFees = new();
- Dictionary operatorComparisonSettlementFees = new();
- Dictionary operatorComparisonPendingSettlementFees = new();
-
- Dictionary operatorTodaysSettlementTransactionCount = new();
- Dictionary operatorTodaysPendingSettlementTransactionCount = new();
- Dictionary operatorComparisonSettlementTransactionCount = new();
- Dictionary operatorComparisonPendingSettlementTransactionCount = new();
-
- foreach (var @operator in this.contractList.Select(c => c.operatorName)) {
- var operatorRecord = this.context.Operators.Single(o => o.Name == @operator);
- operatorTodaysSettlementTransactionCount.Add(operatorRecord.OperatorReportingId, 0);
- operatorTodaysPendingSettlementTransactionCount.Add(operatorRecord.OperatorReportingId, 0);
- operatorComparisonSettlementTransactionCount.Add(operatorRecord.OperatorReportingId, 0);
- operatorComparisonPendingSettlementTransactionCount.Add(operatorRecord.OperatorReportingId, 0);
-
- operatorTodaysSettlementFees.Add(operatorRecord.OperatorReportingId, 0);
- operatorTodaysPendingSettlementFees.Add(operatorRecord.OperatorReportingId, 0);
- operatorComparisonSettlementFees.Add(operatorRecord.OperatorReportingId, 0);
- operatorComparisonPendingSettlementFees.Add(operatorRecord.OperatorReportingId, 0);
- foreach (var merchant in merchantsList) {
-
- int todaysSettlementTransactionCount = 5;
- int todaysPendingSettlementTransactionCount = 9;
- var contract = this.contractList.Single(c => c.operatorName == @operator);
- (decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees) todayTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, todaysDate, todaysSettlementTransactionCount, todaysPendingSettlementTransactionCount);
- todayOverallTotals.Add(todayTotals);
-
- overallTodaysSettlementTransactionCount += todaysSettlementTransactionCount;
- overallTodaysPendingSettlementTransactionCount += todaysPendingSettlementTransactionCount;
-
- operatorTodaysSettlementTransactionCount[operatorRecord.OperatorReportingId] += todaysSettlementTransactionCount;
- operatorTodaysPendingSettlementTransactionCount[operatorRecord.OperatorReportingId] += todaysPendingSettlementTransactionCount;
-
- operatorTodaysSettlementFees[operatorRecord.OperatorReportingId] += todayTotals.settlementFees;
- operatorTodaysPendingSettlementFees[operatorRecord.OperatorReportingId] += todayTotals.pendingSettlementFees;
-
- int comparisonSettlementTransactionCount = 12;
- int comparisonPendingSettlementTransactionCount = 15;
- var comparisonTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, comparisonDate, comparisonSettlementTransactionCount, comparisonPendingSettlementTransactionCount);
- comparisonOverallTotals.Add(comparisonTotals);
-
- overallComparisonSettlementTransactionCount += comparisonSettlementTransactionCount;
- overallComparisonPendingSettlementTransactionCount += comparisonPendingSettlementTransactionCount;
-
- operatorComparisonSettlementTransactionCount[operatorRecord.OperatorReportingId] += comparisonSettlementTransactionCount;
- operatorComparisonPendingSettlementTransactionCount[operatorRecord.OperatorReportingId] += comparisonPendingSettlementTransactionCount;
-
- operatorComparisonSettlementFees[operatorRecord.OperatorReportingId] += comparisonTotals.settlementFees;
- operatorComparisonPendingSettlementFees[operatorRecord.OperatorReportingId] += comparisonTotals.pendingSettlementFees;
- }
-
- }
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date.AddDays(-1));
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDate.Date.AddDays(-1));
- await helper.RunSettlementSummaryProcessing(comparisonDate.Date);
-
- var result = await ApiClient.GetTodaysSettlement(string.Empty, this.TestId, 0, 1, DateTime.Now.AddDays(-1), CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSettlement = result.Data;
- todaysSettlement.ShouldNotBeNull();
- todaysSettlement.ComparisonSettlementCount.ShouldBe(operatorComparisonSettlementTransactionCount[1]);
- todaysSettlement.ComparisonSettlementValue.ShouldBe(operatorComparisonSettlementFees[1]);
- todaysSettlement.ComparisonPendingSettlementCount.ShouldBe(operatorComparisonPendingSettlementTransactionCount[1]);
- todaysSettlement.ComparisonPendingSettlementValue.ShouldBe(operatorComparisonPendingSettlementFees[1]);
-
- todaysSettlement.TodaysSettlementCount.ShouldBe(operatorTodaysSettlementTransactionCount[1]);
- todaysSettlement.TodaysSettlementValue.ShouldBe(operatorTodaysSettlementFees[1]);
- todaysSettlement.TodaysPendingSettlementCount.ShouldBe(operatorTodaysPendingSettlementTransactionCount[1]);
- todaysSettlement.TodaysPendingSettlementValue.ShouldBe(operatorTodaysPendingSettlementFees[1]);
- }
-
- [Fact]
- public async Task FactSettlementsController_LastSettlement_SettlementReturned() {
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> incompleteTotalsList = new();
- List<(decimal settledTransactions, decimal pendingSettlementTransactions, decimal settlementFees, decimal pendingSettlementFees)> completeTotalsList = new();
-
- // Add todays settlement (incomplete)
- Int32 totalSettledTransactionCount = 0;
- Int32 totalPendingSettlementTransactionCount = 21;
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- foreach (Merchant merchant in merchantsList) {
- Int32 settledTransactionCount = 0;
- totalSettledTransactionCount += settledTransactionCount;
- int pendingSettlementTransactionCount = 21;
- totalPendingSettlementTransactionCount += pendingSettlementTransactionCount;
- var incompleteTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, DateTime.Now, settledTransactionCount, pendingSettlementTransactionCount);
- incompleteTotalsList.Add(incompleteTotals);
- }
-
- // Add yesterdays settlement (complete)
- foreach (Merchant merchant in merchantsList) {
- Int32 settledTransactionCount = 18;
- totalSettledTransactionCount += settledTransactionCount;
- int pendingSettlementTransactionCount = 0;
- totalPendingSettlementTransactionCount += pendingSettlementTransactionCount;
- var completeTotals = await helper.AddSettlementRecord(merchant.EstateId, merchant.MerchantId, contract.operatorId, DateTime.Now.AddDays(-1), settledTransactionCount, pendingSettlementTransactionCount);
- completeTotalsList.Add(completeTotals);
- }
-
- await helper.RunSettlementSummaryProcessing(DateTime.Now.AddDays(-1));
-
- var result = await ApiClient.GetLastSettlement(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var lastSettlement = result.Data;
-
- lastSettlement.ShouldNotBeNull();
- lastSettlement.FeesValue.ShouldBe(completeTotalsList.Sum(t => t.settlementFees));
- lastSettlement.SalesCount.ShouldBe(totalSettledTransactionCount);
- lastSettlement.SalesValue.ShouldBe(completeTotalsList.Sum(c => c.settledTransactions));
- }
-
- [Fact]
- public async Task FactSettlementsController_LastSettlement_NoSettlementRecords_SettlementReturned() {
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- await helper.RunSettlementSummaryProcessing(DateTime.Now.AddDays(-1));
-
- var result = await ApiClient.GetLastSettlement(string.Empty, this.TestId, CancellationToken.None);
- result.IsFailed.ShouldBeTrue();
- }
-
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByOperator_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, null, null, null, GroupByOption.Operator, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
-
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
- unsettledFees.Count.ShouldBe(this.contractList.Count);
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var c = await this.context.Contracts.SingleOrDefaultAsync(c => c.ContractId == contract.contractId, CancellationToken.None);
- var cps = await this.context.ContractProducts.Where(cp => cp.ContractId == c.ContractId).Select(cp => cp.ContractProductId).ToListAsync(CancellationToken.None);
- var tf = await context.ContractProductTransactionFees.Where(cptf => cps.Contains(cptf.ContractProductId)).Select(t => t.ContractProductTransactionFeeId).ToListAsync(CancellationToken.None);
-
- var expectedFees = this.context.MerchantSettlementFees.Where(f => tf.Contains(f.ContractProductTransactionFeeId));
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == contract.operatorName);
-
- u.ShouldNotBeNull();
- u.FeesCount.ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- u.FeesValue.ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
- }
- }
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByOperator_OperatorFilter_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, null, [1], null, GroupByOption.Operator, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
-
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
-
- var @operator = await this.context.Operators.SingleOrDefaultAsync(o => o.OperatorReportingId == 1, CancellationToken.None);
- var c = await this.context.Contracts.SingleOrDefaultAsync(c => c.OperatorId == @operator.OperatorId, CancellationToken.None);
- var cps = await this.context.ContractProducts.Where(cp => cp.ContractId == c.ContractId).Select(cp => cp.ContractProductId).ToListAsync(CancellationToken.None);
- var tf = await context.ContractProductTransactionFees.Where(cptf => cps.Contains(cptf.ContractProductId)).Select(t => t.ContractProductTransactionFeeId).ToListAsync(CancellationToken.None);
-
- var expectedFees = this.context.MerchantSettlementFees.Where(f => tf.Contains(f.ContractProductTransactionFeeId));
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == @operator.Name);
-
- unsettledFees.Sum(d => d.FeesCount).ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- unsettledFees.Sum(d => d.FeesValue).ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
-
- }
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByMerchant_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, null, null, null, GroupByOption.Merchant, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
- unsettledFees.Count.ShouldBe(this.merchantsList.Count);
- foreach (var merchant in this.merchantsList) {
- var expectedFees = this.context.MerchantSettlementFees.Where(f => f.MerchantId == merchant.MerchantId);
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == merchant.Name);
-
- u.ShouldNotBeNull();
- u.FeesCount.ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- u.FeesValue.ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
- }
- }
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByMerchant_MerchantFilter_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, [1], null, null, GroupByOption.Merchant, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
-
- var merchantRecord = await this.context.Merchants.SingleOrDefaultAsync(me => me.MerchantReportingId == 1);
- var expectedFees = this.context.MerchantSettlementFees.Where(f => f.MerchantId == merchantRecord.MerchantId);
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == merchantRecord.Name);
-
- u.ShouldNotBeNull();
- u.FeesCount.ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- u.FeesValue.ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
- }
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByProduct_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, null, null, null, GroupByOption.Product, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
-
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
-
- List<(String, Guid, String)> allProducts = new();
- foreach (KeyValuePair> contractProduct in this.contractProducts) {
- var contract = this.contractList.Single(c => c.contractId == contractProduct.Key);
- var @operator = await this.context.Operators.SingleOrDefaultAsync(o => o.OperatorId == contract.operatorId, CancellationToken.None);
-
- foreach ((Guid productId, String productName, Decimal? productValue) s in contractProduct.Value) {
- allProducts.Add((@operator.Name, contractProduct.Key, s.productName));
- }
- }
-
- unsettledFees.Count.ShouldBe(allProducts.Distinct().Count());
- foreach (var contractProduct in allProducts.Distinct()) {
- var product = await this.context.ContractProducts.Where(cp => cp.ProductName == contractProduct.Item3 && cp.ContractId == contractProduct.Item2).SingleOrDefaultAsync(CancellationToken.None);
- var tf = await context.ContractProductTransactionFees.Where(cptf => cptf.ContractProductId == product.ContractProductId).ToListAsync(CancellationToken.None);
- var expectedFees = this.context.MerchantSettlementFees.Where(f => tf.Select(t => t.ContractProductTransactionFeeId).Contains(f.ContractProductTransactionFeeId));
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == $"{contractProduct.Item1} - {contractProduct.Item3}");
-
- u.ShouldNotBeNull($"{contractProduct.Item1} - {contractProduct.Item2}");
- u.FeesCount.ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- u.FeesValue.ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
- }
- }
-
- [Fact]
- public async Task FactSettlementsController_UnsettledFees_ByProduct_ProductFilter_SettlementReturned() {
- // Add some fees over a date range for multiple operators
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
-
- DatabaseHelper helper = new DatabaseHelper(context);
-
- List dates = new();
- dates.Add(new DateTime(2024, 5, 24));
- dates.Add(new DateTime(2024, 5, 25));
- dates.Add(new DateTime(2024, 5, 26));
- dates.Add(new DateTime(2024, 5, 27));
-
- foreach (DateTime dateTime in dates) {
- Guid settlementId = Guid.NewGuid();
- foreach (Merchant merchant in this.merchantsList) {
- foreach ((Guid contractId, String contractName, Guid operatorId, String operatorName) contract in this.contractList) {
- var products = this.contractProducts.Single(cp => cp.Key == contract.contractId);
-
- foreach (var product in products.Value) {
- await helper.AddMerchantSettlementFee(settlementId, dateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, CancellationToken.None);
- }
- }
- }
- }
-
- DateTime startDate = dates.Min();
- DateTime endDate = dates.Max();
-
- var result = await ApiClient.GetUnsettledFees(string.Empty, this.TestId, startDate, endDate, null, null, [1], GroupByOption.Product, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var unsettledFees = result.Data;
-
- unsettledFees.ShouldNotBeNull();
- unsettledFees.ShouldNotBeEmpty();
-
- var contractProduct = await this.context.ContractProducts.Where(cp => cp.ContractProductReportingId == 1).SingleOrDefaultAsync(CancellationToken.None);
- var contractRecord = this.contractList.Single(c => c.contractId == contractProduct.ContractId);
- var @operator = await this.context.Operators.SingleOrDefaultAsync(o => o.OperatorId == contractRecord.operatorId, CancellationToken.None);
- var tf = await context.ContractProductTransactionFees.Where(cptf => cptf.ContractProductId == contractProduct.ContractProductId).ToListAsync(CancellationToken.None);
- var expectedFees = this.context.MerchantSettlementFees.Where(f => tf.Select(t => t.ContractProductTransactionFeeId).Contains(f.ContractProductTransactionFeeId));
-
- var u = unsettledFees.SingleOrDefault(u => u.DimensionName == $"{@operator.Name} - {contractProduct.ProductName}");
-
- u.ShouldNotBeNull($"{@operator.Name} - {contractProduct.ProductName}");
- u.FeesCount.ShouldBe(await expectedFees.CountAsync(CancellationToken.None));
- u.FeesValue.ShouldBe(await expectedFees.SumAsync(f => f.CalculatedValue, CancellationToken.None));
-
- }
- }
-}
-
-*/
\ No newline at end of file
diff --git a/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs b/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs
deleted file mode 100644
index 7c52a8a..0000000
--- a/EstateReportingAPI.IntegrationTests/FactTransactionsControllerTests.cs
+++ /dev/null
@@ -1,1873 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-using Ductus.FluentDocker.Common;
-using EstateReportingAPI.IntegrationTests;
-using Microsoft.EntityFrameworkCore;
-using TransactionProcessor.Database.Contexts;
-using TransactionProcessor.Database.Entities;
-using Xunit.Abstractions;
-
-namespace EstateReportingAPI.IntegrationTests;
-
-using System.Collections.Generic;
-using System.Diagnostics.Contracts;
-using System.Linq;
-using DataTrasferObjects;
-using EstateReportingAPI.DataTransferObjects;
-using EstateReportingAPI.Models;
-using Newtonsoft.Json;
-using Shouldly;
-using Xunit;
-using Merchant = DataTransferObjects.Merchant;
-using SortDirection = DataTransferObjects.SortDirection;
-
-/*
-public class FactTransactionsControllerTestsBase : ControllerTestsBase {
-
- protected override async Task ClearStandingData()
- {
- await helper.DeleteAllContracts();
- await helper.DeleteAllMerchants();
- }
-
- protected override async Task SetupStandingData()
- {
- Stopwatch sw = Stopwatch.StartNew();
- this.TestOutputHelper.WriteLine("Setting up standing data");
-
- // Estates
- await helper.AddEstate("Test Estate", "Ref1");
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Estate {sw.ElapsedMilliseconds}ms");
- sw.Restart();
- // Operators
- Int32 safaricomReportingId = await this.helper.AddOperator("Test Estate", "Safaricom");
- Int32 voucherReportingId = await this.helper.AddOperator("Test Estate", "Voucher");
- Int32 pataPawaPostPayReportingId = await this.helper.AddOperator("Test Estate", "PataPawa PostPay");
- Int32 pataPawaPrePay = await this.helper.AddOperator("Test Estate", "PataPawa PrePay");
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Operators {sw.ElapsedMilliseconds}ms");
- sw.Restart();
- // Merchants
- await helper.AddMerchant("Test Estate", "Test Merchant 1", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 2", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 3", DateTime.MinValue);
- await helper.AddMerchant("Test Estate", "Test Merchant 4", DateTime.MinValue);
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Merchants {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- // Contracts & Products
- List<(string productName, int productType, decimal? value)> safaricomProductList = new(){
- ("200 KES Topup", 0, 200.00m),
- ("100 KES Topup", 0, 100.00m),
- ("50 KES Topup", 0, 50.00m),
- ("Custom", 0, null)
- };
- await helper.AddContractWithProducts("Test Estate", "Safaricom Contract", "Safaricom", safaricomProductList);
-
- List<(string productName, int productType, decimal? value)> voucherProductList = new(){
- ("10 KES Voucher", 0, 10.00m),
- ("Custom", 0, null)
- };
- await helper.AddContractWithProducts("Test Estate", "Healthcare Centre 1 Contract", "Voucher", voucherProductList);
-
- List<(string productName, int productType, decimal? value)> postPayProductList = new(){
- ("Post Pay Bill Pay", 0, null)
- };
- await helper.AddContractWithProducts("Test Estate", "PataPawa PostPay Contract", "PataPawa PostPay", postPayProductList);
-
- List<(string productName, int productType, decimal? value)> prePayProductList = new(){
- ("Pre Pay Bill Pay", 0, null)
- };
- await helper.AddContractWithProducts("Test Estate", "PataPawa PrePay Contract", "PataPawa PrePay", prePayProductList);
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Contracts {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- // Response Codes
- await helper.AddResponseCode(0, "Success");
- await helper.AddResponseCode(1000, "Unknown Device");
- await helper.AddResponseCode(1001, "Unknown Estate");
- await helper.AddResponseCode(1002, "Unknown Merchant");
- await helper.AddResponseCode(1003, "No Devices Configured");
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Response Codes {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- merchantsList = context.Merchants.Select(m => m).ToList();
-
- contractList = context.Contracts
- .Join(
- context.Operators,
- c => c.OperatorId,
- o => o.OperatorId,
- (c, o) => new { c.ContractId, c.Description, o.OperatorId, o.Name}
- )
- .ToList().Select(x => (x.ContractId, x.Description, x.OperatorId,x.Name))
- .ToList();
-
- var query1 = context.Contracts
- .GroupJoin(
- context.ContractProducts,
- c => c.ContractId,
- cp => cp.ContractId,
- (c, productGroup) => new
- {
- c.ContractId,
- Products = productGroup.Select(p => new { p.ContractProductId, p.ProductName, p.Value})
- .OrderBy(p => p.ContractProductId)
- .Select(p => new {p.ContractProductId,p.ProductName, p.Value})
- .ToList()
- })
- .ToList();
-
- contractProducts = query1.ToDictionary(
- item => item.ContractId,
- item => item.Products.Select(i => (i.ContractProductId, i.ProductName, i.Value)).ToList()
- );
-
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Data Caching {sw.ElapsedMilliseconds}ms");
- sw.Restart();
- }
-
- public FactTransactionsControllerTestsBase(ITestOutputHelper testOutputHelper) {
- this.TestOutputHelper = testOutputHelper;
- }
-}
-
-public class FactTransactionsControllerTests_OperatorsTests : FactTransactionsControllerTestsBase {
- public FactTransactionsControllerTests_OperatorsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
- {
-
- }
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomOperatorsByValue_BottomOperators_OperatorsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- Dictionary transactionCounts = new() {
- { "Safaricom", 25 }, // 5000
- { "Voucher", 15 }, // 150
- { "PataPawa PostPay", 45 }, // 3375
- { "PataPawa PrePay", 8 } // 600
- };
-
- Dictionary> transactionsDictionary = new();
- var merchant = merchantsList.First();
- foreach (KeyValuePair transactionCount in transactionCounts) {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(transactionCount.Key) == false) {
- transactionsDictionary.Add(transactionCount.Key, new List());
- }
-
- transactionsDictionary[transactionCount.Key].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t=> t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTopBottomOperatorData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Bottom, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomOperatorData = result.Data;
- topBottomOperatorData.ShouldNotBeNull();
- topBottomOperatorData[0].OperatorName.ShouldBe("Voucher");
- topBottomOperatorData[0].SalesValue.ShouldBe(transactionsDictionary["Voucher"].Sum(p => p.TransactionAmount));
- topBottomOperatorData[1].OperatorName.ShouldBe("PataPawa PrePay");
- topBottomOperatorData[1].SalesValue.ShouldBe(transactionsDictionary["PataPawa PrePay"].Sum(p => p.TransactionAmount));
- topBottomOperatorData[2].OperatorName.ShouldBe("PataPawa PostPay");
- topBottomOperatorData[2].SalesValue.ShouldBe(transactionsDictionary["PataPawa PostPay"].Sum(p => p.TransactionAmount));
- }
-
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomOperatorsByValue_TopOperators_OperatorsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- Dictionary transactionCounts = new() {
- { "Safaricom", 25 }, // 5000
- { "Voucher", 15 }, // 150
- { "PataPawa PostPay", 45 }, // 3375
- { "PataPawa PrePay", 8 } // 600
- };
-
- Dictionary> transactionsDictionary = new();
- var merchant = merchantsList.First();
- foreach (KeyValuePair transactionCount in transactionCounts)
- {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++)
- {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(transactionCount.Key) == false)
- {
- transactionsDictionary.Add(transactionCount.Key, new List());
- }
-
- transactionsDictionary[transactionCount.Key].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t => t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTopBottomOperatorData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Top, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomOperatorData = result.Data;
- topBottomOperatorData[0].OperatorName.ShouldBe("Safaricom");
- topBottomOperatorData[0].SalesValue.ShouldBe(transactionsDictionary["Safaricom"].Sum(p => p.TransactionAmount));
- topBottomOperatorData[1].OperatorName.ShouldBe("PataPawa PostPay");
- topBottomOperatorData[1].SalesValue.ShouldBe(transactionsDictionary["PataPawa PostPay"].Sum(p => p.TransactionAmount));
- topBottomOperatorData[2].OperatorName.ShouldBe("PataPawa PrePay");
- topBottomOperatorData[2].SalesValue.ShouldBe(transactionsDictionary["PataPawa PrePay"].Sum(p => p.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_OperatorPerformance_SingleOperator_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() {
- { "Safaricom", 25 }, // 5000
- { "Voucher", 15 }, // 150
- { "PataPawa PostPay", 45 }, // 3375
- { "PataPawa PrePay", 8 } // 600
- };
-
- var merchant = merchantsList.First();
- foreach (KeyValuePair transactionCount in transactionCounts)
- {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++)
- {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- foreach (KeyValuePair transactionCount in transactionCounts)
- {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++)
- {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- List operatorFilterList = new List { 2 };
- var operatorIdsForVerify = await context.Operators.Where(cp => cp.OperatorReportingId == 2).Select(cp => cp.OperatorId).ToListAsync(CancellationToken.None);
-
-
- string serializedArray = string.Join(",", operatorFilterList);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetOperatorPerformance(string.Empty, this.TestId, comparisonDate, operatorFilterList, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => operatorIdsForVerify.Contains(c.OperatorId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => operatorIdsForVerify.Contains(c.OperatorId)).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => operatorIdsForVerify.Contains(c.OperatorId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => operatorIdsForVerify.Contains(c.OperatorId)).Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_OperatorPerformance_MultipleOperators_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() {
- { "Safaricom", 25 }, // 5000
- { "Voucher", 15 }, // 150
- { "PataPawa PostPay", 45 }, // 3375
- { "PataPawa PrePay", 8 } // 600
- };
-
- var merchant = merchantsList.First();
- foreach (KeyValuePair transactionCount in transactionCounts)
- {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++)
- {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- foreach (KeyValuePair transactionCount in transactionCounts)
- {
- var contract = contractList.Single(s => s.operatorName == transactionCount.Key);
- var products = contractProducts.Single(p => p.Key == contract.contractId);
- var product = products.Value.OrderByDescending(p => p.productValue.GetValueOrDefault()).First();
- for (int i = 0; i < transactionCount.Value; i++)
- {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- List operatorFilterList = new List { 2, 3 };
-
- var operatorIdsForVerify = await context.Operators.Where(cp => cp.OperatorReportingId >= 2 && cp.OperatorReportingId <= 3).Select(cp => cp.OperatorId).ToListAsync(CancellationToken.None);
-
- string serializedArray = string.Join(",", operatorFilterList);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetOperatorPerformance(string.Empty, this.TestId, comparisonDate, operatorFilterList, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => operatorIdsForVerify.Contains(c.OperatorId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => operatorIdsForVerify.Contains(c.OperatorId)).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => operatorIdsForVerify.Contains(c.OperatorId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => operatorIdsForVerify.Contains(c.OperatorId)).Sum(c => c.TransactionAmount));
- }
-}
-
-public class FactTransactionsControllerTests_ProductsTests : FactTransactionsControllerTestsBase {
- public FactTransactionsControllerTests_ProductsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) {
-
- }
-
-
- [Fact]
- public async Task FactTransactionsControllerController_ProductPerformance_AllProducts_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- var merchant = merchantsList.First();
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- List<(Guid, String, Decimal?)> productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
-
- Dictionary transactionCounts = new() {
- { "200 KES Topup", 25 }, //5000
- { "100 KES Topup", 15 }, // 1500
- { "50 KES Topup", 45 }, // 2250
- { "Custom", 8 } // 600
- };
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetProductPerformance(string.Empty, this.TestId, comparisonDate, new List(), CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
- }
-
-
- [Fact]
- public async Task FactTransactionsControllerController_ProductPerformance_SingleProduct_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- var merchant = merchantsList.First();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
-
- Dictionary transactionCounts = new() {
- { "200 KES Topup", 25 }, //5000
- { "100 KES Topup", 15 }, // 1500
- { "50 KES Topup", 45 }, // 2250
- { "Custom", 8 } // 600
- };
-
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
-
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- List productFilterList = new List { 2 };
-
- var productIdsForVerify = await context.ContractProducts.Where(cp => cp.ContractProductReportingId == 2).Select(cp => cp.ContractProductId).ToListAsync(CancellationToken.None);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- string serializedArray = string.Join(",", productFilterList);
-
- var result = await ApiClient.GetProductPerformance(string.Empty, this.TestId, comparisonDate, productFilterList, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => productIdsForVerify.Contains(c.ContractProductId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => productIdsForVerify.Contains(c.ContractProductId)).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => productIdsForVerify.Contains(c.ContractProductId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => productIdsForVerify.Contains(c.ContractProductId)).Sum(c => c.TransactionAmount));
- }
-
-
- [Fact]
- public async Task FactTransactionsControllerController_ProductPerformance_MultipleProducts_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- var merchant = merchantsList.First();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
-
- Dictionary transactionCounts = new() {
- { "200 KES Topup", 25 }, //5000
- { "100 KES Topup", 15 }, // 1500
- { "50 KES Topup", 45 }, // 2250
- { "Custom", 8 } // 600
- };
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- List productFilterList = new List { 2, 3 };
- var productIdsForVerify = await context.ContractProducts.Where(cp => cp.ContractProductReportingId >= 2 && cp.ContractProductReportingId <= 3).Select(cp => cp.ContractProductId).ToListAsync(CancellationToken.None);
-
- string serializedArray = string.Join(",", productFilterList);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetProductPerformance(string.Empty, this.TestId, comparisonDate, productFilterList, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => productIdsForVerify.Contains(c.ContractProductId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => productIdsForVerify.Contains(c.ContractProductId)).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => productIdsForVerify.Contains(c.ContractProductId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => productIdsForVerify.Contains(c.ContractProductId)).Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomProductsByValue_BottomProducts_ProductsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- var merchant = merchantsList.First();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
-
- Dictionary transactionCounts = new() {
- { "200 KES Topup", 25 }, //5000
- { "100 KES Topup", 15 }, // 1500
- { "50 KES Topup", 45 }, // 2250
- { "Custom", 8 } // 600
- };
- Dictionary> transactionsDictionary = new();
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(product.productName) == false) {
- transactionsDictionary.Add(product.productName, new List());
- }
-
- transactionsDictionary[product.productName].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t => t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTopBottomProductData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Bottom, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomProductData = result.Data;
-
- topBottomProductData[0].ProductName.ShouldBe("Custom");
- topBottomProductData[0].SalesValue.ShouldBe(transactionsDictionary["Custom"].Sum(p => p.TransactionAmount));
- topBottomProductData[1].ProductName.ShouldBe("100 KES Topup");
- topBottomProductData[1].SalesValue.ShouldBe(transactionsDictionary["100 KES Topup"].Sum(p => p.TransactionAmount));
- topBottomProductData[2].ProductName.ShouldBe("50 KES Topup");
- topBottomProductData[2].SalesValue.ShouldBe(transactionsDictionary["50 KES Topup"].Sum(p => p.TransactionAmount));
- }
-
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomProductsByValue_TopProducts_ProductsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- var merchant = merchantsList.First();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
-
- Dictionary transactionCounts = new() {
- { "200 KES Topup", 25 }, //5000
- { "100 KES Topup", 15 }, // 1500
- { "50 KES Topup", 45 }, // 2250
- { "Custom", 8 } // 600
- };
-
- Dictionary> transactionsDictionary = new();
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
-
- int transactionCount = transactionCounts.Single(m => m.Key == product.productName).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(product.productName) == false) {
- transactionsDictionary.Add(product.productName, new List());
- }
-
- transactionsDictionary[product.productName].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t => t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTopBottomProductData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Top, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomProductData = result.Data;
- topBottomProductData[0].ProductName.ShouldBe("200 KES Topup");
- topBottomProductData[0].SalesValue.ShouldBe(transactionsDictionary["200 KES Topup"].Sum(p => p.TransactionAmount));
- topBottomProductData[1].ProductName.ShouldBe("50 KES Topup");
- topBottomProductData[1].SalesValue.ShouldBe(transactionsDictionary["50 KES Topup"].Sum(p => p.TransactionAmount));
- topBottomProductData[2].ProductName.ShouldBe("100 KES Topup");
- topBottomProductData[2].SalesValue.ShouldBe(transactionsDictionary["100 KES Topup"].Sum(p => p.TransactionAmount));
- }
- }
-
- public class FactTransactionsControllerTests_MerchantsTests : FactTransactionsControllerTestsBase {
-
- public FactTransactionsControllerTests_MerchantsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) {
-
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_GetMerchantsByLastDaleDate_MerchantsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- await ClearStandingData();
-
- // Last Hour
- await helper.AddMerchant("Test Estate", "Merchant 1", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 2", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 3", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 4", todaysDateTime);
-
- // Yesterday
- await helper.AddMerchant("Test Estate", "Merchant 5", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 6", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 7", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 8", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 9", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 10", todaysDateTime.AddDays(-1));
-
- // 5 days ago
- await helper.AddMerchant("Test Estate", "Merchant 11", todaysDateTime.AddDays(-5));
- await helper.AddMerchant("Test Estate", "Merchant 12", todaysDateTime.AddDays(-5));
- await helper.AddMerchant("Test Estate", "Merchant 13", todaysDateTime.AddDays(-5));
-
- // 10 Days Ago
- await helper.AddMerchant("Test Estate", "Merchant 14", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 15", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 16", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 17", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 18", todaysDateTime.AddDays(-10));
-
- DateTime startDate = DateTime.Now;
- DateTime endDate = DateTime.Now;
-
- // Test 1 - sale in last hour
- startDate = DateTime.Now.AddHours(-1);
- endDate = DateTime.Now;
- var result = await this.ApiClient.GetMerchantsByLastSaleDate(String.Empty, this.TestId, startDate, endDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var searchResult = result.Data;
- searchResult.ShouldNotBeNull();
- searchResult.Count.ShouldBe(4);
- searchResult.SingleOrDefault(s => s.Name == "Merchant 1").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 2").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 3").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 4").ShouldNotBeNull();
-
- // Test 2 - sale in last day but over an hour ago
- startDate = DateTime.Now.Date.AddDays(-1);
- endDate = DateTime.Now.AddHours(-1);
- result = await this.ApiClient.GetMerchantsByLastSaleDate(String.Empty, this.TestId, startDate, endDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.ShouldNotBeNull();
- searchResult.Count.ShouldBe(6);
- searchResult.SingleOrDefault(s => s.Name == "Merchant 5").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 6").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 7").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 8").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 9").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 10").ShouldNotBeNull();
-
- // Test 3 - sale in last 7 days but non yesterday
- startDate = DateTime.Now.Date.AddDays(-7);
- endDate = DateTime.Now.Date.AddDays(-1);
- result = await this.ApiClient.GetMerchantsByLastSaleDate(String.Empty, this.TestId, startDate, endDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.ShouldNotBeNull();
- searchResult.Count.ShouldBe(3);
- searchResult.SingleOrDefault(s => s.Name == "Merchant 11").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 12").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 13").ShouldNotBeNull();
-
- // Test 4 - sale more than 7 days ago
- startDate = DateTime.Now.Date.AddYears(-1);
- endDate = DateTime.Now.Date.AddDays(-7);
- result = await this.ApiClient.GetMerchantsByLastSaleDate(String.Empty, this.TestId, startDate, endDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.ShouldNotBeNull();
- searchResult.Count.ShouldBe(5);
- searchResult.SingleOrDefault(s => s.Name == "Merchant 14").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 15").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 16").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 17").ShouldNotBeNull();
- searchResult.SingleOrDefault(s => s.Name == "Merchant 18").ShouldNotBeNull();
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_GetMerchantsTransactionKpis_SalesReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- await ClearStandingData();
-
- // Last Hour
- await helper.AddMerchant("Test Estate", "Merchant 1", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 2", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 3", todaysDateTime);
- await helper.AddMerchant("Test Estate", "Merchant 4", todaysDateTime);
-
- // Yesterday
- await helper.AddMerchant("Test Estate", "Merchant 5", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 6", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 7", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 8", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 9", todaysDateTime.AddDays(-1));
- await helper.AddMerchant("Test Estate", "Merchant 10", todaysDateTime.AddDays(-1));
-
- // 10 Days Ago
- await helper.AddMerchant("Test Estate", "Merchant 11", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 12", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 13", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 14", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 15", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 16", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 17", todaysDateTime.AddDays(-10));
- await helper.AddMerchant("Test Estate", "Merchant 18", todaysDateTime.AddDays(-10));
-
- var result = await ApiClient.GetMerchantKpi(string.Empty, this.TestId, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.MerchantKpi? merchantKpi = result.Data;
- merchantKpi.ShouldNotBeNull();
- merchantKpi.MerchantsWithSaleInLastHour.ShouldBe(4);
- merchantKpi.MerchantsWithNoSaleToday.ShouldBe(6);
- merchantKpi.MerchantsWithNoSaleInLast7Days.ShouldBe(8);
- }
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomMerchantsByValue_BottomMerchants_MerchantsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 25 }, { "Test Merchant 2", 15 }, { "Test Merchant 3", 45 }, { "Test Merchant 4", 8 } };
-
- Dictionary> transactionsDictionary = new();
- foreach (KeyValuePair transactionCount in transactionCounts) {
- var merchant = merchantsList.Where(m => m.Name == transactionCount.Key).Single();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- var product = contractProducts.Single(cp => cp.Key == contract.contractId).Value.First();
- for (int i = 0; i < transactionCount.Value; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.Item1, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(transactionCount.Key) == false) {
- transactionsDictionary.Add(transactionCount.Key, new List());
- }
-
- transactionsDictionary[transactionCount.Key].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t => t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTopBottomMerchantData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Bottom, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomMerchantData = result.Data;
- topBottomMerchantData.ShouldNotBeNull();
- topBottomMerchantData[0].MerchantName.ShouldBe("Test Merchant 4");
- topBottomMerchantData[0].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 4"].Sum(p => p.TransactionAmount));
- topBottomMerchantData[1].MerchantName.ShouldBe("Test Merchant 2");
- topBottomMerchantData[1].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 2"].Sum(p => p.TransactionAmount));
- topBottomMerchantData[2].MerchantName.ShouldBe("Test Merchant 1");
- topBottomMerchantData[2].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 1"].Sum(p => p.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsController_GetTopBottomMerchantsByValue_TopMerchants_MerchantsReturned() {
- DateTime todaysDateTime = DateTime.Now;
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 25 }, { "Test Merchant 2", 15 }, { "Test Merchant 3", 45 }, { "Test Merchant 4", 8 } };
-
- Dictionary> transactionsDictionary = new();
- foreach (KeyValuePair transactionCount in transactionCounts) {
- var merchant = merchantsList.Where(m => m.Name == transactionCount.Key).Single();
- var contract = this.contractList.Single(c => c.operatorName == "Safaricom");
- (Guid productId, String productName, Decimal? productValue) product = contractProducts.Single(cp => cp.Key == contract.contractId).Value.First();
- for (int i = 0; i < transactionCount.Value; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- if (transactionsDictionary.ContainsKey(transactionCount.Key) == false) {
- transactionsDictionary.Add(transactionCount.Key, new List());
- }
-
- transactionsDictionary[transactionCount.Key].Add(transaction);
- }
- }
-
- await this.helper.AddTransactionsX(transactionsDictionary.Values.SelectMany(t => t).ToList());
-
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
- var result = await ApiClient.GetTopBottomMerchantData(string.Empty, this.TestId, DataTransferObjects.TopBottom.Top, 3, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? topBottomMerchantData = result.Data;
- topBottomMerchantData.ShouldNotBeNull();
- topBottomMerchantData[0].MerchantName.ShouldBe("Test Merchant 3");
- topBottomMerchantData[0].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 3"].Sum(p => p.TransactionAmount));
- topBottomMerchantData[1].MerchantName.ShouldBe("Test Merchant 1");
- topBottomMerchantData[1].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 1"].Sum(p => p.TransactionAmount));
- topBottomMerchantData[2].MerchantName.ShouldBe("Test Merchant 2");
- topBottomMerchantData[2].SalesValue.ShouldBe(transactionsDictionary["Test Merchant 2"].Sum(p => p.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_MerchantPerformance_AllMerchants_SalesReturned() {
-
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() {
- { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 3 },
- };
-
- // Todays sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- // Comparison Date sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetMerchantPerformance(string.Empty, this.TestId, comparisonDate, new List(), CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_MerchantPerformance_SingleMerchant_SalesReturned() {
-
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() {
- { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 3 },
- };
-
- // Todays sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- // Comparison Date sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- List merchantFilterList = new List { 2 };
-
- var merchantIdsForVerify = await this.context.Merchants.Where(m => m.MerchantReportingId == 2).Select(m => m.MerchantId).ToListAsync(CancellationToken.None);
-
- string serializedArray = string.Join(",", merchantFilterList);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetMerchantPerformance(string.Empty, this.TestId, comparisonDate, merchantFilterList, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => merchantIdsForVerify.Contains(c.MerchantId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => merchantIdsForVerify.Contains(c.MerchantId)).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => merchantIdsForVerify.Contains(c.MerchantId)));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => merchantIdsForVerify.Contains(c.MerchantId)).Sum(c => c.TransactionAmount));
- }
-
- }
-
- public class FactTransactionsControllerTests_SalesTests : FactTransactionsControllerTestsBase {
-
- public FactTransactionsControllerTests_SalesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) {
-
- }
-
- #region Todays Sales Tests
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysSales_SalesReturned() {
- List? todaysTransactions = new List();
- List comparisonDateTransactions = new List();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
-
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- // Comparison Date sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTodaysSales(string.Empty, this.TestId, 0, 0, comparisonDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSales = result.Data;
-
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysSales_OperatorFilter_SalesReturned() {
- List todaysTransactions = new();
- List comparisonDateTransactions = new();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
-
- // Todays sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- // Comparison Date sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTodaysSales(string.Empty, this.TestId, 0, 1, comparisonDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSales = result.Data;
-
- todaysSales.ShouldNotBeNull();
-
- var operatorId = await this.helper.GetOperatorId(1, CancellationToken.None);
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => c.OperatorId == operatorId));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => c.OperatorId == operatorId).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => c.OperatorId == operatorId));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => c.OperatorId == operatorId).Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysSales_MerchantFilter_SalesReturned() {
- List todaysTransactions = new();
- List comparisonDateTransactions = new();
-
- DateTime todaysDateTime = DateTime.Now;
- DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };
-
-
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
-
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTodaysSales(string.Empty, this.TestId, 1, 0, comparisonDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSales = result.Data;
-
- todaysSales.ShouldNotBeNull();
-
- var merchantId = await this.helper.GetMerchantId(1, CancellationToken.None);
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count(c => c.MerchantId == merchantId));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => c.MerchantId == merchantId).Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count(c => c.MerchantId == merchantId));
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Where(c => c.MerchantId == merchantId).Sum(c => c.TransactionAmount));
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysSalesCountByHour_SalesReturned() {
- Stopwatch sw = Stopwatch.StartNew();
-
- List todaysTransactions = new List();
- List comparisonDateTransactions = new List();
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 3 }, { "Test Merchant 2", 6 }, { "Test Merchant 3", 2 }, { "Test Merchant 4", 0 } };
-
- // TODO: make counts dynamic
- DateTime todaysDateTime = DateTime.Now;
-
- for (int hour = 0; hour < 24; hour++) {
- List localList = new List();
- DateTime date = new DateTime(todaysDateTime.Year, todaysDateTime.Month, todaysDateTime.Day, hour, 0, 0);
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- todaysTransactions.AddRange(localList);
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Todays Txns {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- DateTime comparisonDate = todaysDateTime.AddDays(-1);
- for (int hour = 0; hour < 24; hour++) {
- List localList = new List();
- DateTime date = new DateTime(comparisonDate.Year, comparisonDate.Month, comparisonDate.Day, hour, 0, 0);
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- comparisonDateTransactions.AddRange(localList);
-
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Comparison txns {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- sw.Stop();
- this.TestOutputHelper.WriteLine($"Setup Summaries {sw.ElapsedMilliseconds}ms");
- sw.Restart();
-
- var result = await ApiClient.GetTodaysSalesCountByHour(string.Empty, this.TestId, 0, 0, comparisonDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var todaysSalesCountByHour = result.Data;
-
- todaysSalesCountByHour.ShouldNotBeNull();
- foreach (DataTransferObjects.TodaysSalesCountByHour salesCountByHour in todaysSalesCountByHour) {
- IEnumerable todayHour = todaysTransactions.Where(t => t.TransactionDateTime.Hour == salesCountByHour.Hour);
- IEnumerable comparisonHour = comparisonDateTransactions.Where(t => t.TransactionDateTime.Hour == salesCountByHour.Hour);
- salesCountByHour.ComparisonSalesCount.ShouldBe(comparisonHour.Count());
- salesCountByHour.TodaysSalesCount.ShouldBe(todayHour.Count());
- }
- }
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysSalesValueByHour_SalesReturned() {
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 3 }, { "Test Merchant 2", 6 }, { "Test Merchant 3", 2 }, { "Test Merchant 4", 0 } };
-
- DateTime todaysDateTime = DateTime.Now;
-
- for (int hour = 0; hour < 24; hour++) {
- DateTime date = new DateTime(todaysDateTime.Year, todaysDateTime.Month, todaysDateTime.Day, hour, 0, 0);
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(todaysTransactions);
-
- DateTime comparisonDate = todaysDateTime.AddDays(-1);
- for (int hour = 0; hour < 24; hour++) {
- DateTime date = new DateTime(comparisonDate.Year, comparisonDate.Month, comparisonDate.Day, hour, 0, 0);
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
- }
-
- await this.helper.AddTransactionsX(comparisonDateTransactions);
-
- await helper.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTodaysSalesValueByHour(string.Empty, this.TestId, 0, 0, comparisonDate, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List? todaysSalesValueByHour = result.Data;
- foreach (DataTransferObjects.TodaysSalesValueByHour salesValueByHour in todaysSalesValueByHour) {
- IEnumerable todayHour = todaysTransactions.Where(t => t.TransactionDateTime.Hour == salesValueByHour.Hour);
- IEnumerable comparisonHour = comparisonDateTransactions.Where(t => t.TransactionDateTime.Hour == salesValueByHour.Hour);
- salesValueByHour.ComparisonSalesValue.ShouldBe(comparisonHour.Sum(c => c.TransactionAmount));
- salesValueByHour.TodaysSalesValue.ShouldBe(todayHour.Sum(c => c.TransactionAmount));
- }
- }
-
- #endregion
-
-
- [Fact]
- public async Task FactTransactionsControllerController_TodaysFailedSales_SalesReturned() {
-
- EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{TestId.ToString()}"));
- var todaysTransactions = new List();
- var comparisonDateTransactions = new List();
- DatabaseHelper helper1 = new DatabaseHelper(context);
- // TODO: make counts dynamic
- DateTime todaysDateTime = DateTime.Now;
- //todaysDateTime = todaysDateTime.AddHours(12).AddMinutes(30);
-
- Dictionary transactionCounts = new() { { "Test Merchant 1", 3 }, { "Test Merchant 2", 6 }, { "Test Merchant 3", 2 }, { "Test Merchant 4", 0 } };
-
- DateTime comparisonDate = todaysDateTime.AddDays(-1);
-
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper1.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "1009", product.productValue);
- todaysTransactions.Add(transaction);
- }
- }
- }
- }
-
- await helper1.AddTransactionsX(todaysTransactions);
-
- // Comparison Date sales
- foreach (var merchant in merchantsList) {
- foreach (var contract in contractList) {
- var productList = contractProducts.Single(cp => cp.Key == contract.contractId).Value;
- foreach ((Guid productId, String productName, Decimal? productValue) product in productList) {
- var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value;
- for (int i = 0; i < transactionCount; i++) {
- Transaction transaction = await helper1.BuildTransactionX(comparisonDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "1009", product.productValue);
- comparisonDateTransactions.Add(transaction);
- }
- }
- }
- }
-
- await helper1.AddTransactionsX(comparisonDateTransactions);
-
-
- await helper1.RunTodaysTransactionsSummaryProcessing(comparisonDate.Date);
- await helper1.RunHistoricTransactionsSummaryProcessing(comparisonDate.Date);
- await helper1.RunTodaysTransactionsSummaryProcessing(todaysDateTime.Date);
-
- var result = await ApiClient.GetTodaysFailedSales(string.Empty, this.TestId, 1, 1, "1009", comparisonDate.Date, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- DataTransferObjects.TodaysSales? todaysSales = result.Data;
-
- todaysSales.ShouldNotBeNull();
- todaysSales.ComparisonSalesCount.ShouldBe(comparisonDateTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
-
- todaysSales.TodaysSalesCount.ShouldBe(todaysTransactions.Count);
- todaysSales.ComparisonSalesValue.ShouldBe(comparisonDateTransactions.Sum(c => c.TransactionAmount));
- }
-
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_NoAdditionalFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- (Guid productId, String productName, Decimal? productValue) product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- // Add some transactions
- List transactions = new List();
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, transactionAmount: product.productValue));
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate };
-
- // No Paging or Sorting
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var searchResult = result.Data;
- searchResult.Count.ShouldBe(10);
- searchResult.Any(s => s.TransactionReportingId == 1).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 3).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 5).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 7).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 8).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 9).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
-
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 1, 5, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(5);
- searchResult.Any(s => s.TransactionReportingId == 1).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 3).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 5).ShouldBeTrue();
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 2, 5, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(5);
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 7).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 8).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 9).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_ValueRangeFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
-
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "Custom").Single();
-
- // Add some transactions
- List transactions = new List();
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, transactionAmount: 50));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, transactionAmount: 123));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, transactionAmount: 100));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, transactionAmount: 101));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, transactionAmount: 199));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, transactionAmount: 150));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, transactionAmount: 200));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, transactionAmount: 201));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, transactionAmount: 99));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, transactionAmount: 111));
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, ValueRange = new() { StartValue = 100, EndValue = 200 } };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
- searchResult.Count.ShouldBe(7);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 3).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 5).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 7).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 1, 3, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 3).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 2, 3, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 5).ShouldBeTrue();
-
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_AuthCodeFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- List transactions = new List();
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, authCode: "AUTH1232", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH1233", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, authCode: "AUTH1234", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, authCode: "AUTH1235", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, authCode: "AUTH1236", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, authCode: "AUTH1237", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, authCode: "AUTH1228", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, authCode: "AUTH1229", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, authCode: "AUTH1123", transactionAmount: product.productValue));
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, AuthCode = "AUTH1235" };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
- searchResult.Count.ShouldBe(1);
- searchResult.Any(s => s.TransactionReportingId == 5).ShouldBeTrue();
- }
-
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_TransactionNumberFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
-
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- List transactions = new List();
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, authCode: "AUTH1232", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH1233", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, authCode: "AUTH1234", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, authCode: "AUTH1235", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, authCode: "AUTH1236", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, authCode: "AUTH1237", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, authCode: "AUTH1228", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, authCode: "AUTH1229", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, authCode: "AUTH1123", transactionAmount: product.productValue));
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, TransactionNumber = "0004" };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
-
- searchResult.Count.ShouldBe(1);
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_ResponseCodeFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- List transactions = new List();
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0001", transactionReportingId: 2, authCode: "AUTH1232", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH1233", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0001", transactionReportingId: 4, authCode: "AUTH1234", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, authCode: "AUTH1235", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0001", transactionReportingId: 6, authCode: "AUTH1236", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, authCode: "AUTH1237", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0001", transactionReportingId: 8, authCode: "AUTH1228", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, authCode: "AUTH1229", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0001", transactionReportingId: 10, authCode: "AUTH1123", transactionAmount: product.productValue));
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, ResponseCode = "0001" };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
- searchResult.Count.ShouldBe(5);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 8).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 1, 3, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 4).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 2, 3, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(2);
- searchResult.Any(s => s.TransactionReportingId == 8).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_MerchantFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
-
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- List transactions = new List();
-
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, authCode: "AUTH231", transactionAmount: product.productValue));
-
- merchant = merchantsList.Single(m => m.Name == "Test Merchant 2");
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 11, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 12, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 13, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 14, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 15, authCode: "AUTH231", transactionAmount: product.productValue));
-
- merchant = merchantsList.Single(m => m.Name == "Test Merchant 3");
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 16, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 17, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 18, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 19, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 20, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 21, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 22, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 23, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 24, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 25, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 26, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 27, authCode: "AUTH231", transactionAmount: product.productValue));
-
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, Merchants = new List() { 2, 3 } };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
-
- searchResult.Count.ShouldBe(10);
- searchResult.Any(s => s.TransactionReportingId == 11).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 12).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 13).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 14).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 15).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 16).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 17).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 18).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 19).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 20).ShouldBeTrue();
- searchResult.Count(s => s.MerchantName == "Test Merchant 2").ShouldBe(5);
- searchResult.Count(s => s.MerchantName == "Test Merchant 3").ShouldBe(5);
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 1, 5, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
-
- searchResult.Count.ShouldBe(5);
- searchResult.Any(s => s.TransactionReportingId == 11).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 12).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 13).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 14).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 15).ShouldBeTrue();
- searchResult.Count(s => s.MerchantName == "Test Merchant 2").ShouldBe(5);
- searchResult.Count(s => s.MerchantName == "Test Merchant 3").ShouldBe(0);
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 2, 5, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
-
- searchResult.Count.ShouldBe(5);
- searchResult.Any(s => s.TransactionReportingId == 16).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 17).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 18).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 19).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 20).ShouldBeTrue();
- searchResult.Count(s => s.MerchantName == "Test Merchant 2").ShouldBe(0);
- searchResult.Count(s => s.MerchantName == "Test Merchant 3").ShouldBe(5);
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_OperatorFiltering_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
-
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "200 KES Topup").Single();
-
- List transactions = new List();
-
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 4, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 5, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 7, authCode: "AUTH231", transactionAmount: product.productValue));
-
- contract = contractList.Single(c => c.operatorName == "Voucher");
- contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- product = contractProducts.First().Value.Where(x => x.productName == "10 KES Voucher").Single();
-
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 6, authCode: "AUTH231", transactionAmount: product.productValue));
-
- contract = contractList.Single(c => c.operatorName == "PataPawa PostPay");
- contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- product = contractProducts.First().Value.Where(x => x.productName == "Post Pay Bill Pay").Single();
-
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 8, authCode: "AUTH231", transactionAmount: product.productValue));
-
- contract = contractList.Single(c => c.operatorName == "PataPawa PrePay");
- contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- product = contractProducts.First().Value.Where(x => x.productName == "Pre Pay Bill Pay").Single();
-
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 9, authCode: "AUTH231", transactionAmount: product.productValue));
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 10, authCode: "AUTH231", transactionAmount: product.productValue));
-
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate, Operators = new List() { 2, 4 } };
-
- // No Paging
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- List searchResult = result.Data;
- searchResult.Count.ShouldBe(4);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 9).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
- searchResult.Count(s => s.OperatorName == "Voucher").ShouldBe(2);
- searchResult.Count(s => s.OperatorName == "PataPawa PrePay").ShouldBe(2);
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 1, 2, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(2);
- searchResult.Any(s => s.TransactionReportingId == 2).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 6).ShouldBeTrue();
- searchResult.Count(s => s.OperatorName == "Voucher").ShouldBe(2);
- searchResult.Count(s => s.OperatorName == "PataPawa PrePay").ShouldBe(0);
-
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, 2, 2, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(2);
- searchResult.Any(s => s.TransactionReportingId == 9).ShouldBeTrue();
- searchResult.Any(s => s.TransactionReportingId == 10).ShouldBeTrue();
- searchResult.Count(s => s.OperatorName == "Voucher").ShouldBe(0);
- searchResult.Count(s => s.OperatorName == "PataPawa PrePay").ShouldBe(2);
- }
-
- [Fact]
- public async Task FactTransactionsController_TransactionSearch_SortingTest_TransactionReturned() {
-
- DateTime transactionDate = new DateTime(2024, 3, 19);
-
- var merchant = merchantsList.Single(m => m.Name == "Test Merchant 1");
- var contract = contractList.Single(c => c.operatorName == "Safaricom");
- var contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- var product = contractProducts.First().Value.Where(x => x.productName == "Custom").Single();
-
- List transactions = new List();
- // Add some transactions
- //await helper.AddTransaction(transactionDate, "Test Merchant 1", "Safaricom Contract", "Custom", "0000", transactionAmount: 100);
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 1, authCode: "AUTH231", transactionAmount: 100));
-
- merchant = merchantsList.Single(m => m.Name == "Test Merchant 2");
- contract = contractList.Single(c => c.operatorName == "Voucher");
- contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- product = contractProducts.First().Value.Where(x => x.productName == "Custom").Single();
-
- //await helper.AddTransaction(transactionDate, "Test Merchant 2", "Healthcare Centre 1 Contract", "Custom", "0000", transactionAmount: 200);
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 2, authCode: "AUTH231", transactionAmount: 200));
-
- merchant = merchantsList.Single(m => m.Name == "Test Merchant 3");
- contract = contractList.Single(c => c.operatorName == "PataPawa PostPay");
- contractProducts = this.contractProducts.Where(cp => cp.Key == contract.contractId);
- product = contractProducts.First().Value.Where(x => x.productName == "Post Pay Bill Pay").Single();
-
- //await helper.AddTransaction(transactionDate, "Test Merchant 3", "PataPawa PostPay Contract", "Post Pay Bill Pay", "0000", transactionAmount: 300);
- transactions.Add(await helper.BuildTransactionX(transactionDate, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", transactionReportingId: 3, authCode: "AUTH231", transactionAmount: 300));
-
- await this.helper.AddTransactionsX(transactions);
-
- DataTransferObjects.TransactionSearchRequest searchRequest = new() { QueryDate = transactionDate };
- // Default Sort
- var result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, null, null, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- var searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].TransactionAmount.ShouldBe(100);
- searchResult[1].TransactionAmount.ShouldBe(200);
- searchResult[2].TransactionAmount.ShouldBe(300);
-
- // Sort By merchant Name ascending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.MerchantName, SortDirection.Ascending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].MerchantName.ShouldBe("Test Merchant 1");
- searchResult[1].MerchantName.ShouldBe("Test Merchant 2");
- searchResult[2].MerchantName.ShouldBe("Test Merchant 3");
-
- // Sort By merchant Name descending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.MerchantName, SortDirection.Descending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].MerchantName.ShouldBe("Test Merchant 3");
- searchResult[1].MerchantName.ShouldBe("Test Merchant 2");
- searchResult[2].MerchantName.ShouldBe("Test Merchant 1");
-
- // Sort By operator Name ascending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.OperatorName, SortDirection.Ascending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
-
- searchResult.Count.ShouldBe(3);
- searchResult[0].OperatorName.ShouldBe("PataPawa PostPay");
- searchResult[1].OperatorName.ShouldBe("Safaricom");
- searchResult[2].OperatorName.ShouldBe("Voucher");
-
- // Sort By operator Name descending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.OperatorName, SortDirection.Descending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].OperatorName.ShouldBe("Voucher");
- searchResult[1].OperatorName.ShouldBe("Safaricom");
- searchResult[2].OperatorName.ShouldBe("PataPawa PostPay");
-
- // Sort By transaction amount ascending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.TransactionAmount, SortDirection.Ascending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].TransactionAmount.ShouldBe(100);
- searchResult[1].TransactionAmount.ShouldBe(200);
- searchResult[2].TransactionAmount.ShouldBe(300);
-
- // Sort By transaction amount descending
- result = await ApiClient.TransactionSearch(string.Empty, this.TestId, searchRequest, null, null, DataTransferObjects.SortField.TransactionAmount, SortDirection.Descending, CancellationToken.None);
- result.IsSuccess.ShouldBeTrue();
- searchResult = result.Data;
- searchResult.Count.ShouldBe(3);
- searchResult[0].TransactionAmount.ShouldBe(300);
- searchResult[1].TransactionAmount.ShouldBe(200);
- searchResult[2].TransactionAmount.ShouldBe(100);
- }
- }*/
diff --git a/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs b/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs
index 761aded..dc48531 100644
--- a/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs
+++ b/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs
@@ -145,6 +145,74 @@ public async Task MerchantEndpoint_GetMerchantDevices_MerchantDevicesReturned()
merchantDevices.SingleOrDefault(m => m.DeviceIdentifier == "123456").ShouldNotBeNull();
}
+ [Fact]
+ public async Task MerchantEndpoint_GetMerchantOpeningHours_MerchantOpeningHoursReturned()
+ {
+ await this.helper.AddEstate("Test Estate", "Ref1");
+
+ Dictionary openingHours = new();
+ openingHours.Add(DayOfWeek.Monday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Monday, OpeningTime = "09:00", ClosingTime = "17:00" });
+ openingHours.Add(DayOfWeek.Tuesday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Tuesday, OpeningTime = "09:00", ClosingTime = "17:00" });
+ openingHours.Add(DayOfWeek.Wednesday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Wednesday, OpeningTime = "09:00", ClosingTime = "17:00" });
+ openingHours.Add(DayOfWeek.Thursday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Thursday, OpeningTime = "09:00", ClosingTime = "17:00" });
+ openingHours.Add(DayOfWeek.Friday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Friday, OpeningTime = "09:00", ClosingTime = "17:00" });
+ openingHours.Add(DayOfWeek.Saturday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Saturday, OpeningTime = "10:00", ClosingTime = "16:00" });
+ openingHours.Add(DayOfWeek.Sunday, new Models.MerchantOpeningHour() { DayOfWeek = DayOfWeek.Sunday, OpeningTime = "09:00", ClosingTime = "18:00" });
+
+ var merchantId = await this.helper.AddMerchant("Test Estate", $"Test Merchant 1", 100, DateTime.Now, DateTime.Now,
+ ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
+ ("Contact 1", "1@2.com", "123456"), devices: ["123456"],
+ openingHours:openingHours);
+
+ Result> result = await this.CreateAndSendHttpRequestMessage>($"{this.BaseRoute}/{merchantId}/openinghours", CancellationToken.None);
+ result.IsSuccess.ShouldBeTrue();
+ var merchantOpeningHours = result.Data;
+
+ merchantOpeningHours.ShouldNotBeNull();
+ merchantOpeningHours.Count.ShouldBe(7);
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Monday && m.OpeningTime == "09:00" && m.ClosingTime == "17:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Tuesday && m.OpeningTime == "09:00" && m.ClosingTime == "17:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Wednesday && m.OpeningTime == "09:00" && m.ClosingTime == "17:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Thursday && m.OpeningTime == "09:00" && m.ClosingTime == "17:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Friday && m.OpeningTime == "09:00" && m.ClosingTime == "17:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Saturday && m.OpeningTime == "10:00" && m.ClosingTime == "16:00").ShouldNotBeNull();
+ merchantOpeningHours.SingleOrDefault(m => m.DayOfWeek == DayOfWeek.Sunday && m.OpeningTime == "09:00" && m.ClosingTime == "18:00").ShouldNotBeNull();
+ }
+
+ [Fact]
+ public async Task MerchantEndpoint_GetMerchantSchedule_MerchantScheduleReturned()
+ {
+ await this.helper.AddEstate("Test Estate", "Ref1");
+
+ var merchantId = await this.helper.AddMerchant("Test Estate", $"Test Merchant 1", 100, DateTime.Now, DateTime.Now,
+ ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"),
+ ("Contact 1", "1@2.com", "123456"), devices: ["123456"]);
+
+ Result result = await this.CreateAndSendHttpRequestMessage($"{this.BaseRoute}/{merchantId}/schedule/2026", CancellationToken.None);
+ result.IsSuccess.ShouldBeTrue();
+ var merchantSchedule = result.Data;
+
+ merchantSchedule.ShouldNotBeNull();
+ merchantSchedule.Year.ShouldBe(2026);
+ merchantSchedule.Months.ShouldNotBeNull();
+ merchantSchedule.Months.Count.ShouldBe(3);
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 1).ShouldNotBeNull();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 1).ClosedDays.Contains(1).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 1).ClosedDays.Contains(2).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 1).ClosedDays.Contains(15).ShouldBeTrue();
+
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 2).ShouldNotBeNull();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 2).ClosedDays.Contains(10).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 2).ClosedDays.Contains(14).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 2).ClosedDays.Contains(28).ShouldBeTrue();
+
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 12).ShouldNotBeNull();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 12).ClosedDays.Contains(24).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 12).ClosedDays.Contains(25).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 12).ClosedDays.Contains(26).ShouldBeTrue();
+ merchantSchedule.Months.SingleOrDefault(m => m.Month == 12).ClosedDays.Contains(31).ShouldBeTrue();
+ }
+
[Fact]
public async Task MerchantEndpoint_GetMerchantKpis_MerchantKpisReturned()
{
diff --git a/EstateReportingAPI.Models/MerchantOpeningHour.cs b/EstateReportingAPI.Models/MerchantOpeningHour.cs
new file mode 100644
index 0000000..1f146ef
--- /dev/null
+++ b/EstateReportingAPI.Models/MerchantOpeningHour.cs
@@ -0,0 +1,24 @@
+namespace EstateReportingAPI.Models;
+
+public class MerchantOpeningHour
+{
+ public Guid MerchantId { get; set; }
+ public DayOfWeek DayOfWeek { get; set; }
+ public String OpeningTime { get; set; }
+ public String ClosingTime { get; set; }
+}
+
+public class MerchantScheduleResponse {
+ public MerchantScheduleResponse() {
+ this.Months = new List();
+ }
+ public int Year { get; set; }
+
+ public List Months { get; set; }
+}
+
+public class MerchantScheduleMonthResponse {
+ public int Month { get; set; }
+
+ public List ClosedDays { get; set; }
+}
\ No newline at end of file
diff --git a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj
index a4ea6d0..af856ae 100644
--- a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj
+++ b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj
@@ -20,7 +20,7 @@
-
+
all
diff --git a/EstateReportingAPI/Endpoints/MerchantEndpoints.cs b/EstateReportingAPI/Endpoints/MerchantEndpoints.cs
index 99a1bb0..58ccb13 100644
--- a/EstateReportingAPI/Endpoints/MerchantEndpoints.cs
+++ b/EstateReportingAPI/Endpoints/MerchantEndpoints.cs
@@ -29,10 +29,14 @@ public static void MapMerchantEndpoints(this IEndpointRouteBuilder app)
group.MapGet("/{merchantId}", MerchantHandler.GetMerchant)
.WithStandardProduces();
group.MapGet("/{merchantId}/operators", MerchantHandler.GetMerchantOperators)
- .WithStandardProduces();
+ .WithStandardProduces>();
group.MapGet("/{merchantId}/contracts", MerchantHandler.GetMerchantContracts)
- .WithStandardProduces();
+ .WithStandardProduces>();
group.MapGet("/{merchantId}/devices", MerchantHandler.GetMerchantDevices)
- .WithStandardProduces();
+ .WithStandardProduces>();
+ group.MapGet("/{merchantId}/openinghours", MerchantHandler.GetMerchantOpeningHours)
+ .WithStandardProduces>();
+ group.MapGet("/{merchantId}/schedule/{year}", MerchantHandler.GetMerchantSchedule)
+ .WithStandardProduces();
}
}
\ No newline at end of file
diff --git a/EstateReportingAPI/EstateReportingAPI.csproj b/EstateReportingAPI/EstateReportingAPI.csproj
index 1da2b45..fd6c2fc 100644
--- a/EstateReportingAPI/EstateReportingAPI.csproj
+++ b/EstateReportingAPI/EstateReportingAPI.csproj
@@ -37,7 +37,7 @@
-
+
diff --git a/EstateReportingAPI/Handlers/MerchantHandler.cs b/EstateReportingAPI/Handlers/MerchantHandler.cs
index 910359c..54f85cb 100644
--- a/EstateReportingAPI/Handlers/MerchantHandler.cs
+++ b/EstateReportingAPI/Handlers/MerchantHandler.cs
@@ -135,6 +135,8 @@ public static async Task GetMerchantOperators([FromHeader] Guid estateI
}).ToList());
}
+
+
public static async Task GetMerchantContracts([FromHeader] Guid estateId,
[FromRoute] Guid merchantId,
IMediator mediator,
@@ -177,4 +179,37 @@ public static async Task GetMerchantDevices([FromHeader] Guid estateId,
DeviceIdentifier = c.DeviceIdentifier
}).ToList());
}
+
+ public static async Task GetMerchantOpeningHours([FromHeader] Guid estateId,
+ [FromRoute] Guid merchantId,
+ IMediator mediator,
+ CancellationToken cancellationToken) {
+ MerchantQueries.GetMerchantOpeningHoursQuery query = new(estateId, merchantId);
+ Result> result = await mediator.Send(query, cancellationToken);
+
+ return ResponseFactory.FromResult(result, r => r.Select(c => new DataTransferObjects.MerchantOpeningHour()
+ {
+ MerchantId = c.MerchantId,
+ DayOfWeek = c.DayOfWeek,
+ OpeningTime = c.OpeningTime,
+ ClosingTime = c.ClosingTime
+ }).ToList());
+ }
+
+ public static async Task GetMerchantSchedule([FromHeader] Guid estateId,
+ [FromRoute] Guid merchantId,
+ [FromRoute] Int32 year,
+ IMediator mediator,
+ CancellationToken cancellationToken) {
+ MerchantQueries.GetMerchantScheduleQuery query = new(estateId, merchantId, year);
+ Result result = await mediator.Send(query, cancellationToken);
+
+ return ResponseFactory.FromResult(result, r => new DataTransferObjects.MerchantScheduleResponse() {
+ Year = r.Year,
+ Months = r.Months.Select(m => new DataTransferObjects.MerchantScheduleMonthResponse() {
+ Month = m.Month,
+ ClosedDays = m.ClosedDays
+ }).ToList()
+ });
+ }
}
\ No newline at end of file