add tests

This commit is contained in:
Leonid Pershin
2025-10-17 05:47:18 +03:00
parent f7e3024e7e
commit 03eb0f22a2
41 changed files with 4001 additions and 30 deletions

View File

@@ -0,0 +1,76 @@
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"));
}
}