add tests
All checks were successful
SonarQube / Build and analyze (push) Successful in 3m54s
Unit Tests / Run Tests (push) Successful in 2m23s

This commit is contained in:
Leonid Pershin
2025-10-20 15:11:42 +03:00
parent f8fd16edb2
commit 1c910d7b7f
8 changed files with 549 additions and 154 deletions

View File

@@ -516,4 +516,33 @@ public class AIServiceTests : UnitTestBase
Times.AtLeast(3) // One for each attempt
);
}
[Fact]
public async Task GenerateChatCompletionAsync_ShouldTimeout_WhenRequestExceedsConfiguredTimeout()
{
// Arrange
var messages = TestDataBuilder.ChatMessages.CreateMessageHistory(2);
var model = "llama3.2";
_modelServiceMock.Setup(x => x.GetCurrentModel()).Returns(model);
_systemPromptServiceMock.Setup(x => x.GetSystemPromptAsync()).ReturnsAsync("System prompt");
// Configure very small timeout (not strictly needed for this simulation)
_aiSettings.RequestTimeoutSeconds = 1;
// Emulate timeout from underlying client
_ollamaClientMock
.Setup(x => x.ChatAsync(It.IsAny<OllamaSharp.Models.Chat.ChatRequest>()))
.Throws(new TimeoutException("Request timed out"));
// Act
var result = await _aiService.GenerateChatCompletionAsync(messages);
// Assert
result.Should().Be(AIResponseConstants.DefaultErrorMessage);
_ollamaClientMock.Verify(
x => x.ChatAsync(It.IsAny<OllamaSharp.Models.Chat.ChatRequest>()),
Times.Exactly(3)
);
}
}