From 06c474f68ceb895b5bd1956b99c90499c98b268a Mon Sep 17 00:00:00 2001 From: s2quake Date: Thu, 5 Sep 2024 11:43:37 +0900 Subject: [PATCH] test: Add ValidatorServiceTest --- .../Services/ValidatorServiceTest.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sdk/node/Libplanet.Node.Tests/Services/ValidatorServiceTest.cs diff --git a/sdk/node/Libplanet.Node.Tests/Services/ValidatorServiceTest.cs b/sdk/node/Libplanet.Node.Tests/Services/ValidatorServiceTest.cs new file mode 100644 index 00000000000..a81b2e4df5d --- /dev/null +++ b/sdk/node/Libplanet.Node.Tests/Services/ValidatorServiceTest.cs @@ -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 + { + [$"{SwarmOptions.Position}:{nameof(SwarmOptions.IsEnabled)}"] = "true", + [$"{ValidatorOptions.Position}:{nameof(ValidatorOptions.IsEnabled)}"] = "true", + }; + var serviceProvider = TestUtility.CreateServiceProvider(settings); + var validatorService = serviceProvider.GetRequiredService(); + Assert.NotNull(validatorService); + } + + [Fact] + public void Enable_WithoutSwarm_ThrowTest() + { + var settings = new Dictionary + { + [$"{ValidatorOptions.Position}:{nameof(ValidatorOptions.IsEnabled)}"] = "true", + }; + var serviceProvider = TestUtility.CreateServiceProvider(settings); + Assert.Throws( + serviceProvider.GetRequiredService); + } + + [Fact] + public void Disable_ThrowTest() + { + var serviceProvider = TestUtility.CreateServiceProvider(); + Assert.ThrowsAny( + serviceProvider.GetRequiredService); + } +}