Files
ChatBot/ChatBot.Tests/Services/ModelServiceTests.cs
Leonid Pershin a96d4d8067 fix issues
2025-10-17 06:15:46 +03:00

61 lines
1.8 KiB
C#

using ChatBot.Models.Configuration;
using ChatBot.Services;
using ChatBot.Tests.TestUtilities;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
namespace ChatBot.Tests.Services;
public class ModelServiceTests : UnitTestBase
{
private readonly Mock<ILogger<ModelService>> _loggerMock;
private readonly Mock<IOptions<OllamaSettings>> _optionsMock;
private readonly ModelService _modelService;
public ModelServiceTests()
{
_loggerMock = TestDataBuilder.Mocks.CreateLoggerMock<ModelService>();
var ollamaSettings = TestDataBuilder.Configurations.CreateOllamaSettings();
_optionsMock = TestDataBuilder.Mocks.CreateOptionsMock(ollamaSettings);
_modelService = new ModelService(_loggerMock.Object, _optionsMock.Object);
}
[Fact]
public void GetCurrentModel_ShouldReturnDefaultModel()
{
// Act
var result = _modelService.GetCurrentModel();
// Assert
result.Should().Be("llama3.2");
}
[Fact]
public async Task InitializeAsync_ShouldLogModelInformation()
{
// Act
var act = async () => await _modelService.InitializeAsync();
// Assert
await act.Should()
.NotThrowAsync("InitializeAsync should complete without throwing exceptions");
// Verify that logging was called (at least once for model information)
_loggerMock.Verify(
x =>
x.Log(
LogLevel.Information,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString()!.Contains("model")),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()
),
Times.AtLeastOnce,
"Should log model information"
);
}
}