/// <summary/>
    public IndexedNuGetPackageProvider(INugetRepository nugetRepository, string?appId = null)
    {
        SourceUrl    = nugetRepository.SourceUrl;
        FriendlyName = nugetRepository.FriendlyName;
        _fallback    = new NuGetPackageProvider(nugetRepository, appId);

        _ = InitializeApiAsync(appId);
    }
Exemplo n.º 2
0
    public async Task SearchAsync_WithNoString_ReturnsResults()
    {
        // Arrange
        var repository = NugetRepository.FromSourceUrl(NugetRepositoryTests.TestNugetFeed);
        var provider   = new NuGetPackageProvider(repository);

        // Act
        var packages = await provider.SearchAsync("");

        // Assert
        Assert.True(packages.Any());
    }
Exemplo n.º 3
0
    public async Task SearchAsync_WithString_ReturnsMatchingResults()
    {
        // Arrange
        var repository = NugetRepository.FromSourceUrl(NugetRepositoryTests.TestNugetFeed);
        var provider   = new NuGetPackageProvider(repository);

        // Act
        var packages = await provider.SearchAsync("Hooks");

        // Assert
        Assert.True(packages.Any());
        Assert.Contains(packages, package => package.Id.Equals("reloaded.sharedlib.hooks", StringComparison.OrdinalIgnoreCase));
    }
Exemplo n.º 4
0
    public async Task SearchAsync_CanDownloadReturnedPackage()
    {
        // Arrange
        var repository = NugetRepository.FromSourceUrl(NugetRepositoryTests.TestNugetFeed);
        var provider   = new NuGetPackageProvider(repository);

        // Act
        using var outputDirectory = new TemporaryFolderAllocation();
        var package = (await provider.SearchAsync("Hooks")).First();
        var downloadedPackagePath = await package.DownloadAsync(outputDirectory.FolderPath, null);

        // Assert
        Assert.True(Directory.Exists(downloadedPackagePath));
        Assert.True(File.Exists(Path.Combine(downloadedPackagePath, ModConfig.ConfigFileName)));
    }
    public async Task AddNuGet(string?nugetUrl, string friendlyName, int?durationMinutes = 45)
    {
        // Validate
        if (string.IsNullOrEmpty(nugetUrl))
        {
            await RespondAsync(embed : Extensions.MakeErrorEmbed("You must specify a NuGet URL"));

            return;
        }

        try
        {
            var provider = new NuGetPackageProvider(NugetRepository.FromSourceUrl(nugetUrl));

            var results = await provider.SearchAsync("", 0, 10);
            await AddSourceCommon(new SourceEntry(nugetUrl), friendlyName, durationMinutes !.Value);
        }
        catch (Exception e)
        {
            await HandleSourceError(e);
        }
    }