Ejemplo n.º 1
0
    /// <inheritdoc />
    public async Task <IEnumerable <IDownloadablePackage> > SearchAsync(string text, int skip = 0, int take = 50, CancellationToken token = default)
    {
        int page       = (skip / take) + 1;
        var gbApiItems = take > MaxItemsPerApiRequest ?
                         await GetMoreThenMaxAsync(text, take, page) :
                         await GameBananaMod.GetByNameAllCategoriesAsync(text, GameId, page, take);

        var results = new ConcurrentBag <IDownloadablePackage>();

        if (gbApiItems.Count <= 0)
        {
            return(results);
        }

        var getExtraDataTasks = new Task[gbApiItems.Count];

        for (var x = 0; x < gbApiItems.Count; x++)
        {
            getExtraDataTasks[x] = AddResultsForApiResult(gbApiItems[x], results);
        }

        await Task.WhenAll(getExtraDataTasks);

        return(results);
    }
Ejemplo n.º 2
0
    public async Task Search_WithSingleChar_DoesNotThrow()
    {
        var result = await GameBananaMod.GetByNameAllCategoriesAsync("u", 7486, 0, 10);

        // Assert
        Assert.True(result.Count > 0);
    }
Ejemplo n.º 3
0
    public async Task Search_ByGame_ReturnsAllResults()
    {
        var result = await GameBananaMod.GetByNameAllCategoriesAsync("", 7486, 0, 10);

        // Assert
        Assert.True(result.Count > 0);
        Assert.Contains(result, mod => mod.Name.Contains("Update Lib. Test"));
    }
Ejemplo n.º 4
0
    public async Task Search_WithString_ReturnsTestLibrary()
    {
        var result = await GameBananaMod.GetByNameAllCategoriesAsync("Update Lib. Test", 7486, 0, 10);

        // Assert
        Assert.Single(result);
        Assert.True(result[0].Files.Count > 0);
    }
Ejemplo n.º 5
0
    private async Task <List <GameBananaMod> > GetMoreThenMaxAsync(string text, int take, int page)
    {
        var asyncPulls = new Task <List <GameBananaMod> > [(take / MaxItemsPerApiRequest) + 1];

        for (int x = 0; x < asyncPulls.Length; x++)
        {
            asyncPulls[x] = GameBananaMod.GetByNameAllCategoriesAsync(text, GameId, page + x, MaxItemsPerApiRequest);
        }

        await Task.WhenAll(asyncPulls);

        // Note: Due to site bugs with uploaded files, can't trust GameBanana with not returning empty or null.
        // Merge
        var result = asyncPulls[0].Result;

        for (int x = 1; x < asyncPulls.Length; x++)
        {
            result.AddRange(asyncPulls[x].Result);
        }

        return(result);
    }
Ejemplo n.º 6
0
    public async Task Search_ReturnsModManagerIntegrations()
    {
        var result = await GameBananaMod.GetByNameAllCategoriesAsync("Update Lib. Test", 7486, 0, 10);

        // Assert
        var integration = result ![0].ManagerIntegrations !.First();