87 lines
2.4 KiB
C#
87 lines
2.4 KiB
C#
using ChatBot.Models.Configuration;
|
|
using ChatBot.Models.Configuration.Validators;
|
|
using FluentAssertions;
|
|
|
|
namespace ChatBot.Tests.Configuration.Validators;
|
|
|
|
public class OllamaSettingsValidatorTests
|
|
{
|
|
private readonly OllamaSettingsValidator _validator = new();
|
|
|
|
[Fact]
|
|
public void Validate_ShouldReturnSuccess_WhenSettingsAreValid()
|
|
{
|
|
// Arrange
|
|
var settings = new OllamaSettings
|
|
{
|
|
Url = "http://localhost:11434",
|
|
DefaultModel = "llama3.2",
|
|
};
|
|
|
|
// Act
|
|
var result = _validator.Validate(null, settings);
|
|
|
|
// Assert
|
|
result.Succeeded.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ShouldReturnFailure_WhenUrlIsEmpty()
|
|
{
|
|
// Arrange
|
|
var settings = new OllamaSettings { Url = "", DefaultModel = "llama3.2" };
|
|
|
|
// Act
|
|
var result = _validator.Validate(null, settings);
|
|
|
|
// Assert
|
|
result.Succeeded.Should().BeFalse();
|
|
result.Failures.Should().Contain(f => f.Contains("Ollama URL is required"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ShouldReturnFailure_WhenUrlIsInvalid()
|
|
{
|
|
// Arrange
|
|
var settings = new OllamaSettings { Url = "invalid-url", DefaultModel = "llama3.2" };
|
|
|
|
// Act
|
|
var result = _validator.Validate(null, settings);
|
|
|
|
// Assert
|
|
result.Succeeded.Should().BeFalse();
|
|
result.Failures.Should().Contain(f => f.Contains("Invalid Ollama URL format"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ShouldReturnFailure_WhenDefaultModelIsEmpty()
|
|
{
|
|
// Arrange
|
|
var settings = new OllamaSettings { Url = "http://localhost:11434", DefaultModel = "" };
|
|
|
|
// Act
|
|
var result = _validator.Validate(null, settings);
|
|
|
|
// Assert
|
|
result.Succeeded.Should().BeFalse();
|
|
result.Failures.Should().Contain(f => f.Contains("DefaultModel is required"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void Validate_ShouldReturnFailure_WhenUrlIsNullOrWhitespace(string? url)
|
|
{
|
|
// Arrange
|
|
var settings = new OllamaSettings { Url = url!, DefaultModel = "llama3.2" };
|
|
|
|
// Act
|
|
var result = _validator.Validate(null, settings);
|
|
|
|
// Assert
|
|
result.Succeeded.Should().BeFalse();
|
|
result.Failures.Should().Contain(f => f.Contains("Ollama URL is required"));
|
|
}
|
|
}
|