Skip to content

Commit d8358d6

Browse files
committed
Fix warnings in the test project
1 parent 82b13bf commit d8358d6

File tree

3 files changed

+96
-84
lines changed

3 files changed

+96
-84
lines changed

AdvancedTodoList.IntegrationTests/Fixtures/BusinessLogicFixture.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ namespace AdvancedTodoList.IntegrationTests.Fixtures;
77
/// </summary>
88
public abstract class BusinessLogicFixture
99
{
10-
protected BusinessLogicWebApplicationFactory WebApplicationFactory { get; private set; }
11-
protected IServiceScope ServiceScope { get; private set; }
10+
protected BusinessLogicWebApplicationFactory WebApplicationFactory { get; private set; }
11+
protected IServiceScope ServiceScope { get; private set; }
1212

13-
[SetUp]
14-
public void SetUpTest()
15-
{
16-
// Configure web application factory
17-
WebApplicationFactory = new BusinessLogicWebApplicationFactory();
18-
WebApplicationFactory.Server.PreserveExecutionContext = true;
13+
[SetUp]
14+
public void SetUpTest()
15+
{
16+
// Configure web application factory
17+
WebApplicationFactory = new BusinessLogicWebApplicationFactory();
18+
WebApplicationFactory.Server.PreserveExecutionContext = true;
1919

20-
var scopeFactory = WebApplicationFactory.Services.GetService<IServiceScopeFactory>()!;
21-
ServiceScope = scopeFactory.CreateScope();
22-
}
20+
var scopeFactory = WebApplicationFactory.Services.GetService<IServiceScopeFactory>()!;
21+
ServiceScope = scopeFactory.CreateScope();
22+
}
2323

24-
[TearDown]
25-
public Task TearDownTestAsync()
26-
{
27-
ServiceScope.Dispose();
28-
return WebApplicationFactory.DisposeAsync().AsTask();
29-
}
24+
[TearDown]
25+
public async Task TearDownTestAsync()
26+
{
27+
ServiceScope.Dispose();
28+
await WebApplicationFactory.DisposeAsync();
29+
}
3030
}

AdvancedTodoList.IntegrationTests/Fixtures/EndpointsFixture.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,54 @@ namespace AdvancedTodoList.IntegrationTests.Fixtures;
1212
/// </summary>
1313
public abstract class EndpointsFixture
1414
{
15-
protected IConfiguration Configuration { get; private set; }
16-
protected EndpointsWebApplicationFactory WebApplicationFactory { get; private set; }
17-
protected IServiceScope ServiceScope { get; private set; }
15+
protected IConfiguration Configuration { get; private set; }
16+
protected EndpointsWebApplicationFactory WebApplicationFactory { get; private set; }
17+
protected IServiceScope ServiceScope { get; private set; }
1818

19-
public const string TestUserId = "TestUserId";
19+
public const string TestUserId = "TestUserId";
2020

21-
protected HttpClient CreateAuthorizedHttpClient(string userId = TestUserId)
22-
{
23-
// Create a valid JWT
24-
string strKey = Configuration["Auth:AccessToken:SecretKey"]!;
25-
SymmetricSecurityKey key = new(Encoding.UTF8.GetBytes(strKey));
21+
protected HttpClient CreateAuthorizedHttpClient(string userId = TestUserId)
22+
{
23+
// Create a valid JWT
24+
string strKey = Configuration["Auth:AccessToken:SecretKey"]!;
25+
SymmetricSecurityKey key = new(Encoding.UTF8.GetBytes(strKey));
2626

27-
List<Claim> authClaims =
28-
[
29-
new(JwtRegisteredClaimNames.Sub, userId)
30-
];
31-
JwtSecurityToken token = new(
32-
issuer: Configuration["Auth:AccessToken:ValidIssuer"],
33-
audience: Configuration["Auth:AccessToken:ValidAudience"],
34-
expires: DateTime.UtcNow.AddMinutes(30),
35-
claims: authClaims,
36-
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
37-
);
27+
List<Claim> authClaims =
28+
[
29+
new(JwtRegisteredClaimNames.Sub, userId)
30+
];
31+
JwtSecurityToken token = new(
32+
issuer: Configuration["Auth:AccessToken:ValidIssuer"],
33+
audience: Configuration["Auth:AccessToken:ValidAudience"],
34+
expires: DateTime.UtcNow.AddMinutes(30),
35+
claims: authClaims,
36+
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
37+
);
3838

39-
string bearerToken = new JwtSecurityTokenHandler().WriteToken(token);
39+
string bearerToken = new JwtSecurityTokenHandler().WriteToken(token);
4040

41-
var client = WebApplicationFactory.CreateClient();
42-
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {bearerToken}");
41+
var client = WebApplicationFactory.CreateClient();
42+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {bearerToken}");
4343

44-
return client;
45-
}
44+
return client;
45+
}
4646

47-
[SetUp]
48-
public void SetUpTest()
49-
{
50-
// Configure web application factory
51-
WebApplicationFactory = new EndpointsWebApplicationFactory();
52-
WebApplicationFactory.Server.PreserveExecutionContext = true;
47+
[SetUp]
48+
public void SetUpTest()
49+
{
50+
// Configure web application factory
51+
WebApplicationFactory = new EndpointsWebApplicationFactory();
52+
WebApplicationFactory.Server.PreserveExecutionContext = true;
5353

54-
var scopeFactory = WebApplicationFactory.Services.GetService<IServiceScopeFactory>()!;
55-
ServiceScope = scopeFactory.CreateScope();
56-
Configuration = ServiceScope.ServiceProvider.GetService<IConfiguration>()!;
57-
}
54+
var scopeFactory = WebApplicationFactory.Services.GetService<IServiceScopeFactory>()!;
55+
ServiceScope = scopeFactory.CreateScope();
56+
Configuration = ServiceScope.ServiceProvider.GetService<IConfiguration>()!;
57+
}
5858

59-
[TearDown]
60-
public Task TearDownTestAsync()
61-
{
62-
ServiceScope.Dispose();
63-
return WebApplicationFactory.DisposeAsync().AsTask();
64-
}
59+
[TearDown]
60+
public async Task TearDownTestAsync()
61+
{
62+
ServiceScope.Dispose();
63+
await WebApplicationFactory.DisposeAsync();
64+
}
6565
}

AdvancedTodoList.IntegrationTests/TestContainersSetup.cs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,50 @@
22

33
namespace AdvancedTodoList.IntegrationTests;
44

5+
#pragma warning disable IDE0079
6+
#pragma warning disable NUnit1028
7+
#pragma warning disable NUnit1032
8+
59
/// <summary>
610
/// Class that sets up integration testing environment.
711
/// </summary>
812
[SetUpFixture]
913
public static class TestContainersSetup
1014
{
11-
/// <summary>
12-
/// Test container that contains a database.
13-
/// </summary>
14-
private static MsSqlContainer? s_testDbContainer;
15+
/// <summary>
16+
/// Test container that contains a database.
17+
/// </summary>
18+
private static MsSqlContainer? s_testDbContainer;
1519

16-
/// <summary>
17-
/// Gets a running test container or creates it if it's the first call.
18-
/// </summary>
19-
/// <returns>
20-
/// A running testing MS SQL container.
21-
/// </returns>
22-
public static async Task<MsSqlContainer> GetTestContainerAsync()
23-
{
24-
if (s_testDbContainer == null)
25-
{
26-
// Initialize and start a container with test DB
27-
s_testDbContainer = new MsSqlBuilder().Build();
28-
await s_testDbContainer.StartAsync();
29-
}
30-
return s_testDbContainer;
31-
}
20+
/// <summary>
21+
/// Gets a running test container or creates it if it's the first call.
22+
/// </summary>
23+
/// <returns>
24+
/// A running testing MS SQL container.
25+
/// </returns>
26+
public static async Task<MsSqlContainer> GetTestContainerAsync()
27+
{
28+
if (s_testDbContainer == null)
29+
{
30+
// Initialize and start a container with test DB
31+
s_testDbContainer = new MsSqlBuilder().Build();
32+
await s_testDbContainer.StartAsync();
33+
}
34+
return s_testDbContainer;
35+
}
3236

33-
[OneTimeTearDown]
34-
public static async Task TearDown()
35-
{
36-
// Stop the DB container
37-
if (s_testDbContainer != null) await s_testDbContainer.StopAsync();
38-
}
37+
[OneTimeTearDown]
38+
public static async Task TearDown()
39+
{
40+
// Stop the DB container
41+
if (s_testDbContainer != null)
42+
{
43+
await s_testDbContainer.StopAsync();
44+
await s_testDbContainer.DisposeAsync();
45+
}
46+
}
3947
}
48+
49+
#pragma warning restore NUnit1028
50+
#pragma warning restore NUnit1032
51+
#pragma warning restore IDE0079

0 commit comments

Comments
 (0)