Files
ChatBot/ChatBot.Tests/Configuration/Validators/TelegramBotSettingsValidatorTests.cs
Leonid Pershin 03eb0f22a2 add tests
2025-10-17 05:47:18 +03:00

77 lines
2.1 KiB
C#

using ChatBot.Models.Configuration;
using ChatBot.Models.Configuration.Validators;
using FluentAssertions;
namespace ChatBot.Tests.Configuration.Validators;
public class TelegramBotSettingsValidatorTests
{
private readonly TelegramBotSettingsValidator _validator = new();
[Fact]
public void Validate_ShouldReturnSuccess_WhenSettingsAreValid()
{
// Arrange
var settings = new TelegramBotSettings
{
BotToken = "1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk",
};
// Act
var result = _validator.Validate(null, settings);
// Assert
result.Succeeded.Should().BeTrue();
}
[Fact]
public void Validate_ShouldReturnFailure_WhenBotTokenIsEmpty()
{
// Arrange
var settings = new TelegramBotSettings { BotToken = "" };
// Act
var result = _validator.Validate(null, settings);
// Assert
result.Succeeded.Should().BeFalse();
result.Failures.Should().Contain(f => f.Contains("Telegram bot token is required"));
}
[Fact]
public void Validate_ShouldReturnFailure_WhenBotTokenIsTooShort()
{
// Arrange
var settings = new TelegramBotSettings
{
BotToken = "1234567890:ABC", // 15 chars, too short
};
// Act
var result = _validator.Validate(null, settings);
// Assert
result.Succeeded.Should().BeFalse();
result
.Failures.Should()
.Contain(f => f.Contains("Telegram bot token must be at least 40 characters"));
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void Validate_ShouldReturnFailure_WhenBotTokenIsNullOrWhitespace(string? botToken)
{
// Arrange
var settings = new TelegramBotSettings { BotToken = botToken! };
// Act
var result = _validator.Validate(null, settings);
// Assert
result.Succeeded.Should().BeFalse();
result.Failures.Should().Contain(f => f.Contains("Telegram bot token is required"));
}
}