aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-02 22:02:32 +0800
committerGitHub <noreply@github.com>2021-06-02 22:02:32 +0800
commit125c77d974c90b547ec3f89e71ad6420f1668fd3 (patch)
tree7d42d50306047b53853edbcbc131b95f42aeef16 /BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
parent9060b1e463b5928d7d0e412fbd4cd7178e131bd4 (diff)
parent0f0b189043b18b951c1aca0174b189bd4ae4cd08 (diff)
downloadtimeline-125c77d974c90b547ec3f89e71ad6420f1668fd3.tar.gz
timeline-125c77d974c90b547ec3f89e71ad6420f1668fd3.tar.bz2
timeline-125c77d974c90b547ec3f89e71ad6420f1668fd3.zip
Merge pull request #587 from crupest/default-color
Add patch default color api.
Diffstat (limited to 'BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs')
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs39
1 files changed, 23 insertions, 16 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
index e8b774d8..9b28a648 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
@@ -1,6 +1,7 @@
using FluentAssertions;
using Microsoft.AspNetCore.SignalR.Client;
using System;
+using System.Threading;
using System.Threading.Tasks;
using Timeline.SignalRHub;
using Xunit;
@@ -17,7 +18,7 @@ namespace Timeline.Tests.IntegratedTests
private HubConnection CreateConnection(string? token)
{
- return new HubConnectionBuilder().WithUrl("http://localhost/api/hub/timeline",
+ return new HubConnectionBuilder().WithUrl("ws://localhost/api/hub/timeline",
options =>
{
options.HttpMessageHandlerFactory = _ => TestApp.Server.CreateHandler();
@@ -33,36 +34,42 @@ namespace Timeline.Tests.IntegratedTests
await using var connection = CreateConnection(token);
+ await connection.StartAsync();
+ connection.State.Should().Be(HubConnectionState.Connected);
+
+ using SemaphoreSlim semaphore = new SemaphoreSlim(0);
+
var changed = false;
connection.On<string>(nameof(ITimelineClient.OnTimelinePostChanged), (timelineName) =>
{
timelineName.Should().Be(generator(1));
changed = true;
+ semaphore.Release();
});
- await connection.StartAsync();
- connection.State.Should().Be(HubConnectionState.Connected);
+ await Task.Run(async () =>
+ {
+ using var client = await CreateClientAsUser();
- using var client = await CreateClientAsUser();
+ await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("aaa"));
- await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("aaa"));
- await Task.Delay(1);
- changed.Should().BeFalse();
+ changed.Should().BeFalse();
- await connection.InvokeAsync(nameof(TimelineHub.SubscribeTimelinePostChange), generator(1));
+ await connection.InvokeAsync(nameof(TimelineHub.SubscribeTimelinePostChange), generator(1));
- await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("bbb"));
- await Task.Delay(1);
- changed.Should().BeTrue();
+ await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("bbb"));
+ await semaphore.WaitAsync();
+ changed.Should().BeTrue();
- changed = false;
+ changed = false;
- await connection.InvokeAsync(nameof(TimelineHub.UnsubscribeTimelinePostChange), generator(1));
+ await connection.InvokeAsync(nameof(TimelineHub.UnsubscribeTimelinePostChange), generator(1));
- await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("ccc"));
- await Task.Delay(1);
- changed.Should().BeFalse();
+ await client.TestPostAsync($"timelines/{generator(1)}/posts", TimelinePostTest.CreateTextPostRequest("ccc"));
+ changed.Should().BeFalse();
+
+ });
}
[Fact]