Skip to content

Commit 9b98792

Browse files
minor crime fixed
1 parent 43d628f commit 9b98792

3 files changed

Lines changed: 27 additions & 36 deletions

File tree

EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,13 @@ public abstract class ControllerTestsBase : IAsyncLifetime
1919
protected List<String> merchantsList;
2020
protected List<(String contract, String operatorname)> contractList;
2121
protected Dictionary<String, List<String>> contractProducts;
22-
22+
protected DatabaseHelper helper;
2323
public virtual async Task InitializeAsync()
2424
{
25-
await this.SetupStandingData();
26-
}
27-
28-
public virtual async Task DisposeAsync()
29-
{
30-
}
31-
32-
protected DatabaseHelper helper;
33-
34-
protected EstateManagementGenericContext context;
35-
36-
protected abstract Task ClearStandingData();
37-
protected abstract Task SetupStandingData();
38-
39-
protected readonly HttpClient Client;
40-
protected readonly CustomWebApplicationFactory<Startup> factory;
41-
42-
protected readonly Guid TestId;
25+
this.TestId = Guid.NewGuid();
4326

44-
public ControllerTestsBase(){
45-
this.StartSqlContainer();
27+
await this.StartSqlContainer();
4628

47-
this.TestId = Guid.NewGuid();
4829
String dbConnString = GetLocalConnectionString($"EstateReportingReadModel{this.TestId}");
4930

5031
this.factory = new CustomWebApplicationFactory<Startup>(dbConnString);
@@ -53,8 +34,24 @@ public ControllerTestsBase(){
5334
this.context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}"));
5435

5536
this.helper = new DatabaseHelper(context);
37+
38+
await this.SetupStandingData();
5639
}
5740

41+
public virtual async Task DisposeAsync()
42+
{
43+
}
44+
45+
protected EstateManagementGenericContext context;
46+
47+
protected abstract Task ClearStandingData();
48+
protected abstract Task SetupStandingData();
49+
50+
protected HttpClient Client;
51+
protected CustomWebApplicationFactory<Startup> factory;
52+
53+
protected Guid TestId;
54+
5855
internal async Task<T?> CreateAndSendHttpRequestMessage<T>(String url, CancellationToken cancellationToken)
5956
{
6057
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
@@ -78,7 +75,7 @@ public static String GetLocalConnectionString(String databaseName)
7875
return $"server=localhost,{databaseHostPort};database={databaseName};user id={SqlCredentials.usename};password={SqlCredentials.password};Encrypt=false";
7976
}
8077

81-
internal void StartSqlContainer(){
78+
internal async Task StartSqlContainer(){
8279
DockerHelper dockerHelper = new TestDockerHelper();
8380

8481
NlogLogger logger = new NlogLogger();
@@ -87,9 +84,10 @@ internal void StartSqlContainer(){
8784
dockerHelper.Logger = logger;
8885
dockerHelper.SqlCredentials = SqlCredentials;
8986
dockerHelper.SqlServerContainerName = "sharedsqlserver";
87+
dockerHelper.RequiredDockerServices = DockerServices.SqlServer;
9088

9189
DatabaseServerNetwork = dockerHelper.SetupTestNetwork("sharednetwork", true);
92-
Retry.For(async () => {
90+
await Retry.For(async () => {
9391
DatabaseServerContainer = await dockerHelper.SetupSqlServerContainer(DatabaseServerNetwork);
9492
});
9593
}

EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
using ResponseCode = DataTrasferObjects.ResponseCode;
1515

1616
public class DimensionsControllerTests :ControllerTestsBase{
17-
private DatabaseHelper helper;
18-
public DimensionsControllerTests(){
19-
EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}"));
20-
21-
this.helper = new DatabaseHelper(context);
22-
}
23-
2417

2518
[Fact]
2619
public async Task DimensionsController_GetCalendarYears_NoDataInDatabase(){

EstateReportingAPI.IntegrationTests/FactSettlementsControllerTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
public class FactSettlementsControllerTests : ControllerTestsBase
1212
{
1313
protected override async Task ClearStandingData(){
14-
await this.helper.DeleteAllContracts();
15-
await this.helper.DeleteAllEstateOperator();
16-
await this.helper.DeleteAllMerchants();
17-
}
14+
await this.helper.DeleteAllContracts();
15+
await this.helper.DeleteAllEstateOperator();
16+
await this.helper.DeleteAllMerchants();
17+
}
1818

19-
protected override async Task SetupStandingData(){
19+
protected override async Task SetupStandingData(){
2020
// Estates
2121
await helper.AddEstate("Test Estate", "Ref1");
2222

0 commit comments

Comments
 (0)