-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b81706c
commit d05109d
Showing
1 changed file
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
using System.Net; | ||
using System.Diagnostics; | ||
using System.Net; | ||
using Cnblogs.Architecture.TestIntegrationEvents; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Cnblogs.Architecture.IntegrationTests; | ||
|
||
[Collection(DddWebTestCollection.Name)] | ||
public class DaprTests | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public DaprTests(DddWebTestFactory factory) | ||
public DaprTests() | ||
{ | ||
_httpClient = factory.CreateClient(); | ||
} | ||
|
||
[Fact] | ||
public async Task Dapr_SubscribeEndpoint_OkAsync() | ||
{ | ||
// Arrange | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Services.AddDaprEventBus(nameof(DaprTests)); | ||
builder.WebHost.UseTestServer(); | ||
|
||
var app = builder.Build(); | ||
app.Subscribe<TestIntegrationEvent>(); | ||
await app.StartAsync(); | ||
var httpClient = app.GetTestClient(); | ||
|
||
// Act | ||
var response = await _httpClient.GetAsync("/dapr/subscribe"); | ||
var response = await httpClient.GetAsync("/dapr/subscribe"); | ||
|
||
// Assert | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
var responseText = await response.Content.ReadAsStringAsync(); | ||
responseText.Should().Contain("pubsub"); | ||
} | ||
|
||
[Fact] | ||
public async Task Dapr_MapSubscribeHandler_OkAsync() | ||
{ | ||
// Arrange | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Services.AddDaprClient(); | ||
builder.WebHost.UseTestServer(); | ||
|
||
var app = builder.Build(); | ||
app.MapSubscribeHandler(); | ||
await app.StartAsync(); | ||
var httpClient = app.GetTestClient(); | ||
|
||
// Act | ||
var response = await httpClient.GetAsync("/dapr/subscribe"); | ||
|
||
// Assert | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
} | ||
} |