using JdeScoping.DataAccess.Interfaces; using JdeScoping.DataSync.Services; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using Shouldly; namespace JdeScoping.DataSync.Tests.Services; /// /// Unit tests for SearchRepository. /// Tests constructor validation and interface contract compliance. /// Integration tests with actual database are required for full coverage. /// public class SearchRepositoryTests { private readonly IDbConnectionFactory _connectionFactory; private readonly ILogger _logger; public SearchRepositoryTests() { _connectionFactory = Substitute.For(); _logger = NullLogger.Instance; } #region Constructor Tests [Fact] public void Constructor_WithNullConnectionFactory_ThrowsArgumentNullException() { // Act & Assert var exception = Should.Throw(() => new SearchRepository(null!, _logger)); exception.ParamName.ShouldBe("connectionFactory"); } [Fact] public void Constructor_WithNullLogger_ThrowsArgumentNullException() { // Act & Assert var exception = Should.Throw(() => new SearchRepository(_connectionFactory, null!)); exception.ParamName.ShouldBe("logger"); } [Fact] public void Constructor_WithValidDependencies_CreatesInstance() { // Act var repository = new SearchRepository(_connectionFactory, _logger); // Assert repository.ShouldNotBeNull(); } #endregion #region Interface Contract Tests [Fact] public void SearchRepository_ImplementsISearchRepository() { // Arrange & Act var repository = new SearchRepository(_connectionFactory, _logger); // Assert repository.ShouldBeAssignableTo(); } [Fact] public void GetNextQueuedSearchAsync_HasCorrectSignature() { // Arrange var repository = new SearchRepository(_connectionFactory, _logger); // Act - Verify method exists with correct return type var methodInfo = typeof(SearchRepository).GetMethod(nameof(SearchRepository.GetNextQueuedSearchAsync)); // Assert methodInfo.ShouldNotBeNull(); methodInfo.ReturnType.ShouldBe(typeof(Task)); } [Fact] public void ResetPartialSearchesAsync_HasCorrectSignature() { // Arrange var repository = new SearchRepository(_connectionFactory, _logger); // Act - Verify method exists with correct return type var methodInfo = typeof(SearchRepository).GetMethod(nameof(SearchRepository.ResetPartialSearchesAsync)); // Assert methodInfo.ShouldNotBeNull(); methodInfo.ReturnType.ShouldBe(typeof(Task)); } [Fact] public void StartSearchAsync_HasCorrectSignature() { // Arrange var repository = new SearchRepository(_connectionFactory, _logger); // Act - Verify method exists with correct return type var methodInfo = typeof(SearchRepository).GetMethod(nameof(SearchRepository.StartSearchAsync)); // Assert methodInfo.ShouldNotBeNull(); methodInfo.ReturnType.ShouldBe(typeof(Task)); } [Fact] public void CompleteSearchAsync_HasCorrectSignature() { // Arrange var repository = new SearchRepository(_connectionFactory, _logger); // Act - Verify method exists with correct return type var methodInfo = typeof(SearchRepository).GetMethod(nameof(SearchRepository.CompleteSearchAsync)); // Assert methodInfo.ShouldNotBeNull(); methodInfo.ReturnType.ShouldBe(typeof(Task)); } #endregion }