Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Sep 9, 2024
1 parent afce2a2 commit 6c033ce
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdk/node/Libplanet.Node.Tests/Services/RendererServiceTest.cs
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));
}
}
32 changes: 32 additions & 0 deletions sdk/node/Libplanet.Node.Tests/TestObserver.cs
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);
}

0 comments on commit 6c033ce

Please sign in to comment.