Skip to content

Commit 3ce3128

Browse files
committed
Merge branch 'fix/fix-ci-failed'
2 parents b67d000 + a62177a commit 3ce3128

4 files changed

Lines changed: 25 additions & 155 deletions

File tree

.config/dotnet-tools.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"commands": [
2020
"aspire"
2121
]
22+
},
23+
"csharpier": {
24+
"version": "0.30.6",
25+
"commands": [
26+
"dotnet-csharpier"
27+
]
2228
}
2329
}
2430
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"main": "index.js",
88
"scripts": {
99
"prepare": "husky && dotnet tool restore",
10-
"format": "dotnet format booking-microservices.sln --severity error --verbosity detailed",
11-
"ci-format": "dotnet format booking-microservices.sln --verify-no-changes --severity error --verbosity detailed",
10+
"format": "dotnet tool run dotnet-csharpier booking-microservices.sln",
11+
"ci-format": "dotnet tool run dotnet-csharpier booking-microservices.sln --check",
1212
"upgrade-packages": "dotnet outdated --upgrade"
1313
},
1414
"devDependencies": {

src/BuildingBlocks/TestBase/TestBase.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,10 @@ public async Task InitializeAsync()
136136
{
137137
CancellationTokenSource = new CancellationTokenSource();
138138
await StartTestContainerAsync();
139-
140-
if (ServiceProvider.GetService<ITestHarness>() is { } harness)
141-
{
142-
await harness.Start();
143-
144-
// Add a small delay to ensure harness is ready
145-
await Task.Delay(1000);
146-
}
147139
}
148140

149141
public async Task DisposeAsync()
150142
{
151-
if (ServiceProvider.GetService<ITestHarness>() is { } harness)
152-
{
153-
await harness.Stop();
154-
}
155-
156143
await StopTestContainerAsync();
157144
await _factory.DisposeAsync();
158145
await CancellationTokenSource.CancelAsync();
@@ -312,13 +299,6 @@ await Task.WhenAll(
312299
// Start RabbitMQ last and wait extra time
313300
await RabbitMqTestContainer.StartAsync();
314301
await Task.Delay(5000); // Give RabbitMQ extra time to initialize
315-
316-
// Verify RabbitMQ is healthy
317-
var healthCheck = await RabbitMqTestContainer.ExecAsync(new[] { "rabbitmq-diagnostics", "ping" });
318-
if (healthCheck.ExitCode != 0)
319-
{
320-
await Task.Delay(5000); // Wait more if not healthy
321-
}
322302
}
323303

324304
private async Task StopTestContainerAsync()
@@ -743,4 +723,4 @@ protected TestBase(
743723
}
744724

745725
public TestFixture<TEntryPoint, TWContext, TRContext> Fixture { get; }
746-
}
726+
}

src/Services/Passenger/tests/IntegrationTest/Passenger/Features/CompleteRegisterPassengerTests.cs

Lines changed: 16 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -2,154 +2,38 @@
22
using BuildingBlocks.TestBase;
33
using FluentAssertions;
44
using Integration.Test.Fakes;
5-
using Microsoft.Extensions.Logging;
65
using Passenger.Data;
76
using Xunit;
8-
using Xunit.Abstractions;
97

108
namespace Integration.Test.Passenger.Features;
119

1210
public class CompleteRegisterPassengerTests : PassengerIntegrationTestBase
1311
{
1412
public CompleteRegisterPassengerTests(
15-
TestFixture<Program, PassengerDbContext, PassengerReadDbContext> integrationTestFactory,
16-
ITestOutputHelper outputHelper
13+
TestFixture<Program, PassengerDbContext, PassengerReadDbContext> integrationTestFactory
1714
)
18-
: base(integrationTestFactory)
19-
{
20-
Fixture.Logger = Fixture.CreateLogger(outputHelper);
21-
}
15+
: base(integrationTestFactory) { }
2216

2317
[Fact]
2418
public async Task should_complete_register_passenger_and_update_to_db()
2519
{
2620
// Arrange
27-
Fixture.Logger?.LogInformation("Starting CompleteRegisterPassenger test at {Time}", DateTime.UtcNow);
28-
29-
try
30-
{
31-
// Generate and publish UserCreated event
32-
var userCreated = new FakeUserCreated().Generate();
33-
Fixture.Logger?.LogInformation(
34-
"Generated UserCreated event with PassportNumber: {PassportNumber}",
35-
userCreated.PassportNumber
36-
);
37-
38-
await Fixture.Publish(userCreated);
39-
Fixture.Logger?.LogInformation("Published UserCreated event");
40-
41-
// Wait for publishing with retry logic
42-
var published = await WaitForWithRetry(
43-
async () => await Fixture.WaitForPublishing<UserCreated>(),
44-
"publishing",
45-
maxRetries: 3
46-
);
47-
48-
published.Should().BeTrue("UserCreated event should be published to message broker");
49-
Fixture.Logger?.LogInformation("UserCreated event published successfully");
50-
51-
// Wait for consuming with retry logic
52-
var consumed = await WaitForWithRetry(
53-
async () => await Fixture.WaitForConsuming<UserCreated>(),
54-
"consuming",
55-
maxRetries: 5
56-
);
57-
58-
consumed.Should().BeTrue("UserCreated event should be consumed by the passenger service");
59-
Fixture.Logger?.LogInformation("UserCreated event consumed successfully");
60-
61-
// Small delay to ensure event processing is complete
62-
await Task.Delay(1000);
63-
64-
// Generate and send complete registration command
65-
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
66-
Fixture.Logger?.LogInformation(
67-
"Sending CompleteRegisterPassenger command for PassportNumber: {PassportNumber}",
68-
command.PassportNumber
69-
);
70-
71-
// Act
72-
var response = await Fixture.SendAsync(command);
73-
Fixture.Logger?.LogInformation("Received response for CompleteRegisterPassenger command");
74-
75-
// Assert with detailed logging
76-
response.Should().NotBeNull("Response should not be null");
77-
Fixture.Logger?.LogInformation("Response is not null");
78-
79-
response?.PassengerDto.Should().NotBeNull("PassengerDto should not be null");
80-
81-
response
82-
?.PassengerDto?.Name.Should()
83-
.Be(
84-
userCreated.Name,
85-
$"Passenger name should be '{userCreated.Name}' but was '{response?.PassengerDto?.Name}'"
86-
);
87-
88-
response
89-
?.PassengerDto?.PassportNumber.Should()
90-
.Be(
91-
command.PassportNumber,
92-
$"Passport number should be '{command.PassportNumber}' but was '{response?.PassengerDto?.PassportNumber}'"
93-
);
94-
95-
response
96-
?.PassengerDto?.PassengerType.ToString()
97-
.Should()
98-
.Be(
99-
command.PassengerType.ToString(),
100-
$"Passenger type should be '{command.PassengerType}' but was '{response?.PassengerDto?.PassengerType}'"
101-
);
102-
103-
response
104-
?.PassengerDto?.Age.Should()
105-
.Be(command.Age, $"Age should be {command.Age} but was {response?.PassengerDto?.Age}");
106-
107-
Fixture.Logger?.LogInformation("All assertions passed successfully");
108-
}
109-
catch (Exception ex)
110-
{
111-
Fixture.Logger?.LogError(ex, "Test failed with exception: {Message}", ex.Message);
112-
throw;
113-
}
114-
finally
115-
{
116-
Fixture.Logger?.LogInformation("Test completed at {Time}", DateTime.UtcNow);
117-
}
118-
}
119-
120-
private async Task<bool> WaitForWithRetry(Func<Task<bool>> waitCondition, string operation, int maxRetries = 3)
121-
{
122-
for (int i = 0; i < maxRetries; i++)
123-
{
124-
Fixture.Logger?.LogInformation(
125-
"Attempt {Attempt}/{MaxRetries} for {Operation}",
126-
i + 1,
127-
maxRetries,
128-
operation
129-
);
21+
var userCreated = new FakeUserCreated().Generate();
13022

131-
var result = await waitCondition();
23+
await Fixture.Publish(userCreated);
24+
(await Fixture.WaitForPublishing<UserCreated>()).Should().Be(true);
25+
(await Fixture.WaitForConsuming<UserCreated>()).Should().Be(true);
13226

133-
if (result)
134-
{
135-
Fixture.Logger?.LogInformation("{Operation} successful on attempt {Attempt}", operation, i + 1);
136-
return true;
137-
}
27+
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
13828

139-
if (i < maxRetries - 1)
140-
{
141-
var delaySeconds = (i + 1) * 2; // Exponential backoff: 2, 4, 6 seconds
142-
Fixture.Logger?.LogWarning(
143-
"{Operation} failed on attempt {Attempt}, waiting {Delay}s before retry",
144-
operation,
145-
i + 1,
146-
delaySeconds
147-
);
148-
await Task.Delay(TimeSpan.FromSeconds(delaySeconds));
149-
}
150-
}
29+
// Act
30+
var response = await Fixture.SendAsync(command);
15131

152-
Fixture.Logger?.LogError("{Operation} failed after {MaxRetries} attempts", operation, maxRetries);
153-
return false;
32+
// Assert
33+
response.Should().NotBeNull();
34+
response?.PassengerDto?.Name.Should().Be(userCreated.Name);
35+
response?.PassengerDto?.PassportNumber.Should().Be(command.PassportNumber);
36+
response?.PassengerDto?.PassengerType.ToString().Should().Be(command.PassengerType.ToString());
37+
response?.PassengerDto?.Age.Should().Be(command.Age);
15438
}
155-
}
39+
}

0 commit comments

Comments
 (0)