diff --git a/ChatBot.Tests/Data/Repositories/ChatSessionRepositoryTests.cs b/ChatBot.Tests/Data/Repositories/ChatSessionRepositoryTests.cs index 192a98c..c5b9927 100644 --- a/ChatBot.Tests/Data/Repositories/ChatSessionRepositoryTests.cs +++ b/ChatBot.Tests/Data/Repositories/ChatSessionRepositoryTests.cs @@ -1,12 +1,10 @@ using ChatBot.Data; using ChatBot.Data.Interfaces; using ChatBot.Data.Repositories; -using ChatBot.Models.Entities; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Moq; diff --git a/ChatBot.Tests/Integration/ChatServiceIntegrationTests.cs b/ChatBot.Tests/Integration/ChatServiceIntegrationTests.cs index 7c70ef0..97d8791 100644 --- a/ChatBot.Tests/Integration/ChatServiceIntegrationTests.cs +++ b/ChatBot.Tests/Integration/ChatServiceIntegrationTests.cs @@ -1,15 +1,9 @@ -using System.Linq; -using ChatBot.Models; -using ChatBot.Models.Configuration; -using ChatBot.Models.Dto; using ChatBot.Services; using ChatBot.Services.Interfaces; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; using OllamaSharp.Models.Chat; diff --git a/ChatBot.Tests/Services/AIServiceTests.cs b/ChatBot.Tests/Services/AIServiceTests.cs index bb54861..daaf23c 100644 --- a/ChatBot.Tests/Services/AIServiceTests.cs +++ b/ChatBot.Tests/Services/AIServiceTests.cs @@ -1,4 +1,3 @@ -using System.Linq; using ChatBot.Common.Constants; using ChatBot.Models.Configuration; using ChatBot.Models.Dto; @@ -7,7 +6,6 @@ using ChatBot.Services.Interfaces; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; using OllamaSharp.Models.Chat; diff --git a/ChatBot.Tests/Services/ChatServiceTests.cs b/ChatBot.Tests/Services/ChatServiceTests.cs index 2149fe0..be9b408 100644 --- a/ChatBot.Tests/Services/ChatServiceTests.cs +++ b/ChatBot.Tests/Services/ChatServiceTests.cs @@ -1,12 +1,9 @@ -using ChatBot.Models; using ChatBot.Models.Configuration; -using ChatBot.Models.Dto; using ChatBot.Services; using ChatBot.Services.Interfaces; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; namespace ChatBot.Tests.Services; diff --git a/ChatBot.Tests/Services/DatabaseSessionStorageTests.cs b/ChatBot.Tests/Services/DatabaseSessionStorageTests.cs index 3d0840a..83056ff 100644 --- a/ChatBot.Tests/Services/DatabaseSessionStorageTests.cs +++ b/ChatBot.Tests/Services/DatabaseSessionStorageTests.cs @@ -1,14 +1,11 @@ using ChatBot.Data; using ChatBot.Data.Interfaces; -using ChatBot.Data.Repositories; -using ChatBot.Models; using ChatBot.Models.Entities; using ChatBot.Services; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Moq; diff --git a/ChatBot.Tests/Services/HealthChecks/OllamaHealthCheckTests.cs b/ChatBot.Tests/Services/HealthChecks/OllamaHealthCheckTests.cs index a439dfe..8aa50e3 100644 --- a/ChatBot.Tests/Services/HealthChecks/OllamaHealthCheckTests.cs +++ b/ChatBot.Tests/Services/HealthChecks/OllamaHealthCheckTests.cs @@ -1,4 +1,3 @@ -using System.Linq; using ChatBot.Models.Configuration; using ChatBot.Services.HealthChecks; using ChatBot.Services.Interfaces; @@ -8,7 +7,6 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; -using OllamaSharp.Models.Chat; namespace ChatBot.Tests.Services.HealthChecks; @@ -16,7 +14,6 @@ public class OllamaHealthCheckTests : UnitTestBase { private readonly Mock> _loggerMock; private readonly Mock _ollamaClientMock; - private readonly Mock> _optionsMock; private readonly OllamaHealthCheck _healthCheck; public OllamaHealthCheckTests() @@ -24,9 +21,6 @@ public class OllamaHealthCheckTests : UnitTestBase _loggerMock = TestDataBuilder.Mocks.CreateLoggerMock(); _ollamaClientMock = TestDataBuilder.Mocks.CreateOllamaClientMock(); - var ollamaSettings = TestDataBuilder.Configurations.CreateOllamaSettings(); - _optionsMock = TestDataBuilder.Mocks.CreateOptionsMock(ollamaSettings); - _healthCheck = new OllamaHealthCheck(_ollamaClientMock.Object, _loggerMock.Object); } diff --git a/ChatBot.Tests/Services/HealthChecks/TelegramBotHealthCheckTests.cs b/ChatBot.Tests/Services/HealthChecks/TelegramBotHealthCheckTests.cs index a5d6d03..7d62f6f 100644 --- a/ChatBot.Tests/Services/HealthChecks/TelegramBotHealthCheckTests.cs +++ b/ChatBot.Tests/Services/HealthChecks/TelegramBotHealthCheckTests.cs @@ -1,11 +1,9 @@ -using ChatBot.Models.Configuration; using ChatBot.Services.HealthChecks; using ChatBot.Services.Interfaces; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; using Telegram.Bot.Types; diff --git a/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs b/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs index 30edb66..d7496b1 100644 --- a/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs +++ b/ChatBot.Tests/Services/HistoryCompressionServiceTests.cs @@ -1,4 +1,3 @@ -using System.Linq; using ChatBot.Models.Configuration; using ChatBot.Models.Dto; using ChatBot.Services; @@ -6,7 +5,6 @@ using ChatBot.Services.Interfaces; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; using OllamaSharp.Models.Chat; diff --git a/ChatBot.Tests/Services/SystemPromptServiceTests.cs b/ChatBot.Tests/Services/SystemPromptServiceTests.cs index f8acdec..9cc1dd0 100644 --- a/ChatBot.Tests/Services/SystemPromptServiceTests.cs +++ b/ChatBot.Tests/Services/SystemPromptServiceTests.cs @@ -3,7 +3,6 @@ using ChatBot.Services; using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Moq; namespace ChatBot.Tests.Services; diff --git a/ChatBot.Tests/Telegram/Commands/ClearCommandTests.cs b/ChatBot.Tests/Telegram/Commands/ClearCommandTests.cs index 94c3429..3bdfb7c 100644 --- a/ChatBot.Tests/Telegram/Commands/ClearCommandTests.cs +++ b/ChatBot.Tests/Telegram/Commands/ClearCommandTests.cs @@ -1,11 +1,7 @@ -using ChatBot.Models; -using ChatBot.Models.Configuration; using ChatBot.Services; -using ChatBot.Services.Interfaces; using ChatBot.Services.Telegram.Commands; using ChatBot.Tests.TestUtilities; using FluentAssertions; -using Microsoft.Extensions.Logging; using Moq; namespace ChatBot.Tests.Telegram.Commands; diff --git a/ChatBot.Tests/Telegram/Commands/CommandRegistryTests.cs b/ChatBot.Tests/Telegram/Commands/CommandRegistryTests.cs index cce1fda..6d691ce 100644 --- a/ChatBot.Tests/Telegram/Commands/CommandRegistryTests.cs +++ b/ChatBot.Tests/Telegram/Commands/CommandRegistryTests.cs @@ -1,4 +1,3 @@ -using ChatBot.Services; using ChatBot.Services.Telegram.Commands; using ChatBot.Services.Telegram.Interfaces; using ChatBot.Tests.TestUtilities; diff --git a/ChatBot.Tests/Telegram/Commands/HelpCommandTests.cs b/ChatBot.Tests/Telegram/Commands/HelpCommandTests.cs index d671313..3e55412 100644 --- a/ChatBot.Tests/Telegram/Commands/HelpCommandTests.cs +++ b/ChatBot.Tests/Telegram/Commands/HelpCommandTests.cs @@ -1,4 +1,3 @@ -using ChatBot.Models.Configuration; using ChatBot.Services; using ChatBot.Services.Telegram.Commands; using ChatBot.Services.Telegram.Interfaces; @@ -6,7 +5,6 @@ using ChatBot.Tests.TestUtilities; using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; -using Telegram.Bot.Types; namespace ChatBot.Tests.Telegram.Commands; diff --git a/ChatBot.Tests/Telegram/Commands/SettingsCommandTests.cs b/ChatBot.Tests/Telegram/Commands/SettingsCommandTests.cs index 4e98f3d..49d18e7 100644 --- a/ChatBot.Tests/Telegram/Commands/SettingsCommandTests.cs +++ b/ChatBot.Tests/Telegram/Commands/SettingsCommandTests.cs @@ -4,9 +4,7 @@ using ChatBot.Services.Interfaces; using ChatBot.Services.Telegram.Commands; using ChatBot.Tests.TestUtilities; using FluentAssertions; -using Microsoft.Extensions.Logging; using Moq; -using Telegram.Bot.Types; namespace ChatBot.Tests.Telegram.Commands; diff --git a/ChatBot.Tests/Telegram/Commands/StartCommandTests.cs b/ChatBot.Tests/Telegram/Commands/StartCommandTests.cs index 7ca7902..bde404d 100644 --- a/ChatBot.Tests/Telegram/Commands/StartCommandTests.cs +++ b/ChatBot.Tests/Telegram/Commands/StartCommandTests.cs @@ -1,11 +1,8 @@ -using ChatBot.Models.Configuration; using ChatBot.Services; using ChatBot.Services.Telegram.Commands; using ChatBot.Tests.TestUtilities; using FluentAssertions; -using Microsoft.Extensions.Logging; using Moq; -using Telegram.Bot.Types; namespace ChatBot.Tests.Telegram.Commands; diff --git a/ChatBot.Tests/Telegram/Commands/StatusCommandTests.cs b/ChatBot.Tests/Telegram/Commands/StatusCommandTests.cs index 0ed09ef..b9e3ed4 100644 --- a/ChatBot.Tests/Telegram/Commands/StatusCommandTests.cs +++ b/ChatBot.Tests/Telegram/Commands/StatusCommandTests.cs @@ -1,11 +1,9 @@ -using System.Linq; using ChatBot.Models.Configuration; using ChatBot.Services; using ChatBot.Services.Interfaces; using ChatBot.Services.Telegram.Commands; using ChatBot.Tests.TestUtilities; using FluentAssertions; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using OllamaSharp.Models.Chat; diff --git a/ChatBot.Tests/TestUtilities/TestBase.cs b/ChatBot.Tests/TestUtilities/TestBase.cs index c80359e..fe18271 100644 --- a/ChatBot.Tests/TestUtilities/TestBase.cs +++ b/ChatBot.Tests/TestUtilities/TestBase.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Moq; @@ -10,6 +9,8 @@ namespace ChatBot.Tests.TestUtilities; /// public abstract class TestBase : IDisposable { + private bool _disposed; + protected IServiceProvider ServiceProvider { get; private set; } = null!; protected Mock LoggerMock { get; private set; } = null!; @@ -30,17 +31,18 @@ public abstract class TestBase : IDisposable protected abstract void ConfigureServices(IServiceCollection services); - protected virtual void Cleanup() + protected virtual void Dispose(bool disposing) { - if (ServiceProvider is IDisposable disposable) + if (!_disposed && disposing && ServiceProvider is IDisposable disposable) { disposable.Dispose(); } + _disposed = true; } public void Dispose() { - Cleanup(); + Dispose(true); GC.SuppressFinalize(this); } } diff --git a/ChatBot/Migrations/20251016214154_InitialCreate.cs b/ChatBot/Migrations/20251016214154_InitialCreate.cs index 1f433e2..f47f138 100644 --- a/ChatBot/Migrations/20251016214154_InitialCreate.cs +++ b/ChatBot/Migrations/20251016214154_InitialCreate.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable diff --git a/ChatBot/Services/DatabaseInitializationService.cs b/ChatBot/Services/DatabaseInitializationService.cs index 2eaa425..9035851 100644 --- a/ChatBot/Services/DatabaseInitializationService.cs +++ b/ChatBot/Services/DatabaseInitializationService.cs @@ -1,8 +1,5 @@ using ChatBot.Data; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace ChatBot.Services { diff --git a/ChatBot/Services/OllamaClientAdapter.cs b/ChatBot/Services/OllamaClientAdapter.cs index 39361b6..edf8a15 100644 --- a/ChatBot/Services/OllamaClientAdapter.cs +++ b/ChatBot/Services/OllamaClientAdapter.cs @@ -1,4 +1,3 @@ -using System.Net.Security; using ChatBot.Services.Interfaces; using OllamaSharp; using OllamaSharp.Models; diff --git a/ChatBot/Services/Telegram/Commands/StatusCommand.cs b/ChatBot/Services/Telegram/Commands/StatusCommand.cs index 4866c74..a728917 100644 --- a/ChatBot/Services/Telegram/Commands/StatusCommand.cs +++ b/ChatBot/Services/Telegram/Commands/StatusCommand.cs @@ -1,6 +1,4 @@ -using System.Linq; using ChatBot.Models.Configuration; -using ChatBot.Services; using ChatBot.Services.Interfaces; using Microsoft.Extensions.Options; diff --git a/ChatBot/Services/Telegram/Services/TelegramBotService.cs b/ChatBot/Services/Telegram/Services/TelegramBotService.cs index ede50d9..d06a8d4 100644 --- a/ChatBot/Services/Telegram/Services/TelegramBotService.cs +++ b/ChatBot/Services/Telegram/Services/TelegramBotService.cs @@ -1,6 +1,4 @@ using ChatBot.Services.Telegram.Interfaces; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using Telegram.Bot; using Telegram.Bot.Polling; using Telegram.Bot.Types;