From a96d4d80672a0898447284ba81ca3325b0abc234 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Fri, 17 Oct 2025 06:15:46 +0300 Subject: [PATCH] fix issues --- .../HistoryCompressionServiceTests.cs | 4 +--- ChatBot.Tests/Services/ModelServiceTests.cs | 20 ++++++++++++++++--- .../TestUtilities/TestDataBuilder.cs | 6 +++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs b/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs index 5deb067..30edb66 100644 --- a/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs +++ b/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs @@ -173,9 +173,7 @@ public class HistoryCompressionServiceTests : UnitTestBase ); } - private static IAsyncEnumerable ThrowAsyncEnumerable( - Exception exception - ) + private static ThrowingAsyncEnumerable ThrowAsyncEnumerable(Exception exception) { return new ThrowingAsyncEnumerable(exception); } diff --git a/ChatBot.Tests/Services/ModelServiceTests.cs b/ChatBot.Tests/Services/ModelServiceTests.cs index 81cb00b..41be3f3 100644 --- a/ChatBot.Tests/Services/ModelServiceTests.cs +++ b/ChatBot.Tests/Services/ModelServiceTests.cs @@ -37,10 +37,24 @@ public class ModelServiceTests : UnitTestBase public async Task InitializeAsync_ShouldLogModelInformation() { // Act - await _modelService.InitializeAsync(); + var act = async () => await _modelService.InitializeAsync(); // Assert - // The method should complete without throwing exceptions - // In a real test, we might verify logging calls + 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(), + It.Is((v, t) => v.ToString()!.Contains("model")), + It.IsAny(), + It.IsAny>() + ), + Times.AtLeastOnce, + "Should log model information" + ); } } diff --git a/ChatBot.Tests/TestUtilities/TestDataBuilder.cs b/ChatBot.Tests/TestUtilities/TestDataBuilder.cs index c9b0b93..a1fa04f 100644 --- a/ChatBot.Tests/TestUtilities/TestDataBuilder.cs +++ b/ChatBot.Tests/TestUtilities/TestDataBuilder.cs @@ -156,16 +156,16 @@ public static class TestDataBuilder .Returns( (chatId, chatType, chatTitle) => { - if (!sessions.ContainsKey(chatId)) + if (!sessions.TryGetValue(chatId, out var session)) { - var session = TestDataBuilder.ChatSessions.CreateBasicSession( + session = TestDataBuilder.ChatSessions.CreateBasicSession( chatId, chatType ); session.ChatTitle = chatTitle; sessions[chatId] = session; } - return sessions[chatId]; + return session; } );