79492eac16
Comprehensive NUnit test suite covering ChannelManager, CliChannel, TelegramChannel, DI registration, and integration scenarios. Uses Moq for mocking with test stubs for isolated unit testing.
65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Luna.Configuration;
|
|
using Luna.Configuration.Extensions;
|
|
|
|
namespace Luna.Channels.Tests;
|
|
|
|
[TestFixture]
|
|
[Category("Unit")]
|
|
public class TelegramOptionsTests
|
|
{
|
|
[Test]
|
|
public void BotToken_Binds_From_Configuration()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Channels:Telegram:BotToken"] = "test-token"
|
|
})
|
|
.Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IConfiguration>(config);
|
|
services.AddTelegramOptions();
|
|
|
|
var provider = services.BuildServiceProvider();
|
|
var options = provider.GetRequiredService<IOptions<TelegramOptions>>().Value;
|
|
|
|
Assert.That(options.BotToken, Is.EqualTo("test-token"));
|
|
}
|
|
|
|
[Test]
|
|
public void Validation_Fails_When_BotToken_Missing()
|
|
{
|
|
var config = new ConfigurationBuilder().Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IConfiguration>(config);
|
|
services.AddTelegramOptions();
|
|
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
Assert.That(
|
|
() => provider.GetRequiredService<IOptions<TelegramOptions>>().Value,
|
|
Throws.InstanceOf<OptionsValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PollingTimeoutSeconds_Defaults_To_30()
|
|
{
|
|
var options = new TelegramOptions { BotToken = "x" };
|
|
|
|
Assert.That(options.PollingTimeoutSeconds, Is.EqualTo(30));
|
|
}
|
|
|
|
[Test]
|
|
public void AllowedUserIds_Defaults_To_Empty()
|
|
{
|
|
var options = new TelegramOptions { BotToken = "x" };
|
|
|
|
Assert.That(options.AllowedUserIds, Is.Empty);
|
|
}
|
|
}
|