forked from planetarium/libplanet
-
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
56 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
sdk/node/Libplanet.Node.Tests/Services/RendererServiceTest.cs
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,24 @@ | ||
using Libplanet.Node.Options; | ||
using Libplanet.Node.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.Tests.Services; | ||
|
||
public class RendererServiceTest | ||
{ | ||
[Fact] | ||
public async Task RenderAction_TestAsync() | ||
{ | ||
var serviceProvider = TestUtility.CreateServiceProvider(); | ||
var blockChainService = serviceProvider.GetRequiredService<IBlockChainService>(); | ||
var rendererService = serviceProvider.GetRequiredService<IRendererService>(); | ||
var blockChain = blockChainService.BlockChain; | ||
|
||
using var observer = new TestObserver<RenderBlockInfo>(rendererService.RenderBlockEnd); | ||
await Assert.RaisesAnyAsync( | ||
attach: handler => observer.Next += handler, | ||
detach: handler => observer.Next -= handler, | ||
testCode: async () => await BlockChainUtility.AppendBlockAsync(blockChain)); | ||
} | ||
} |
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,32 @@ | ||
namespace Libplanet.Node.Tests; | ||
|
||
internal sealed class TestObserver<T> : IObserver<T>, IDisposable | ||
{ | ||
private IDisposable? _subscription; | ||
|
||
public TestObserver(IObservable<T> observable) | ||
{ | ||
_subscription = observable.Subscribe(this); | ||
} | ||
|
||
public event EventHandler? Completed; | ||
|
||
public event EventHandler? Error; | ||
|
||
public event EventHandler? Next; | ||
|
||
public void Dispose() | ||
{ | ||
if (_subscription is not null) | ||
{ | ||
_subscription.Dispose(); | ||
_subscription = null; | ||
} | ||
} | ||
|
||
void IObserver<T>.OnCompleted() => Completed?.Invoke(this, EventArgs.Empty); | ||
|
||
void IObserver<T>.OnError(Exception error) => Error?.Invoke(this, EventArgs.Empty); | ||
|
||
void IObserver<T>.OnNext(T value) => Next?.Invoke(this, EventArgs.Empty); | ||
} |