Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 47 additions & 29 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@

await this.StartSqlContainer();

String dbConnString = GetLocalConnectionString($"EstateReportingReadModel{this.TestId}");
String dbConnString = GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId}");

this.factory = new CustomWebApplicationFactory<Startup>(dbConnString);
this.Client = this.factory.CreateClient();
this.ApiClient = new EstateReportingApiClient((s) => "http://localhost", this.Client);

this.context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}"));
this.context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId.ToString()}"));

this.helper = new DatabaseHelper(context);
await this.helper.CreateStoredProcedures(CancellationToken.None);
await this.SetupStandingData();
}

public virtual async Task DisposeAsync()

Check warning on line 52 in EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
}

Expand All @@ -65,7 +65,7 @@

protected Guid TestId;

internal async Task<Result<T?>> CreateAndSendHttpRequestMessage<T>(String url, CancellationToken cancellationToken)

Check warning on line 68 in EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
requestMessage.Headers.Add("estateId", this.TestId.ToString());
Expand All @@ -79,7 +79,7 @@
return null;
}

internal async Task<Result<T?>> CreateAndSendHttpRequestMessage<T>(String url, String payload, CancellationToken cancellationToken)

Check warning on line 82 in EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
requestMessage.Headers.Add("estateId", this.TestId.ToString());
Expand Down Expand Up @@ -112,7 +112,7 @@

NlogLogger logger = new NlogLogger();
logger.Initialise(LogManager.GetLogger("Specflow"), "Specflow");
LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

Check warning on line 115 in EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

'LogManager.AddHiddenAssembly(Assembly)' is obsolete: 'Replaced by LogManager.Setup().SetupLogFactory(setup => setup.AddCallSiteHiddenAssembly(assembly)). Marked obsolete on NLog 5.3'
dockerHelper.Logger = logger;
dockerHelper.SqlCredentials = SqlCredentials;
dockerHelper.SqlServerContainerName = "sharedsqlserver";
Expand Down Expand Up @@ -153,6 +153,6 @@


public class TestDockerHelper : DockerHelper{
public override async Task CreateSubscriptions(){

Check warning on line 156 in EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
// Nothing here
}
Expand Down
58 changes: 26 additions & 32 deletions EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Shared.Repositories;
using TransactionProcessor.Database.Contexts;

Expand All @@ -24,7 +26,7 @@

public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
private readonly string DatabaseConnectionString;
private string DatabaseConnectionString;

public CustomWebApplicationFactory(string databaseConnectionString)
{
Expand All @@ -38,12 +40,33 @@
{
builder.ConfigureServices(containerBuilder =>
{
var createcontext = new EstateManagementContext(DatabaseConnectionString);
bool b = createcontext.Database.EnsureCreated();
b.ShouldBeTrue();

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DatabaseConnectionString)
{
InitialCatalog = "TransactionProcessorReadModel",
};
this.DatabaseConnectionString = builder.ToString();

var context = new EstateManagementContext(DatabaseConnectionString);
Func<string, EstateManagementContext> f = connectionString => context;

IDbContextFactory<EstateManagementContext> factory = new DbContextFactory<EstateManagementContext>(new TestConnectionStringConfigurationRepository(DatabaseConnectionString), f);
containerBuilder.AddTransient<EstateManagementContext>(_ => context);
var serviceProvider = containerBuilder.BuildServiceProvider();

var inMemorySettings = new Dictionary<string, string>
{
{ "ConnectionStrings:TransactionProcessorReadModel", DatabaseConnectionString }
};

IConfiguration configuration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings)
.Build();

IReportingManager manager = new ReportingManager(factory);
IDbContextResolver<EstateManagementContext> resolver = new DbContextResolver<EstateManagementContext>(serviceProvider, configuration);
IReportingManager manager = new ReportingManager(resolver);

containerBuilder.AddSingleton(manager);

Expand All @@ -52,42 +75,13 @@
containerBuilder.AddAuthentication(TestAuthHandler.AuthenticationScheme)
.AddScheme<TestAuthHandlerOptions, TestAuthHandler>(TestAuthHandler.AuthenticationScheme, options => { });

bool b = context.Database.EnsureCreated();

b.ShouldBeTrue();
});

}

}

public class TestConnectionStringConfigurationRepository : IConnectionStringConfigurationRepository
{
private readonly string DbConnectionString;

public TestConnectionStringConfigurationRepository(String dbConnectionString)
{
DbConnectionString = dbConnectionString;
}
public Task DeleteConnectionStringConfiguration(string externalIdentifier, string connectionStringIdentifier,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public async Task<string> GetConnectionString(string externalIdentifier, string connectionStringIdentifier,
CancellationToken cancellationToken)
{
return DbConnectionString;
}

public Task CreateConnectionString(string externalIdentifier, string connectionStringIdentifier, string connectionString,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

public class TestAuthHandlerOptions : AuthenticationSchemeOptions
{
public string DefaultUserId { get; set; } = null!;
Expand All @@ -104,7 +98,7 @@
IOptionsMonitor<TestAuthHandlerOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock) : base(options, logger, encoder, clock)

Check warning on line 101 in EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

'AuthenticationHandler<TestAuthHandlerOptions>.AuthenticationHandler(IOptionsMonitor<TestAuthHandlerOptions>, ILoggerFactory, UrlEncoder, ISystemClock)' is obsolete: 'ISystemClock is obsolete, use TimeProvider on AuthenticationSchemeOptions instead.'

Check warning on line 101 in EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

'ISystemClock' is obsolete: 'Use TimeProvider instead.'
{
_defaultUserId = options.CurrentValue.DefaultUserId;
}
Expand Down
28 changes: 14 additions & 14 deletions EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[Fact]
public async Task DimensionsController_GetCalendarYears_NoDataInDatabase()
{
var yearsResult = await ApiClient.GetCalendarYears(string.Empty, Guid.NewGuid(), CancellationToken.None);
var yearsResult = await ApiClient.GetCalendarYears(string.Empty, this.TestId, CancellationToken.None);
yearsResult.IsFailed.ShouldBeTrue();
}

Expand All @@ -40,7 +40,7 @@
await helper.AddCalendarYear(year);
}

var result = await ApiClient.GetCalendarYears(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetCalendarYears(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var years = result.Data;
years.ShouldNotBeNull();
Expand All @@ -53,7 +53,7 @@
List<DateTime> datesInYear = helper.GetDatesForYear(DateTime.Now.Year);
await helper.AddCalendarDates(datesInYear);

Result<List<ComparisonDate>> result = await ApiClient.GetComparisonDates(string.Empty, Guid.NewGuid(), CancellationToken.None);
Result<List<ComparisonDate>> result = await ApiClient.GetComparisonDates(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
List<ComparisonDate> dates = result.Data;
List <DateTime> expectedDates = datesInYear.Where(d => d <= DateTime.Now.Date.AddDays(-1)).ToList();
Expand All @@ -73,7 +73,7 @@
[Fact]
public async Task DimensionsController_GetCalendarComparisonDates_NoDataInDatabase()
{
var result= await ApiClient.GetComparisonDates(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result= await ApiClient.GetComparisonDates(string.Empty, this.TestId, CancellationToken.None);
result.IsFailed.ShouldBeTrue();;
}

Expand All @@ -83,7 +83,7 @@
List<DateTime> datesInYear = helper.GetDatesForYear(2023);
await helper.AddCalendarDates(datesInYear);

var datesResult = await ApiClient.GetCalendarDates(string.Empty, Guid.NewGuid(), 2023, CancellationToken.None);
var datesResult = await ApiClient.GetCalendarDates(string.Empty, this.TestId, 2023, CancellationToken.None);

datesResult.IsSuccess.ShouldBeTrue();
var dates = datesResult.Data;
Expand All @@ -100,13 +100,13 @@
[Fact]
public async Task DimensionsController_GetCalendarDates_NoDataInDatabase()
{
var datesResult = await ApiClient.GetCalendarDates(string.Empty, Guid.NewGuid(), 2023, CancellationToken.None);
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, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

Expand All @@ -120,7 +120,7 @@
await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now);
}

var result = await ApiClient.GetMerchants(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var merchants = result.Data;

Expand Down Expand Up @@ -150,7 +150,7 @@
await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now, addressList);
}

var result = await ApiClient.GetMerchants(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var merchants = result.Data;

Expand Down Expand Up @@ -181,7 +181,7 @@
await helper.AddMerchant("Test Estate", $"Test Merchant {i}", DateTime.Now, addressList);
}

var result = await ApiClient.GetMerchants(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetMerchants(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
var merchants = result.Data;

Expand All @@ -200,7 +200,7 @@
[Fact]
public async Task DimensionsController_GetOperators_NoData_NoOperatorsReturned()
{
Result<List<Operator>> result = await ApiClient.GetOperators(string.Empty, Guid.NewGuid(), CancellationToken.None);
Result<List<Operator>> result = await ApiClient.GetOperators(string.Empty, this.TestId, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

Expand All @@ -213,7 +213,7 @@
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, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetOperators(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();

var operators = result.Data;
Expand Down Expand Up @@ -244,7 +244,7 @@
await helper.AddResponseCode(1002, "Unknown Merchant");
await helper.AddResponseCode(1003, "No Devices Configured");

var result = await ApiClient.GetResponseCodes(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetResponseCodes(string.Empty, this.TestId, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();

var responseCodes = result.Data;
Expand All @@ -261,7 +261,7 @@
[Fact]
public async Task DimensionsController_GetResponseCodes_NoData_NoResponseCodesReturned()
{
var result = await ApiClient.GetResponseCodes(string.Empty, Guid.NewGuid(), CancellationToken.None);
var result = await ApiClient.GetResponseCodes(string.Empty, this.TestId, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

Expand All @@ -275,7 +275,7 @@

}

public void Dispose()

Check warning on line 278 in EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

'DimensionsControllerTests.Dispose()' hides inherited member 'ControllerTestsBase.Dispose()'. Use the new keyword if hiding was intended.
{
EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}"));

Expand Down
Loading
Loading