-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
83 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// <copyright file="CallbackNoneTest.cs" company="JSSoft"> | ||
// Copyright (c) 2024 Jeesu Choi. All Rights Reserved. | ||
// Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
// </copyright> | ||
|
||
using JSSoft.Communication.Tests.Extensions; | ||
using Xunit.Abstractions; | ||
|
||
namespace JSSoft.Communication.Tests; | ||
|
||
public class CallbackNoneTest : IAsyncLifetime | ||
{ | ||
private const int Timeout = 30000; | ||
private readonly ITestOutputHelper _logger; | ||
private readonly TestServer1 _testServer = new(); | ||
private readonly ServerContext _serverContext; | ||
private readonly ClientContext _clientContext; | ||
private readonly RandomEndPoint _endPoint = new(); | ||
private ITestService1? _server; | ||
|
||
private Guid _clientToken; | ||
private Guid _serverToken; | ||
|
||
public CallbackNoneTest(ITestOutputHelper logger) | ||
{ | ||
_logger = logger; | ||
_serverContext = new(_testServer) { EndPoint = _endPoint }; | ||
_clientContext = new(new ClientService<ITestService1>()) { EndPoint = _endPoint }; | ||
logger.WriteLine($"{_endPoint}"); | ||
} | ||
|
||
public interface ITestService1 | ||
{ | ||
void Invoke(); | ||
} | ||
|
||
public interface ITestService2 | ||
{ | ||
void Invoke(); | ||
} | ||
|
||
public interface ITestCallback2 | ||
{ | ||
void OnInvoked(); | ||
} | ||
|
||
[Fact] | ||
public void Callback1_Test() | ||
{ | ||
var manualResetEvent = new ManualResetEvent(false); | ||
_clientContext.Disconnected += ClientContext_Disconnected; | ||
_server!.Invoke(); | ||
Assert.True(manualResetEvent.WaitOne(Timeout)); | ||
Check failure on line 53 in test/JSSoft.Communication.Tests/CallbackNoneTest.cs GitHub Actions / XUnit TestsJSSoft.Communication.Tests.CallbackNoneTest ► Callback1_Test
Raw output
|
||
|
||
void ClientContext_Disconnected(object? sender, EventArgs e) | ||
{ | ||
manualResetEvent.Set(); | ||
} | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
_logger.WriteLine($"InitializeAsync 1"); | ||
_serverToken = await _serverContext.OpenAsync(CancellationToken.None); | ||
_clientToken = await _clientContext.OpenAsync(CancellationToken.None); | ||
_server = _testServer; | ||
_logger.WriteLine($"InitializeAsync 2"); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
_logger.WriteLine($"DisposeAsync 1"); | ||
await _serverContext.ReleaseAsync(_serverToken); | ||
await _clientContext.ReleaseAsync(_clientToken); | ||
_endPoint.Dispose(); | ||
_logger.WriteLine($"DisposeAsync 2"); | ||
} | ||
|
||
private sealed class TestServer1 : ServerService<ITestService1, ITestCallback2>, ITestService1 | ||
{ | ||
public void Invoke() => Client.OnInvoked(); | ||
} | ||
} |