Skip to content

Commit 7b656cc

Browse files
refactor: refactor test case
Co-authored-by: 沈星繁 <ikesnowy@outlook.com>
1 parent 0bdda4e commit 7b656cc

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

test/Cnblogs.Architecture.IntegrationTests/IntegrationEventHandlerTests.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,31 @@ namespace Cnblogs.Architecture.IntegrationTests;
1717
public class IntegrationEventHandlerTests
1818
{
1919
private readonly IntegrationTestFactory _factory;
20+
private readonly ITestOutputHelper _testOutputHelper;
2021

21-
public IntegrationEventHandlerTests(IntegrationTestFactory factory)
22+
public IntegrationEventHandlerTests(IntegrationTestFactory factory, ITestOutputHelper testOutputHelper)
2223
{
2324
_factory = factory;
25+
_factory.TestOutputHelper = testOutputHelper;
26+
_testOutputHelper = testOutputHelper;
2427
}
2528

2629
[Fact]
2730
public async Task IntegrationEventHandler_TestIntegrationEvent_SuccessAsync()
2831
{
2932
// Arrange
3033
var client = _factory.CreateClient();
34+
var @event = new TestIntegrationEvent(Guid.NewGuid(), DateTimeOffset.Now, "Hello World!");
3135

3236
// Act
3337
var subscriptions = await client.GetFromJsonAsync<Subscription[]>("/dapr/subscribe");
34-
35-
// Assert
36-
subscriptions.Should().NotBeNullOrEmpty();
37-
38-
// Act
39-
var sub = subscriptions.FirstOrDefault(s => s.Route.Contains(nameof(TestIntegrationEvent)));
40-
41-
// Assert
42-
sub.Should().NotBeNull();
43-
44-
Debug.WriteLine("Subscription Route: " + sub.Route);
45-
46-
// Act
47-
var @event = new TestIntegrationEvent(Guid.NewGuid(), DateTimeOffset.Now, "Hello World!");
38+
var sub = subscriptions.First(x => x.Route.Contains(nameof(TestIntegrationEvent)));
4839
var response = await client.PostAsJsonAsync(sub.Route, @event);
40+
_testOutputHelper.WriteLine("Subscription Route: " + sub.Route);
4941

5042
// Assert
5143
response.Should().BeSuccessful();
52-
Assert.True(response.Headers.TryGetValues(Constants.IntegrationEventIdHeaderName, out var values));
53-
values.First().Should().Be(@event.Id.ToString());
44+
response.Headers.Should().ContainKey(Constants.IntegrationEventIdHeaderName)
45+
.WhoseValue.First().Should().Be(@event.Id.ToString());
5446
}
5547
}

0 commit comments

Comments
 (0)