|
1 | | -using System.Net; |
| 1 | +using System.Diagnostics; |
| 2 | +using System.Net; |
| 3 | +using Cnblogs.Architecture.TestIntegrationEvents; |
2 | 4 | using FluentAssertions; |
| 5 | +using Microsoft.AspNetCore.Builder; |
| 6 | +using Microsoft.AspNetCore.Routing; |
| 7 | +using Microsoft.AspNetCore.TestHost; |
| 8 | +using Microsoft.Extensions.DependencyInjection; |
3 | 9 |
|
4 | 10 | namespace Cnblogs.Architecture.IntegrationTests; |
5 | 11 |
|
6 | | -[Collection(DddWebTestCollection.Name)] |
7 | 12 | public class DaprTests |
8 | 13 | { |
9 | | - private readonly HttpClient _httpClient; |
10 | | - |
11 | | - public DaprTests(DddWebTestFactory factory) |
| 14 | + public DaprTests() |
12 | 15 | { |
13 | | - _httpClient = factory.CreateClient(); |
14 | 16 | } |
15 | 17 |
|
16 | 18 | [Fact] |
17 | 19 | public async Task Dapr_SubscribeEndpoint_OkAsync() |
18 | 20 | { |
| 21 | + // Arrange |
| 22 | + var builder = WebApplication.CreateBuilder(); |
| 23 | + builder.Services.AddDaprEventBus(nameof(DaprTests)); |
| 24 | + builder.WebHost.UseTestServer(); |
| 25 | + |
| 26 | + var app = builder.Build(); |
| 27 | + app.Subscribe<TestIntegrationEvent>(); |
| 28 | + await app.StartAsync(); |
| 29 | + var httpClient = app.GetTestClient(); |
| 30 | + |
19 | 31 | // Act |
20 | | - var response = await _httpClient.GetAsync("/dapr/subscribe"); |
| 32 | + var response = await httpClient.GetAsync("/dapr/subscribe"); |
21 | 33 |
|
22 | 34 | // Assert |
23 | 35 | response.StatusCode.Should().Be(HttpStatusCode.OK); |
24 | 36 | var responseText = await response.Content.ReadAsStringAsync(); |
25 | 37 | responseText.Should().Contain("pubsub"); |
26 | 38 | } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public async Task Dapr_MapSubscribeHandler_OkAsync() |
| 42 | + { |
| 43 | + // Arrange |
| 44 | + var builder = WebApplication.CreateBuilder(); |
| 45 | + builder.Services.AddDaprClient(); |
| 46 | + builder.WebHost.UseTestServer(); |
| 47 | + |
| 48 | + var app = builder.Build(); |
| 49 | + app.MapSubscribeHandler(); |
| 50 | + await app.StartAsync(); |
| 51 | + var httpClient = app.GetTestClient(); |
| 52 | + |
| 53 | + // Act |
| 54 | + var response = await httpClient.GetAsync("/dapr/subscribe"); |
| 55 | + |
| 56 | + // Assert |
| 57 | + response.StatusCode.Should().Be(HttpStatusCode.OK); |
| 58 | + } |
27 | 59 | } |
0 commit comments