diff --git a/src/ScoopSearch.Indexer.Tests/Processor/FetchBucketsProcessorTests.cs b/src/ScoopSearch.Indexer.Tests/Processor/FetchBucketsProcessorTests.cs deleted file mode 100644 index e2a4313..0000000 --- a/src/ScoopSearch.Indexer.Tests/Processor/FetchBucketsProcessorTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Text.RegularExpressions; -using FluentAssertions; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Moq; -using ScoopSearch.Indexer.Configuration; -using ScoopSearch.Indexer.GitHub; -using ScoopSearch.Indexer.Processor; -using ScoopSearch.Indexer.Tests.Helpers; -using Xunit.Abstractions; - -namespace ScoopSearch.Indexer.Tests.Processor; - -public class FetchBucketsProcessorTests : IClassFixture -{ - private readonly XUnitLogger _logger; - private readonly FetchBucketsProcessor _sut; - - public FetchBucketsProcessorTests(HostFixture hostFixture, ITestOutputHelper testOutputHelper) - { - hostFixture.Configure(testOutputHelper); - - _logger = new XUnitLogger(testOutputHelper); - _sut = new FetchBucketsProcessor( - hostFixture.Instance.Services.GetRequiredService(), - hostFixture.Instance.Services.GetRequiredService>(), - _logger); - } - - [Fact] - public async void FetchBucketsAsync_ReturnsBuckets_Succeeds() - { - // Arrange - var cancellationToken = new CancellationToken(); - var expectedOfficialBucketsCount = 10; - var expectedAtLeastBucketsCount = 1400; - - // Act - var result = await _sut.FetchBucketsAsync(cancellationToken); - - // Assert - result.Should().HaveCountGreaterOrEqualTo(expectedAtLeastBucketsCount); - result.Should().OnlyHaveUniqueItems(_ => _.Uri.AbsoluteUri.ToLowerInvariant()); - - _logger.Should().Log(LogLevel.Information, "Retrieving buckets from sources"); - _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, $"Found {expectedOfficialBucketsCount} official buckets.+")); - _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, @"Found \d{4} buckets on GitHub")); - _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, @"Found \d+ buckets to ignore \(appsettings\.json\)")); - _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, @"Found \d+ buckets to add \(appsettings\.json\)")); - _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, @"Found \d+ buckets to add from external list.+")); - _logger.Should().Log(LogLevel.Debug, _ => _.StartsWith("Adding bucket"), Times.AtLeast(expectedAtLeastBucketsCount)); - _logger.Should().Log(LogLevel.Debug, _ => _.StartsWith("Adding bucket 'https://github.com/ScoopInstaller/Main'")); - _logger.Should().Log(LogLevel.Debug, _ => _.StartsWith("Adding bucket 'https://github.com/ScoopInstaller/Extras'")); - } -} diff --git a/src/ScoopSearch.Indexer.Tests/ScoopSearch.Indexer.Tests.csproj b/src/ScoopSearch.Indexer.Tests/ScoopSearch.Indexer.Tests.csproj index 7a6a38a..d73bd9d 100644 --- a/src/ScoopSearch.Indexer.Tests/ScoopSearch.Indexer.Tests.csproj +++ b/src/ScoopSearch.Indexer.Tests/ScoopSearch.Indexer.Tests.csproj @@ -19,8 +19,4 @@ - - - - diff --git a/src/ScoopSearch.Indexer.Tests/ScoopSearchIndexerTests.cs b/src/ScoopSearch.Indexer.Tests/ScoopSearchIndexerTests.cs new file mode 100644 index 0000000..5d4f787 --- /dev/null +++ b/src/ScoopSearch.Indexer.Tests/ScoopSearchIndexerTests.cs @@ -0,0 +1,70 @@ +using System.Text.RegularExpressions; +using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Moq; +using ScoopSearch.Indexer.Buckets; +using ScoopSearch.Indexer.Buckets.Sources; +using ScoopSearch.Indexer.Configuration; +using ScoopSearch.Indexer.Data; +using ScoopSearch.Indexer.Processor; +using ScoopSearch.Indexer.Tests.Helpers; +using Xunit.Abstractions; + +namespace ScoopSearch.Indexer.Tests; + +public class ScoopSearchIndexerTests : IClassFixture +{ + private readonly Mock _indexingProcessorMock; + private readonly XUnitLogger _logger; + private readonly ScoopSearchIndexer _sut; + + public ScoopSearchIndexerTests(HostFixture hostFixture, ITestOutputHelper testOutputHelper) + { + hostFixture.Configure(testOutputHelper); + + _indexingProcessorMock = new Mock(); + + var fetchManifestsProcessorMock = new Mock(); + fetchManifestsProcessorMock + .Setup(x => x.FetchManifestsAsync(It.IsAny(), It.IsAny())) + .Returns(AsyncEnumerable.Empty()); + + _logger = new XUnitLogger(testOutputHelper); + _sut = new ScoopSearchIndexer( + hostFixture.Instance.Services.GetRequiredService>(), + hostFixture.Instance.Services.GetRequiredService(), + fetchManifestsProcessorMock.Object, + _indexingProcessorMock.Object, + hostFixture.Instance.Services.GetRequiredService>(), + _logger); + } + + [Fact] + public async void ExecuteAsync_ReturnsBuckets_Succeeds() + { + // Arrange + const int expectedAtLeastBucketsCount = 1500; + var cancellationToken = new CancellationToken(); + Uri[]? actualBucketsUris = null; + _indexingProcessorMock + .Setup(x => x.CleanIndexFromNonExistentBucketsAsync(It.IsAny(), cancellationToken)) + .Returns(Task.CompletedTask) + .Callback((uris, _) => actualBucketsUris = uris) + .Verifiable(); + + // Act + await _sut.ExecuteAsync(cancellationToken); + + // Assert + _indexingProcessorMock.Verify(); + actualBucketsUris.Should().HaveCountGreaterThan(expectedAtLeastBucketsCount); + actualBucketsUris.Should().OnlyHaveUniqueItems(_ => _.AbsoluteUri.ToLowerInvariant()); + + _logger.Should().Log(LogLevel.Information, _ => Regex.IsMatch(_, @"Found \d+ buckets for a total of \d+ manifests.")); + _logger.Should().Log(LogLevel.Information, _ => _.StartsWith("Processed bucket "), Times.AtLeast(expectedAtLeastBucketsCount)); + _logger.Should().Log(LogLevel.Information, _ => _.StartsWith("Processed bucket https://github.com/ScoopInstaller/Main")); + _logger.Should().Log(LogLevel.Information, _ => _.StartsWith("Processed bucket https://github.com/ScoopInstaller/Extras")); + } +}