Skip to content

Commit

Permalink
Merge pull request #12 from tmacharia/patch-1
Browse files Browse the repository at this point in the history
Skip Count, Updates Dependencies
  • Loading branch information
tmacharia committed Mar 16, 2021
2 parents 3add9c8 + 69e5a7e commit 2fc7302
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
@@ -0,0 +1,4 @@
[*.cs]

# IDE0011: Add braces
csharp_prefer_braces = when_multiline
3 changes: 2 additions & 1 deletion Paginator.sln
Expand Up @@ -5,10 +5,11 @@ VisualStudioVersion = 16.0.29006.145
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Paginator", "src\Paginator.csproj", "{372B4525-5399-4792-BBC7-33BB8897F191}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "tests\TestCases.csproj", "{48A1CCEB-85F0-4091-8B9F-154D61AF1D5A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCases", "tests\TestCases.csproj", "{48A1CCEB-85F0-4091-8B9F-154D61AF1D5A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A9AA53E-5B35-419C-BBCA-C42DD98FBE71}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
_config.yml = _config.yml
Expand Down
20 changes: 3 additions & 17 deletions Tests/IEnumerableTests.cs
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using Paginator;
using System.Linq;
using System;
using Common;

namespace Tests
{
Expand Down Expand Up @@ -41,8 +39,8 @@ public void Empty(ICollection<Rate> Rates)
public void FuncTest(ICollection<string> nums)
{
int perpage = 5;
var result = nums.Paged(x => x.Matches("0"), 2, perpage);

var result = nums.Paged(x => x.Equals("0"), 2, perpage, x => x);
int pages = GetPages(result.TotalItems, perpage);

Assert.AreEqual(2, result.Page);
Expand All @@ -53,24 +51,12 @@ public void FuncTest(ICollection<string> nums)
[Test, TestCaseSource(typeof(Seed), "Pages")]
public void OrderByProperty(ICollection<Rate> Rates)
{
var result = Rates.ToPaginate(null, 1, 10, "Value", "desc");
var result = Rates.ToPaginate(null, 1, 10, x=>x.Value, "desc");

Assert.IsNotNull(result);
Assert.AreEqual(1, result.Page);
Assert.AreEqual(Rates.Count, result.TotalItems);
Assert.Greater(result.Items.First().Value, result.Items.Last().Value);
result.Items.ForEach(x =>
{
Console.WriteLine(x.Value);
});
}

[Test, TestCaseSource(typeof(Seed), "Pages")]
public void NullRequestTest(ICollection<Rate> list)
{
var result = list.ToPages(null);

Assert.AreEqual(1, result.Page);
}
}
}
11 changes: 1 addition & 10 deletions Tests/IQueryableTests.cs
Expand Up @@ -38,21 +38,12 @@ public void Empty(ICollection<Rate> Rates)
public void FuncTest(ICollection<Rate> Rates)
{
var result = Rates.AsQueryable()
.Paged(x => x.Value > 9, 2, 2);
.Paged(x => x.Value > 9, 2, 2, x => x.Value);

Assert.NotNull(result);
Assert.AreEqual(2, result.Page);
Assert.AreEqual(2, result.ItemsPerPage);
Assert.AreEqual(Rates.Count(x => x.Value > 9), result.TotalItems);
}

[Test, TestCaseSource(typeof(Seed), "Pages")]
public void NullRequestTest(ICollection<Rate> list)
{
var result = list.AsQueryable()
.ToPages(null);

Assert.AreEqual(1, result.Page);
}
}
}
4 changes: 2 additions & 2 deletions src/PagedResult.cs
Expand Up @@ -22,7 +22,7 @@ public class PagedResult<T>
/// </summary>
public PagedResult()
{
Items = new HashSet<T>();
Items = new List<T>();
}
/// <summary>
/// Current page in pagination
Expand All @@ -45,7 +45,7 @@ public PagedResult()
/// <summary>
/// Collection containing items in the current page.
/// </summary>
public ICollection<T> Items { get; set; }
public IList<T> Items { get; set; }

/// <summary>
/// Calculates &amp; returns the hashcode of the current object.
Expand Down
173 changes: 115 additions & 58 deletions src/Paginator.cs

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions src/Paginator.csproj
Expand Up @@ -5,7 +5,8 @@
<TargetFrameworks>
netstandard2.0;
netcoreapp3.0;netcoreapp2.0;netcoreapp2.1;
net47
<!--net47,-->
net48
</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -18,19 +19,18 @@
<RepositoryUrl>https://github.com/tmacharia/linq-paginator</RepositoryUrl>
<PackageTags>linq, pagination, list paginator, paging, list, array, collection</PackageTags>
<Description>For queries that return a lot of data, a need emerges to consume the results in chunks rather than the entire set. Consuming all results at once can be costly in terms of network traffic thus slowing down your application.
Linq Paginator allows you to run your queries and return your data in form of pages. A page contains a set number of items to return per page e.g 20. If for example you have 100 records, it will return the following object:
Linq Paginator allows you to run your queries and return your data in form of pages. A page contains a set number of items to return per page e.g 20. If for example you have 100 records, it will return the following object:
- Page: 1,
- TotalPages: 5,
- ItemsPerPage: 20,
- TotalItems: 100,
- List (collection of the first 20 records)
- Items (collection of the first 20 records)
</Description>
<PackageId>LinqPaginator</PackageId>
<Version>1.2.6</Version>
<Version>1.2.7</Version>
<NeutralLanguage>en</NeutralLanguage>
<PackageReleaseNotes>
Fixes bug/issue with pagination result:
-&gt; TotalPages is always zero
Fixes bug/issue casting.
</PackageReleaseNotes>
<PackageLicenseUrl></PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -42,12 +42,9 @@
<DocumentationFile></DocumentationFile>
</PropertyGroup>-->

<ItemGroup>
<PackageReference Include="Shared.Common" Version="1.3.5" />
</ItemGroup>

<!--Conditionally obtain references for .NET Core 1.1 target-->
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCases.csproj
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit.Console" Version="3.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit.Console" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 2fc7302

Please sign in to comment.