Skip to content

Commit

Permalink
test: Add ValidatorServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Sep 5, 2024
1 parent d60b474 commit c93be13
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions sdk/node/Libplanet.Node.Tests/Services/ValidatorServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Libplanet.Node.Options;
using Libplanet.Node.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Libplanet.Node.Tests.Services;

public class ValidatorServiceTest
{
[Fact]
public void Enable_Test()
{
var settings = new Dictionary<string, string?>
{
[$"{SwarmOptions.Position}:{nameof(SwarmOptions.IsEnabled)}"] = "true",
[$"{ValidatorOptions.Position}:{nameof(ValidatorOptions.IsEnabled)}"] = "true",
};
var serviceProvider = TestUtility.CreateServiceProvider(settings);
var validatorService = serviceProvider.GetRequiredService<IValidatorService>();
Assert.NotNull(validatorService);
}

[Fact]
public void Enable_WithoutSwarm_ThrowTest()
{
var settings = new Dictionary<string, string?>
{
[$"{ValidatorOptions.Position}:{nameof(ValidatorOptions.IsEnabled)}"] = "true",
};
var serviceProvider = TestUtility.CreateServiceProvider(settings);
Assert.Throws<OptionsValidationException>(
serviceProvider.GetRequiredService<IValidatorService>);
}

[Fact]
public void Disable_ThrowTest()
{
var serviceProvider = TestUtility.CreateServiceProvider();
Assert.ThrowsAny<InvalidOperationException>(
serviceProvider.GetRequiredService<ISwarmService>);
}
}

0 comments on commit c93be13

Please sign in to comment.