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
commitc7dd16740d7a8953533c895d1bebec0d84f7ec65 (patch)
tree82e3918b2a681c18eaccb11df0349b1dd3f9f198 /BackEnd/Timeline.Tests/IntegratedTests/TimelineHubTest.cs
parentaac9480e22060ddb62ccbdc3a5b851a54d2fe3af (diff)
parent634fc0454b81dc63e6dd31e69930d5eb5d744b47 (diff)
downloadtimeline-c7dd16740d7a8953533c895d1bebec0d84f7ec65.tar.gz
timeline-c7dd16740d7a8953533c895d1bebec0d84f7ec65.tar.bz2
timeline-c7dd16740d7a8953533c895d1bebec0d84f7ec65.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]