From f092e6b0324b3fc701ce2aa8b3fe0208f60c9d08 Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Tue, 18 Apr 2017 22:58:14 -0500 Subject: [PATCH 01/10] bye-bye project.json --- PaginableCollections.sln | 13 +++---- global.json | 6 --- .../PaginableCollections.csproj | 35 +++++++++++++++++ .../PaginableCollections.xproj | 25 ------------ .../Properties/AssemblyInfo.cs | 9 ++--- src/PaginableCollections/project.json | 24 ------------ .../PaginableCollections.Tests.csproj | 38 +++++++++++++++++++ .../PaginableCollections.Tests.xproj | 22 ----------- tests/PaginableCollections.Tests/project.json | 14 ------- 9 files changed, 82 insertions(+), 104 deletions(-) delete mode 100644 global.json create mode 100644 src/PaginableCollections/PaginableCollections.csproj delete mode 100644 src/PaginableCollections/PaginableCollections.xproj delete mode 100644 src/PaginableCollections/project.json create mode 100644 tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj delete mode 100644 tests/PaginableCollections.Tests/PaginableCollections.Tests.xproj delete mode 100644 tests/PaginableCollections.Tests/project.json diff --git a/PaginableCollections.sln b/PaginableCollections.sln index 8eaa476..3d29d6a 100644 --- a/PaginableCollections.sln +++ b/PaginableCollections.sln @@ -1,20 +1,19 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B15992BA-EB0A-4096-BA64-A7E1B7F6FA32}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PaginableCollections", "src\PaginableCollections\PaginableCollections.xproj", "{8F6C7555-710F-443F-A5CA-BF50FC37484D}" -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PaginableCollections.Tests", "tests\PaginableCollections.Tests\PaginableCollections.Tests.xproj", "{1834508B-44C8-44AD-83F2-19ACEE028AAF}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50BAA0E6-841D-4678-9679-38A2A3456F60}" ProjectSection(SolutionItems) = preProject build.ps1 = build.ps1 - global.json = global.json EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaginableCollections", "src\PaginableCollections\PaginableCollections.csproj", "{8F6C7555-710F-443F-A5CA-BF50FC37484D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaginableCollections.Tests", "tests\PaginableCollections.Tests\PaginableCollections.Tests.csproj", "{1834508B-44C8-44AD-83F2-19ACEE028AAF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/global.json b/global.json deleted file mode 100644 index 564162d..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-preview2-003121" - } -} \ No newline at end of file diff --git a/src/PaginableCollections/PaginableCollections.csproj b/src/PaginableCollections/PaginableCollections.csproj new file mode 100644 index 0000000..ae6e685 --- /dev/null +++ b/src/PaginableCollections/PaginableCollections.csproj @@ -0,0 +1,35 @@ + + + + A light weight pagination framework + Copyright Nicholas Myers + 2.0.1 + Nicholas Myers + net45;netstandard1.3 + PaginableCollections + PaginableCollections + paginable;page;paging;queryable;collections;paginablecollections + https://github.com/neekgreen/PaginableCollections + git + git://github.com/neekgreen/paginablecollections + 1.6.0 + false + false + false + false + false + false + false + false + + + + + + + + + + + + diff --git a/src/PaginableCollections/PaginableCollections.xproj b/src/PaginableCollections/PaginableCollections.xproj deleted file mode 100644 index 8dff99a..0000000 --- a/src/PaginableCollections/PaginableCollections.xproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 8f6c7555-710f-443f-a5ca-bf50fc37484d - PaginableCollections - .\obj - .\bin\ - v4.5 - - - 2.0 - - - - - - - - - \ No newline at end of file diff --git a/src/PaginableCollections/Properties/AssemblyInfo.cs b/src/PaginableCollections/Properties/AssemblyInfo.cs index 830830e..a9e3ed4 100644 --- a/src/PaginableCollections/Properties/AssemblyInfo.cs +++ b/src/PaginableCollections/Properties/AssemblyInfo.cs @@ -1,15 +1,12 @@ using System.Reflection; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. [assembly: AssemblyTitle("PaginableCollections")] [assembly: AssemblyDescription("A light weight pagination framework.")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("PaginableCollections")] [assembly: AssemblyProduct("PaginableCollections")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("2.0.*")] +[assembly: AssemblyVersion("3.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] \ No newline at end of file diff --git a/src/PaginableCollections/project.json b/src/PaginableCollections/project.json deleted file mode 100644 index 35f41a9..0000000 --- a/src/PaginableCollections/project.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "2.0.1", - "authors": [ "Nicholas Myers" ], - "copyright": "Copyright Nicholas Myers", - "description": "A light weight pagination framework", - "packOptions": { - "tags": [ "paginable", "page", "paging", "queryable", "collections", "paginablecollections" ], - "projectUrl": "https://github.com/neekgreen/PaginableCollections", - "repository": { - "type": "git", - "url": "git://github.com/neekgreen/paginablecollections" - } - }, - - "frameworks": { - "net45": {}, - "netstandard1.3": { - "dependencies": { - "NETStandard.Library": "1.6.0", - "System.Linq.Queryable": "4.0.1" - } - } - } -} diff --git a/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj new file mode 100644 index 0000000..7c4ab3a --- /dev/null +++ b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj @@ -0,0 +1,38 @@ + + + + net451 + PaginableCollections.Tests + PaginableCollections.Tests + true + false + false + false + false + false + false + false + false + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/PaginableCollections.Tests/PaginableCollections.Tests.xproj b/tests/PaginableCollections.Tests/PaginableCollections.Tests.xproj deleted file mode 100644 index e217210..0000000 --- a/tests/PaginableCollections.Tests/PaginableCollections.Tests.xproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 1834508b-44c8-44ad-83f2-19acee028aaf - PaginableCollections.Tests - .\obj - .\bin\ - v4.5 - - - 2.0 - - - - - - \ No newline at end of file diff --git a/tests/PaginableCollections.Tests/project.json b/tests/PaginableCollections.Tests/project.json deleted file mode 100644 index 1a653ac..0000000 --- a/tests/PaginableCollections.Tests/project.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "dependencies": { - "PaginableCollections": { - "target": "project" - }, - "FluentAssertions": "4.9.1", - "NUnit": "3.4.1", - "dotnet-test-nunit": "3.4.0-beta-2" - }, - "testRunner": "nunit", - "frameworks": { - "net451": {} - } -} \ No newline at end of file From d76f2adfddad51e222ca159eaccaed7c5692314b Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Tue, 18 Apr 2017 23:09:23 -0500 Subject: [PATCH 02/10] new stuff --- .../EnumerableExtensions.cs | 7 +- src/PaginableCollections/IPager.cs | 12 ++++ src/PaginableCollections/IPagerItem.cs | 14 ++++ src/PaginableCollections/IPaginable.cs | 27 ++++--- src/PaginableCollections/IPaginableItem.cs | 8 +++ ...IPaginableInfo.cs => IPaginableRequest.cs} | 2 +- src/PaginableCollections/PagerItem.cs | 20 ++++++ src/PaginableCollections/Paginable.cs | 45 ++++++------ .../PaginableCollections.csproj | 1 + .../PaginableExtensions.cs | 8 ++- src/PaginableCollections/PaginableItem.cs | 16 +++++ .../{PaginableInfo.cs => PaginableRequest.cs} | 4 +- .../Properties/AssemblyInfo.cs | 2 +- .../QueryableBasedPaginable.cs | 30 ++++++-- src/PaginableCollections/StaticPager.cs | 58 +++++++++++++++ src/PaginableCollections/StaticPaginable.cs | 20 +++++- .../EmptyPaginableTests.cs | 2 - ... EnumerableStaticPaginableRequestTests.cs} | 8 +-- .../EnumerableStaticPaginableTests.cs | 6 +- .../PagerItemTests.cs | 72 +++++++++++++++++++ ...eInfoTests.cs => PaginableRequestTests.cs} | 10 ++- ...s.cs => QueryablePaginableRequestTests.cs} | 8 +-- .../QueryablePaginableTests.cs | 13 +++- .../StaticPagerTests.cs | 15 ++++ .../StaticPaginableTests.cs | 14 +++- 25 files changed, 353 insertions(+), 69 deletions(-) create mode 100644 src/PaginableCollections/IPager.cs create mode 100644 src/PaginableCollections/IPagerItem.cs create mode 100644 src/PaginableCollections/IPaginableItem.cs rename src/PaginableCollections/{IPaginableInfo.cs => IPaginableRequest.cs} (80%) create mode 100644 src/PaginableCollections/PagerItem.cs create mode 100644 src/PaginableCollections/PaginableItem.cs rename src/PaginableCollections/{PaginableInfo.cs => PaginableRequest.cs} (71%) create mode 100644 src/PaginableCollections/StaticPager.cs rename tests/PaginableCollections.Tests/{EnumerableStaticPaginableInfoTests.cs => EnumerableStaticPaginableRequestTests.cs} (74%) create mode 100644 tests/PaginableCollections.Tests/PagerItemTests.cs rename tests/PaginableCollections.Tests/{PaginableInfoTests.cs => PaginableRequestTests.cs} (66%) rename tests/PaginableCollections.Tests/{QueryablePaginableInfoTests.cs => QueryablePaginableRequestTests.cs} (75%) create mode 100644 tests/PaginableCollections.Tests/StaticPagerTests.cs diff --git a/src/PaginableCollections/EnumerableExtensions.cs b/src/PaginableCollections/EnumerableExtensions.cs index 71e1a47..acff959 100644 --- a/src/PaginableCollections/EnumerableExtensions.cs +++ b/src/PaginableCollections/EnumerableExtensions.cs @@ -1,6 +1,5 @@ namespace PaginableCollections { - using System; using System.Collections.Generic; using System.Linq; @@ -14,14 +13,14 @@ public static IPaginable ToPaginable(this IEnumerable enumerable, int p .ToPaginable(pageNumber, itemCountPerPage); } - public static IPaginable ToPaginable(this IEnumerable enumerable, IPaginableInfo paginableInfo) + public static IPaginable ToPaginable(this IEnumerable enumerable, IPaginableRequest paginableRequest) { return enumerable - .ToPaginable(paginableInfo.PageNumber, paginableInfo.ItemCountPerPage); + .ToPaginable(paginableRequest.PageNumber, paginableRequest.ItemCountPerPage); } - public static IPaginable ToStaticPaginable(this IEnumerable enumerable, int pageNumber, int itemCountPerPage, int totalItemCount) + public static IPaginable ToPaginable(this IEnumerable enumerable, int pageNumber, int itemCountPerPage, int totalItemCount) { //# If enumerable is EF Queryable instance, a '.ToList()' will force it to execute the SQL. return new StaticPaginable(enumerable.ToList(), pageNumber, itemCountPerPage, totalItemCount); diff --git a/src/PaginableCollections/IPager.cs b/src/PaginableCollections/IPager.cs new file mode 100644 index 0000000..952db0c --- /dev/null +++ b/src/PaginableCollections/IPager.cs @@ -0,0 +1,12 @@ +namespace PaginableCollections +{ + using System.Collections.Generic; + + public interface IPager + { + IEnumerable GetPages(); + + int TotalPageCount { get; } + int MaximumPageNumberCount { get; } + } +} \ No newline at end of file diff --git a/src/PaginableCollections/IPagerItem.cs b/src/PaginableCollections/IPagerItem.cs new file mode 100644 index 0000000..75531ef --- /dev/null +++ b/src/PaginableCollections/IPagerItem.cs @@ -0,0 +1,14 @@ +namespace PaginableCollections +{ + public interface IPagerItem + { + int PageNumber { get; } + int TotalPageCount { get; } + + bool IsFirstPage { get; } + bool IsLastPage { get; } + + bool HasPreviousPage { get; } + bool HasNextPage { get; } + } +} \ No newline at end of file diff --git a/src/PaginableCollections/IPaginable.cs b/src/PaginableCollections/IPaginable.cs index 7b641fa..d443056 100644 --- a/src/PaginableCollections/IPaginable.cs +++ b/src/PaginableCollections/IPaginable.cs @@ -1,13 +1,12 @@ namespace PaginableCollections { - using System; + using System.Collections; using System.Collections.Generic; - using System.Linq; /// /// Non-generic contract representing a page of data. /// - public interface IPaginable + public interface IPaginable : IEnumerable { /// /// Total number of pages. @@ -30,38 +29,48 @@ public interface IPaginable int ItemCountPerPage { get; } /// - /// + /// Identifies the first page. /// bool IsFirstPage { get; } /// - /// + /// Identifies the last page. /// bool IsLastPage { get; } /// - /// + /// Identifies if there is a previous page. /// bool HasPreviousPage { get; } /// - /// + /// Identifies if there is a next page. /// bool HasNextPage { get; } + + /// + /// The first item number of the page. + /// + int FirstItemNumber { get; } + + /// + /// The last item number of this page. + /// + int LastItemNumber { get; } } /// /// Generic contract representing a page of data. /// /// - public interface IPaginable : IEnumerable, IPaginable + public interface IPaginable : IEnumerable>, IPaginable { /// /// /// /// /// - T this[int index] { get; } + IPaginableItem this[int index] { get; } /// /// Number of items in this paginable. diff --git a/src/PaginableCollections/IPaginableItem.cs b/src/PaginableCollections/IPaginableItem.cs new file mode 100644 index 0000000..3717894 --- /dev/null +++ b/src/PaginableCollections/IPaginableItem.cs @@ -0,0 +1,8 @@ +namespace PaginableCollections +{ + public interface IPaginableItem + { + T Item { get; } + int ItemNumber { get; } + } +} \ No newline at end of file diff --git a/src/PaginableCollections/IPaginableInfo.cs b/src/PaginableCollections/IPaginableRequest.cs similarity index 80% rename from src/PaginableCollections/IPaginableInfo.cs rename to src/PaginableCollections/IPaginableRequest.cs index 8bb4212..f39b6f3 100644 --- a/src/PaginableCollections/IPaginableInfo.cs +++ b/src/PaginableCollections/IPaginableRequest.cs @@ -3,7 +3,7 @@ using System; using System.Linq; - public interface IPaginableInfo + public interface IPaginableRequest { int PageNumber { get; } int ItemCountPerPage { get; } diff --git a/src/PaginableCollections/PagerItem.cs b/src/PaginableCollections/PagerItem.cs new file mode 100644 index 0000000..7de0262 --- /dev/null +++ b/src/PaginableCollections/PagerItem.cs @@ -0,0 +1,20 @@ +namespace PaginableCollections +{ + public class PagerItem: IPagerItem + { + public PagerItem(int pageNumber, int totalPageCount) + { + this.PageNumber = pageNumber; + this.TotalPageCount = totalPageCount; + } + + public int PageNumber { get; private set; } + public int TotalPageCount { get; private set; } + + public bool IsFirstPage => PageNumber == 1; + public bool IsLastPage => PageNumber >= TotalPageCount; + + public bool HasPreviousPage => PageNumber > 1; + public bool HasNextPage => PageNumber < TotalPageCount; + } +} \ No newline at end of file diff --git a/src/PaginableCollections/Paginable.cs b/src/PaginableCollections/Paginable.cs index ba8b0f0..49971b4 100644 --- a/src/PaginableCollections/Paginable.cs +++ b/src/PaginableCollections/Paginable.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; + using System.Linq; /// /// Base class represents page of items. @@ -10,22 +11,18 @@ /// The type of items in this paginable. public abstract class Paginable : IPaginable { - protected readonly List innerList = new List(); + protected readonly List> innerList = new List>(); /// /// /// /// - public IEnumerator GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { return innerList.GetEnumerator(); } - /// - /// - /// - /// - IEnumerator IEnumerable.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return innerList.GetEnumerator(); } @@ -50,46 +47,48 @@ IEnumerator IEnumerable.GetEnumerator() /// /// /// - public T this[int index] { get { return innerList[index]; } } + IPaginableItem IPaginable.this[int index] => innerList[index]; /// /// Number of items in this result set. /// - public int Count { get { return innerList.Count; } } + public int Count => innerList.Count; /// /// Total number of pages. /// - public int TotalPageCount - { - get - { - return - TotalItemCount > 0 - ? (int)Math.Ceiling(TotalItemCount / (double)this.ItemCountPerPage) - : 0; - } - } + public int TotalPageCount => + TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)this.ItemCountPerPage) : 0; /// /// Identifies the first page. /// - public bool IsFirstPage { get { return PageNumber == 1; } } + public bool IsFirstPage => PageNumber == 1; /// /// Identifies the last page. /// - public bool IsLastPage { get { return PageNumber >= TotalPageCount; } } + public bool IsLastPage => PageNumber >= TotalPageCount; /// /// Identifies if a previous page is available. /// - public bool HasPreviousPage { get { return PageNumber > 1; } } + public bool HasPreviousPage => PageNumber > 1; /// /// Identifies if a next page is available. /// - public bool HasNextPage { get { return PageNumber < TotalPageCount; } } + public bool HasNextPage => PageNumber < TotalPageCount; + + /// + /// Identifies the first item number of the page. + /// + public int FirstItemNumber { get; protected set; } + + /// + /// Identifies the last item number of the page. + /// + public int LastItemNumber { get; protected set; } } diff --git a/src/PaginableCollections/PaginableCollections.csproj b/src/PaginableCollections/PaginableCollections.csproj index ae6e685..355a5f7 100644 --- a/src/PaginableCollections/PaginableCollections.csproj +++ b/src/PaginableCollections/PaginableCollections.csproj @@ -21,6 +21,7 @@ false false false + True diff --git a/src/PaginableCollections/PaginableExtensions.cs b/src/PaginableCollections/PaginableExtensions.cs index d1ddb1b..39c6c4d 100644 --- a/src/PaginableCollections/PaginableExtensions.cs +++ b/src/PaginableCollections/PaginableExtensions.cs @@ -25,9 +25,15 @@ public static IPaginable ToPaginable(this IQueryable queryable, int pag /// /// /// - public static IPaginable ToPaginable(this IQueryable queryable, IPaginableInfo paginableInfo) + public static IPaginable ToPaginable(this IQueryable queryable, IPaginableRequest paginableInfo) { return queryable.ToPaginable(paginableInfo.PageNumber, paginableInfo.ItemCountPerPage); } + + + public static IPager ToPager(this IPaginable paginable, int maximumPageNumberCount) + { + return new StaticPager(paginable, maximumPageNumberCount); + } } } \ No newline at end of file diff --git a/src/PaginableCollections/PaginableItem.cs b/src/PaginableCollections/PaginableItem.cs new file mode 100644 index 0000000..b8f0b91 --- /dev/null +++ b/src/PaginableCollections/PaginableItem.cs @@ -0,0 +1,16 @@ +namespace PaginableCollections +{ + public class PaginableItem : IPaginableItem + { + private PaginableItem() { } + + public PaginableItem(T item, int itemNumber) + { + this.Item = item; + this.ItemNumber = itemNumber; + } + + public T Item { get; private set; } + public int ItemNumber { get; private set; } + } +} \ No newline at end of file diff --git a/src/PaginableCollections/PaginableInfo.cs b/src/PaginableCollections/PaginableRequest.cs similarity index 71% rename from src/PaginableCollections/PaginableInfo.cs rename to src/PaginableCollections/PaginableRequest.cs index c82a079..ce5e4d9 100644 --- a/src/PaginableCollections/PaginableInfo.cs +++ b/src/PaginableCollections/PaginableRequest.cs @@ -3,9 +3,9 @@ using System; using System.Linq; - public class PaginableInfo : IPaginableInfo + public class PaginableRequest : IPaginableRequest { - public PaginableInfo(int pageNumber, int itemCountPerPage) + public PaginableRequest(int pageNumber, int itemCountPerPage) { this.PageNumber = pageNumber; this.ItemCountPerPage = itemCountPerPage; diff --git a/src/PaginableCollections/Properties/AssemblyInfo.cs b/src/PaginableCollections/Properties/AssemblyInfo.cs index a9e3ed4..764c26f 100644 --- a/src/PaginableCollections/Properties/AssemblyInfo.cs +++ b/src/PaginableCollections/Properties/AssemblyInfo.cs @@ -9,4 +9,4 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("3.0.0")] -[assembly: AssemblyInformationalVersion("1.1.0")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("3.0.0")] \ No newline at end of file diff --git a/src/PaginableCollections/QueryableBasedPaginable.cs b/src/PaginableCollections/QueryableBasedPaginable.cs index 2e8f56e..b2336e3 100644 --- a/src/PaginableCollections/QueryableBasedPaginable.cs +++ b/src/PaginableCollections/QueryableBasedPaginable.cs @@ -19,10 +19,10 @@ public class QueryableBasedPaginable : Paginable public QueryableBasedPaginable(IQueryable queryable, int pageNumber, int itemCountPerPage) { if (pageNumber < 1) - throw new ArgumentOutOfRangeException("pageNumber"); + throw new ArgumentOutOfRangeException(nameof(pageNumber)); if (itemCountPerPage < 1) - throw new ArgumentOutOfRangeException("itemCountPerPage"); + throw new ArgumentOutOfRangeException(nameof(ItemCountPerPage)); this.TotalItemCount = queryable == null ? 0 : queryable.Count(); this.PageNumber = pageNumber; @@ -31,8 +31,11 @@ public QueryableBasedPaginable(IQueryable queryable, int pageNumber, int item if (queryable != null && TotalItemCount > 0) innerList.AddRange( pageNumber == 1 - ? queryable.Skip(0).Take(ItemCountPerPage).ToList() - : queryable.Skip((pageNumber - 1) * ItemCountPerPage).Take(ItemCountPerPage).ToList()); + ? queryable.Skip(0).Take(ItemCountPerPage).ToPaginableItemList(pageNumber, itemCountPerPage) + : queryable.Skip((pageNumber - 1) * ItemCountPerPage).Take(ItemCountPerPage).ToPaginableItemList(pageNumber, itemCountPerPage)); + + this.FirstItemNumber = innerList.First().ItemNumber; + this.LastItemNumber = innerList.Last().ItemNumber; } /// @@ -44,4 +47,23 @@ public QueryableBasedPaginable(IQueryable queryable, int pageNumber, int item public QueryableBasedPaginable(IEnumerable superset, int pageNumber, int itemCountPerPage) : this(superset.AsQueryable(), pageNumber, itemCountPerPage) { } } + + + + + + public static class Something + { + public static IEnumerable> ToPaginableItemList(this IEnumerable t, int pageNumber, int itemCountPerPage) + { + var offset = (pageNumber - 1) * itemCountPerPage; + var list = t.ToList(); + + for (var i = 0; i < t.Count(); i++) + { + yield return new PaginableItem(list[i], offset + 1); + offset++; + } + } + } } \ No newline at end of file diff --git a/src/PaginableCollections/StaticPager.cs b/src/PaginableCollections/StaticPager.cs new file mode 100644 index 0000000..29a3e9a --- /dev/null +++ b/src/PaginableCollections/StaticPager.cs @@ -0,0 +1,58 @@ +namespace PaginableCollections +{ + using System.Collections.Generic; + using System.Linq; + + public class StaticPager : IPager + { + private readonly IList pages; + + public StaticPager(IPaginable paginable, int maximumPageNumberCount) + { + + this.MaximumPageNumberCount = maximumPageNumberCount; + this.TotalPageCount = paginable.TotalPageCount; + + var firstPageToDisplay = 1; + var lastPageToDisplay = paginable.TotalPageCount; + var pageNumbersToDisplay = lastPageToDisplay; + + if (paginable.TotalPageCount > maximumPageNumberCount) + { + var maxPageNumbersToDisplay = maximumPageNumberCount; + firstPageToDisplay = paginable.PageNumber - maxPageNumbersToDisplay / 2; + if (firstPageToDisplay < 1) + { + firstPageToDisplay = 1; + } + pageNumbersToDisplay = maxPageNumbersToDisplay; + lastPageToDisplay = firstPageToDisplay + pageNumbersToDisplay - 1; + if (lastPageToDisplay > paginable.TotalPageCount) + { + firstPageToDisplay = paginable.TotalPageCount - maxPageNumbersToDisplay + 1; + } + } + + var totalPageNumber = paginable.TotalPageCount; + if (totalPageNumber == 0) + { + totalPageNumber = 1; + } + + pages = new List(); + + for (int i = firstPageToDisplay; i <= firstPageToDisplay + pageNumbersToDisplay - 1; i++) + { + pages.Add(new PagerItem(i, totalPageNumber)); + } + } + + IEnumerable IPager.GetPages() + { + return pages; + } + + public int TotalPageCount { get; private set; } + public int MaximumPageNumberCount { get; private set; } + } +} \ No newline at end of file diff --git a/src/PaginableCollections/StaticPaginable.cs b/src/PaginableCollections/StaticPaginable.cs index 16a42ae..1f4f178 100644 --- a/src/PaginableCollections/StaticPaginable.cs +++ b/src/PaginableCollections/StaticPaginable.cs @@ -20,16 +20,30 @@ public class StaticPaginable : Paginable public StaticPaginable(IEnumerable subset, int pageNumber, int itemCountPerPage, int totalItemCount) { if (pageNumber < 1) - throw new ArgumentOutOfRangeException("pageNumber"); + throw new ArgumentOutOfRangeException(nameof(pageNumber)); if (itemCountPerPage < 1) - throw new ArgumentOutOfRangeException("itemCountPerPage"); + throw new ArgumentOutOfRangeException(nameof(itemCountPerPage)); + + if (subset.Count() > totalItemCount) + throw new ArgumentOutOfRangeException(nameof(totalItemCount)); this.TotalItemCount = totalItemCount; this.PageNumber = pageNumber; this.ItemCountPerPage = itemCountPerPage; - this.innerList.AddRange(subset); + this.innerList.AddRange(subset.ToPaginableItemList(pageNumber, itemCountPerPage)); + + if (innerList.Any()) + { + this.FirstItemNumber = innerList.First().ItemNumber; + this.LastItemNumber = innerList.Last().ItemNumber; + } + else + { + this.FirstItemNumber = 0; + this.LastItemNumber = 0; + } } } } \ No newline at end of file diff --git a/tests/PaginableCollections.Tests/EmptyPaginableTests.cs b/tests/PaginableCollections.Tests/EmptyPaginableTests.cs index fa03176..d3126fc 100644 --- a/tests/PaginableCollections.Tests/EmptyPaginableTests.cs +++ b/tests/PaginableCollections.Tests/EmptyPaginableTests.cs @@ -1,7 +1,5 @@ namespace PaginableCollections.Tests { - using System; - using System.Linq; using FluentAssertions; using NUnit.Framework; diff --git a/tests/PaginableCollections.Tests/EnumerableStaticPaginableInfoTests.cs b/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs similarity index 74% rename from tests/PaginableCollections.Tests/EnumerableStaticPaginableInfoTests.cs rename to tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs index d4a49cb..f796ebb 100644 --- a/tests/PaginableCollections.Tests/EnumerableStaticPaginableInfoTests.cs +++ b/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs @@ -5,15 +5,15 @@ using FluentAssertions; using NUnit.Framework; - [TestFixture, Category("PaginableInfo")] - public class EnumerableStaticPaginableInfoTests + [TestFixture, Category("PaginableRequest")] + public class EnumerableStaticPaginableRequestTests { [Test] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50); var expectedPageNumber = 2; - var paginableInfo = new PaginableInfo(expectedPageNumber, 10); + var paginableInfo = new PaginableRequest(expectedPageNumber, 10); var sut = source.ToPaginable(paginableInfo); @@ -25,7 +25,7 @@ public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100); var expectedItemCountPerPage = 12; - var paginableInfo = new PaginableInfo(2, expectedItemCountPerPage); + var paginableInfo = new PaginableRequest(2, expectedItemCountPerPage); var sut = source.ToPaginable(paginableInfo); diff --git a/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs b/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs index d00d4d9..e2c85b0 100644 --- a/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs +++ b/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs @@ -14,7 +14,7 @@ public void ShouldEqualPageNumber() var source = Enumerable.Range(11, 20); var expectedPageNumber = 2; - var sut = source.ToStaticPaginable(expectedPageNumber, 10, 100); + var sut = source.ToPaginable(expectedPageNumber, 10, 100); sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } @@ -25,7 +25,7 @@ public void ShouldEqualItemCountPerPage() var source = Enumerable.Range(11, 20); var expectedItemCountPerPage = 12; - var sut = source.ToStaticPaginable(2, expectedItemCountPerPage, 100); + var sut = source.ToPaginable(2, expectedItemCountPerPage, 100); sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } @@ -36,7 +36,7 @@ public void ShouldEqualTotalItemCount() var expectedTotalItemCount = 25; var source = Enumerable.Range(11, expectedTotalItemCount); - var sut = source.ToStaticPaginable(2, 10, expectedTotalItemCount); + var sut = source.ToPaginable(2, 10, expectedTotalItemCount); sut.TotalItemCount.ShouldBeEquivalentTo(expectedTotalItemCount); } diff --git a/tests/PaginableCollections.Tests/PagerItemTests.cs b/tests/PaginableCollections.Tests/PagerItemTests.cs new file mode 100644 index 0000000..c927983 --- /dev/null +++ b/tests/PaginableCollections.Tests/PagerItemTests.cs @@ -0,0 +1,72 @@ +namespace PaginableCollections.Tests +{ + using FluentAssertions; + using NUnit.Framework; + + [TestFixture] + public class StaticPagerPageTests + { + [Test] + public void ShouldSetPageNumber() + { + var pageNumber = 1; + var sut = new PagerItem(pageNumber, 10); + + sut.PageNumber.ShouldBeEquivalentTo(pageNumber); + } + + [Test] + public void ShouldSetIsFirstPage() + { + var pageNumber = 1; + var sut = new PagerItem(pageNumber, 10); + + sut.IsFirstPage.ShouldBeEquivalentTo(true); + } + + [Test] + public void ShouldSetIsPreviousPage() + { + var pageNumber = 1; + var sut = new PagerItem(pageNumber, 10); + + sut.HasPreviousPage.ShouldBeEquivalentTo(false); + } + + [Test] + public void ShouldSetHasNextPage() + { + var pageNumber = 1; + var sut = new PagerItem(pageNumber, 10); + + sut.HasNextPage.ShouldBeEquivalentTo(true); + } + + [Test] + public void ShouldSetTotalPageCount() + { + var totalPageCount = 1; + var sut = new PagerItem(1, totalPageCount); + + sut.TotalPageCount.ShouldBeEquivalentTo(totalPageCount); + } + + [Test] + public void ShouldBeLastPage() + { + var totalPageCount = 10; + var sut = new PagerItem(totalPageCount, totalPageCount); + + sut.IsLastPage.ShouldBeEquivalentTo(true); + } + + [Test] + public void ShouldBeHasNextPage() + { + var totalPageCount = 10; + var sut = new PagerItem(totalPageCount, totalPageCount); + + sut.HasNextPage.ShouldBeEquivalentTo(false); + } + } +} diff --git a/tests/PaginableCollections.Tests/PaginableInfoTests.cs b/tests/PaginableCollections.Tests/PaginableRequestTests.cs similarity index 66% rename from tests/PaginableCollections.Tests/PaginableInfoTests.cs rename to tests/PaginableCollections.Tests/PaginableRequestTests.cs index 9f4d86b..8b03b84 100644 --- a/tests/PaginableCollections.Tests/PaginableInfoTests.cs +++ b/tests/PaginableCollections.Tests/PaginableRequestTests.cs @@ -1,18 +1,16 @@ namespace PaginableCollections.Tests { - using System; - using System.Linq; using FluentAssertions; using NUnit.Framework; - [TestFixture, Category("PaginableInfo")] - public class PaginableInfoTests + [TestFixture, Category("PaginableRequest")] + public class PaginableRequestTests { [Test] public void ShouldEqualPageNumber() { var expectedPageNumber = 2; - var sut = new PaginableInfo(expectedPageNumber, 10); + var sut = new PaginableRequest(expectedPageNumber, 10); sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } @@ -21,7 +19,7 @@ public void ShouldEqualPageNumber() public void ShouldEqualItemCountPerPage() { var expectedItemCountPerPage = 12; - var sut = new PaginableInfo(2, expectedItemCountPerPage); + var sut = new PaginableRequest(2, expectedItemCountPerPage); sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } diff --git a/tests/PaginableCollections.Tests/QueryablePaginableInfoTests.cs b/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs similarity index 75% rename from tests/PaginableCollections.Tests/QueryablePaginableInfoTests.cs rename to tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs index 95acb3d..ece2a10 100644 --- a/tests/PaginableCollections.Tests/QueryablePaginableInfoTests.cs +++ b/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs @@ -5,15 +5,15 @@ using FluentAssertions; using NUnit.Framework; - [TestFixture, Category("PaginableInfo")] - public class QueryablePaginableInfoTests + [TestFixture, Category("PaginableRequest")] + public class QueryablePaginableRequestTests { [Test] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50).AsQueryable(); var expectedPageNumber = 2; - var paginableInfo = new PaginableInfo(expectedPageNumber, 10); + var paginableInfo = new PaginableRequest(expectedPageNumber, 10); var sut = source.ToPaginable(paginableInfo); @@ -25,7 +25,7 @@ public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100).AsQueryable(); var expectedItemCountPerPage = 12; - var paginableInfo = new PaginableInfo(2, expectedItemCountPerPage); + var paginableInfo = new PaginableRequest(2, expectedItemCountPerPage); var sut = source.ToPaginable(paginableInfo); diff --git a/tests/PaginableCollections.Tests/QueryablePaginableTests.cs b/tests/PaginableCollections.Tests/QueryablePaginableTests.cs index f27bedd..30530a8 100644 --- a/tests/PaginableCollections.Tests/QueryablePaginableTests.cs +++ b/tests/PaginableCollections.Tests/QueryablePaginableTests.cs @@ -1,6 +1,5 @@ namespace PaginableCollections.Tests { - using System; using System.Linq; using FluentAssertions; using NUnit.Framework; @@ -40,5 +39,17 @@ public void ShouldEqualTotalItemCount() sut.TotalItemCount.ShouldBeEquivalentTo(expectedTotalItemCount); } + + [Test] + public void ShouldEqualFirstElementNextPage() + { + var source = Enumerable.Range(1, 100).AsQueryable(); + var paginable = new QueryableBasedPaginable(source, 3, 10); + + var sut = paginable.ElementAt(0); + + sut.ItemNumber.ShouldBeEquivalentTo(21); + sut.Item.ShouldBeEquivalentTo(21); + } } } \ No newline at end of file diff --git a/tests/PaginableCollections.Tests/StaticPagerTests.cs b/tests/PaginableCollections.Tests/StaticPagerTests.cs new file mode 100644 index 0000000..1e321c1 --- /dev/null +++ b/tests/PaginableCollections.Tests/StaticPagerTests.cs @@ -0,0 +1,15 @@ +namespace PaginableCollections.Tests +{ + using System.Linq; + using NUnit.Framework; + + [TestFixture] + public class StaticPagerTest + { + [Test] + public void ShouldNotBeNull() + { + var sut = Enumerable.Range(1, 10).ToPaginable(1, 5).ToPager(2); + } + } +} \ No newline at end of file diff --git a/tests/PaginableCollections.Tests/StaticPaginableTests.cs b/tests/PaginableCollections.Tests/StaticPaginableTests.cs index 8967c40..04c2a6e 100644 --- a/tests/PaginableCollections.Tests/StaticPaginableTests.cs +++ b/tests/PaginableCollections.Tests/StaticPaginableTests.cs @@ -14,7 +14,7 @@ public void ShouldEqualPageNumber() var source = Enumerable.Range(11, 20); var expectedPageNumber = 2; - var sut = new StaticPaginable(source, expectedPageNumber, 10, 100); + IPaginable sut = new StaticPaginable(source, expectedPageNumber, 10, 100); sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } @@ -40,5 +40,17 @@ public void ShouldEqualTotalItemCount() sut.TotalItemCount.ShouldBeEquivalentTo(expectedTotalItemCount); } + + [Test] + public void ShouldEqualFirstElementNextPage() + { + var source = Enumerable.Range(1, 100); + var paginable = new StaticPaginable(source, 3, 10, 100); + + var sut = paginable.ElementAt(0); + + sut.ItemNumber.ShouldBeEquivalentTo(21); + sut.Item.ShouldBeEquivalentTo(1); + } } } \ No newline at end of file From b908572c6cf9023a6379eab259a78bc830f3874d Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Wed, 19 Apr 2017 13:58:15 -0500 Subject: [PATCH 03/10] bug fixes --- .../PaginableExtensions.cs | 28 ++++++++++++++++- .../QueryableBasedPaginable.cs | 31 ++++++------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/PaginableCollections/PaginableExtensions.cs b/src/PaginableCollections/PaginableExtensions.cs index 39c6c4d..81eba4a 100644 --- a/src/PaginableCollections/PaginableExtensions.cs +++ b/src/PaginableCollections/PaginableExtensions.cs @@ -1,6 +1,7 @@ namespace PaginableCollections { using System; + using System.Collections.Generic; using System.Linq; public static class PaginableExtensions @@ -30,10 +31,35 @@ public static IPaginable ToPaginable(this IQueryable queryable, IPagina return queryable.ToPaginable(paginableInfo.PageNumber, paginableInfo.ItemCountPerPage); } - + /// + /// + /// + /// + /// + /// public static IPager ToPager(this IPaginable paginable, int maximumPageNumberCount) { return new StaticPager(paginable, maximumPageNumberCount); } + + /// + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable> ToPaginableItemList(this IEnumerable t, int pageNumber, int itemCountPerPage) + { + var offset = (pageNumber - 1) * itemCountPerPage; + var list = t.ToList(); + + for (var i = 0; i < t.Count(); i++) + { + yield return new PaginableItem(list[i], offset + 1); + offset++; + } + } } } \ No newline at end of file diff --git a/src/PaginableCollections/QueryableBasedPaginable.cs b/src/PaginableCollections/QueryableBasedPaginable.cs index b2336e3..f3ee812 100644 --- a/src/PaginableCollections/QueryableBasedPaginable.cs +++ b/src/PaginableCollections/QueryableBasedPaginable.cs @@ -34,8 +34,16 @@ public QueryableBasedPaginable(IQueryable queryable, int pageNumber, int item ? queryable.Skip(0).Take(ItemCountPerPage).ToPaginableItemList(pageNumber, itemCountPerPage) : queryable.Skip((pageNumber - 1) * ItemCountPerPage).Take(ItemCountPerPage).ToPaginableItemList(pageNumber, itemCountPerPage)); - this.FirstItemNumber = innerList.First().ItemNumber; - this.LastItemNumber = innerList.Last().ItemNumber; + if (innerList.Any()) + { + this.FirstItemNumber = innerList.First().ItemNumber; + this.LastItemNumber = innerList.Last().ItemNumber; + } + else + { + this.FirstItemNumber = 0; + this.LastItemNumber = 0; + } } /// @@ -47,23 +55,4 @@ public QueryableBasedPaginable(IQueryable queryable, int pageNumber, int item public QueryableBasedPaginable(IEnumerable superset, int pageNumber, int itemCountPerPage) : this(superset.AsQueryable(), pageNumber, itemCountPerPage) { } } - - - - - - public static class Something - { - public static IEnumerable> ToPaginableItemList(this IEnumerable t, int pageNumber, int itemCountPerPage) - { - var offset = (pageNumber - 1) * itemCountPerPage; - var list = t.ToList(); - - for (var i = 0; i < t.Count(); i++) - { - yield return new PaginableItem(list[i], offset + 1); - offset++; - } - } - } } \ No newline at end of file From c158262e2f196b4e6c5f7bec1be0c1a050d55784 Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Thu, 20 Apr 2017 22:22:15 -0500 Subject: [PATCH 04/10] add cake build --- build.cake | 68 +++++++++++++++++ build.ps1 | 215 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 237 insertions(+), 46 deletions(-) create mode 100644 build.cake diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..056bc17 --- /dev/null +++ b/build.cake @@ -0,0 +1,68 @@ +#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0 +////////////////////////////////////////////////////////////////////// +// ARGUMENTS +////////////////////////////////////////////////////////////////////// + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); + +////////////////////////////////////////////////////////////////////// +// PREPARATION +////////////////////////////////////////////////////////////////////// + +// Define directories. +var buildDir = Directory("./src/PaginableCollections/bin") + Directory(configuration); +var outputDir = Directory("./artifacts"); + +var buildSettings = new DotNetCoreBuildSettings + { + Framework = "netcoreapp1.1", + Configuration = "Release", + OutputDirectory = buildDir + }; + +////////////////////////////////////////////////////////////////////// +// TASKS +////////////////////////////////////////////////////////////////////// + +Task("Clean") + .Does(() => +{ + CleanDirectory(buildDir); +}); + +Task("Restore-NuGet-Packages") + .IsDependentOn("Clean") + .Does(() => +{ + DotNetCoreRestore("./PaginableCollections.sln"); +}); + +Task("Build") + .IsDependentOn("Restore-NuGet-Packages") + .Does(() => +{ +DotNetCoreBuild("./src/PaginableCollections/PaginableCollections.csproj"); +}); + +Task("Run-Unit-Tests") + .IsDependentOn("Build") + .Does(() => +{ + NUnit3("./tests/**/bin/" + configuration + "/**/*.Tests.dll", new NUnit3Settings { + NoResults = true + }); +}); + +////////////////////////////////////////////////////////////////////// +// TASK TARGETS +////////////////////////////////////////////////////////////////////// + +Task("Default") + .IsDependentOn("Run-Unit-Tests"); + +////////////////////////////////////////////////////////////////////// +// EXECUTION +////////////////////////////////////////////////////////////////////// + +RunTarget(target); diff --git a/build.ps1 b/build.ps1 index 5819689..3a8ef5c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,66 +1,189 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + <# + .SYNOPSIS - You can add this to you build script to ensure that psbuild is available before calling - Invoke-MSBuild. If psbuild is not available locally it will be downloaded automatically. +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +http://cakebuild.net + #> -function EnsurePsbuildInstalled{ - [cmdletbinding()] - param( - [string]$psbuildInstallUri = 'https://raw.githubusercontent.com/ligershark/psbuild/master/src/GetPSBuild.ps1' - ) - process{ - if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){ - 'Installing psbuild from [{0}]' -f $psbuildInstallUri | Write-Verbose - (new-object Net.WebClient).DownloadString($psbuildInstallUri) | iex - } - else{ - 'psbuild already loaded, skipping download' | Write-Verbose - } - # make sure it's loaded and throw if not - if(-not (Get-Command "Invoke-MsBuild" -errorAction SilentlyContinue)){ - throw ('Unable to install/load psbuild from [{0}]' -f $psbuildInstallUri) +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() } } } -# Taken from psake https://github.com/psake/psake +Write-Host "Preparing to run build script..." -<# -.SYNOPSIS - This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode - to see if an error occcured. If an error is detected then an exception is thrown. - This function allows you to run command-line programs without having to - explicitly check the $lastexitcode variable. -.EXAMPLE - exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" -#> -function Exec -{ - [CmdletBinding()] - param( - [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, - [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) - ) - & $cmd - if ($lastexitcode -ne 0) { - throw ("Exec: " + $errorMessage) +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." } } -if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} -EnsurePsbuildInstalled +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} -exec { & dotnet restore } +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE -Invoke-MSBuild +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR -$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe + } -exec { & dotnet test .\tests\PaginableCollections.Tests -c Release } + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" -exec { & dotnet pack .\src\PaginableCollections -c Release -o .\artifacts --version-suffix=$revision } + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location +} +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE \ No newline at end of file From 51efaf18991c563cf821aad30e0e5e74ec687135 Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Wed, 19 Apr 2017 15:32:25 -0500 Subject: [PATCH 05/10] now using xunit and moved to dotnetcore test project --- .../EmptyPaginableTests.cs | 9 ++++---- .../EnumerableQueryablePaginableTests.cs | 10 ++++----- .../EnumerableStaticPaginableRequestTests.cs | 8 +++---- .../EnumerableStaticPaginableTests.cs | 10 ++++----- .../PagerItemTests.cs | 21 +++++++++---------- .../PaginableCollections.Tests.csproj | 8 +++---- .../PaginableRequestTests.cs | 7 +++---- .../QueryablePaginableRequestTests.cs | 8 +++---- .../QueryablePaginableTests.cs | 15 +++++++------ .../StaticPagerTests.cs | 5 ++--- .../StaticPaginableTests.cs | 16 +++++++------- 11 files changed, 51 insertions(+), 66 deletions(-) diff --git a/tests/PaginableCollections.Tests/EmptyPaginableTests.cs b/tests/PaginableCollections.Tests/EmptyPaginableTests.cs index d3126fc..4295e96 100644 --- a/tests/PaginableCollections.Tests/EmptyPaginableTests.cs +++ b/tests/PaginableCollections.Tests/EmptyPaginableTests.cs @@ -1,12 +1,11 @@ namespace PaginableCollections.Tests { using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("EmptyPaginable")] public class EmptyPaginableTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var expectedPageNumber = 1; @@ -15,7 +14,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var expectedItemCountPerPage = EmptyPaginable.DefaultItemCountPerPage; @@ -24,7 +23,7 @@ public void ShouldEqualItemCountPerPage() sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } - [Test] + [Fact] public void ShouldEqualTotalItemCount() { var expectedTotalItemCount = 0; diff --git a/tests/PaginableCollections.Tests/EnumerableQueryablePaginableTests.cs b/tests/PaginableCollections.Tests/EnumerableQueryablePaginableTests.cs index 1c6734e..25188a3 100644 --- a/tests/PaginableCollections.Tests/EnumerableQueryablePaginableTests.cs +++ b/tests/PaginableCollections.Tests/EnumerableQueryablePaginableTests.cs @@ -1,14 +1,12 @@ namespace PaginableCollections.Tests { - using System; using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("QueryablePaginable")] public class EnumerableQueryablePaginableTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50); @@ -19,7 +17,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100); @@ -30,7 +28,7 @@ public void ShouldEqualItemCountPerPage() sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } - [Test] + [Fact] public void ShouldEqualTotalItemCount() { var expectedTotalItemCount = 25; diff --git a/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs b/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs index f796ebb..d94ca0b 100644 --- a/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs +++ b/tests/PaginableCollections.Tests/EnumerableStaticPaginableRequestTests.cs @@ -1,14 +1,12 @@ namespace PaginableCollections.Tests { - using System; using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("PaginableRequest")] public class EnumerableStaticPaginableRequestTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50); @@ -20,7 +18,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100); diff --git a/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs b/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs index e2c85b0..8fe4fa2 100644 --- a/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs +++ b/tests/PaginableCollections.Tests/EnumerableStaticPaginableTests.cs @@ -1,14 +1,12 @@ namespace PaginableCollections.Tests { - using System; using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("StaticPaginable")] public class EnumerableStaticPaginableTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(11, 20); @@ -19,7 +17,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 20); @@ -30,7 +28,7 @@ public void ShouldEqualItemCountPerPage() sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } - [Test] + [Fact] public void ShouldEqualTotalItemCount() { var expectedTotalItemCount = 25; diff --git a/tests/PaginableCollections.Tests/PagerItemTests.cs b/tests/PaginableCollections.Tests/PagerItemTests.cs index c927983..e6b341a 100644 --- a/tests/PaginableCollections.Tests/PagerItemTests.cs +++ b/tests/PaginableCollections.Tests/PagerItemTests.cs @@ -1,12 +1,11 @@ -namespace PaginableCollections.Tests +namespace PaginableCollections.Facts { using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture] - public class StaticPagerPageTests + public class StaticPagerPageFacts { - [Test] + [Fact] public void ShouldSetPageNumber() { var pageNumber = 1; @@ -15,7 +14,7 @@ public void ShouldSetPageNumber() sut.PageNumber.ShouldBeEquivalentTo(pageNumber); } - [Test] + [Fact] public void ShouldSetIsFirstPage() { var pageNumber = 1; @@ -24,7 +23,7 @@ public void ShouldSetIsFirstPage() sut.IsFirstPage.ShouldBeEquivalentTo(true); } - [Test] + [Fact] public void ShouldSetIsPreviousPage() { var pageNumber = 1; @@ -33,7 +32,7 @@ public void ShouldSetIsPreviousPage() sut.HasPreviousPage.ShouldBeEquivalentTo(false); } - [Test] + [Fact] public void ShouldSetHasNextPage() { var pageNumber = 1; @@ -42,7 +41,7 @@ public void ShouldSetHasNextPage() sut.HasNextPage.ShouldBeEquivalentTo(true); } - [Test] + [Fact] public void ShouldSetTotalPageCount() { var totalPageCount = 1; @@ -51,7 +50,7 @@ public void ShouldSetTotalPageCount() sut.TotalPageCount.ShouldBeEquivalentTo(totalPageCount); } - [Test] + [Fact] public void ShouldBeLastPage() { var totalPageCount = 10; @@ -60,7 +59,7 @@ public void ShouldBeLastPage() sut.IsLastPage.ShouldBeEquivalentTo(true); } - [Test] + [Fact] public void ShouldBeHasNextPage() { var totalPageCount = 10; diff --git a/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj index 7c4ab3a..01ab32e 100644 --- a/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj +++ b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj @@ -1,7 +1,7 @@  - net451 + netcoreapp1.1 PaginableCollections.Tests PaginableCollections.Tests true @@ -21,9 +21,9 @@ - - - + + + diff --git a/tests/PaginableCollections.Tests/PaginableRequestTests.cs b/tests/PaginableCollections.Tests/PaginableRequestTests.cs index 8b03b84..af745db 100644 --- a/tests/PaginableCollections.Tests/PaginableRequestTests.cs +++ b/tests/PaginableCollections.Tests/PaginableRequestTests.cs @@ -1,12 +1,11 @@ namespace PaginableCollections.Tests { using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("PaginableRequest")] public class PaginableRequestTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var expectedPageNumber = 2; @@ -15,7 +14,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var expectedItemCountPerPage = 12; diff --git a/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs b/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs index ece2a10..5ee33be 100644 --- a/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs +++ b/tests/PaginableCollections.Tests/QueryablePaginableRequestTests.cs @@ -1,14 +1,12 @@ namespace PaginableCollections.Tests { - using System; using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("PaginableRequest")] public class QueryablePaginableRequestTests { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50).AsQueryable(); @@ -20,7 +18,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100).AsQueryable(); diff --git a/tests/PaginableCollections.Tests/QueryablePaginableTests.cs b/tests/PaginableCollections.Tests/QueryablePaginableTests.cs index 30530a8..cea1836 100644 --- a/tests/PaginableCollections.Tests/QueryablePaginableTests.cs +++ b/tests/PaginableCollections.Tests/QueryablePaginableTests.cs @@ -1,13 +1,12 @@ -namespace PaginableCollections.Tests +namespace PaginableCollections.Facts { using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("QueryablePaginable")] - public class QueryablePaginableTests + public class QueryablePaginableFacts { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(10, 50).AsQueryable(); @@ -18,7 +17,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 100).AsQueryable(); @@ -29,7 +28,7 @@ public void ShouldEqualItemCountPerPage() sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } - [Test] + [Fact] public void ShouldEqualTotalItemCount() { var expectedTotalItemCount = 25; @@ -40,7 +39,7 @@ public void ShouldEqualTotalItemCount() sut.TotalItemCount.ShouldBeEquivalentTo(expectedTotalItemCount); } - [Test] + [Fact] public void ShouldEqualFirstElementNextPage() { var source = Enumerable.Range(1, 100).AsQueryable(); diff --git a/tests/PaginableCollections.Tests/StaticPagerTests.cs b/tests/PaginableCollections.Tests/StaticPagerTests.cs index 1e321c1..665856e 100644 --- a/tests/PaginableCollections.Tests/StaticPagerTests.cs +++ b/tests/PaginableCollections.Tests/StaticPagerTests.cs @@ -1,12 +1,11 @@ namespace PaginableCollections.Tests { using System.Linq; - using NUnit.Framework; + using Xunit; - [TestFixture] public class StaticPagerTest { - [Test] + [Fact] public void ShouldNotBeNull() { var sut = Enumerable.Range(1, 10).ToPaginable(1, 5).ToPager(2); diff --git a/tests/PaginableCollections.Tests/StaticPaginableTests.cs b/tests/PaginableCollections.Tests/StaticPaginableTests.cs index 04c2a6e..bf97e0d 100644 --- a/tests/PaginableCollections.Tests/StaticPaginableTests.cs +++ b/tests/PaginableCollections.Tests/StaticPaginableTests.cs @@ -1,14 +1,12 @@ -namespace PaginableCollections.Tests +namespace PaginableCollections.Facts { - using System; using System.Linq; using FluentAssertions; - using NUnit.Framework; + using Xunit; - [TestFixture, Category("StaticPaginable")] - public class StaticPaginableTests + public class StaticPaginableFacts { - [Test] + [Fact] public void ShouldEqualPageNumber() { var source = Enumerable.Range(11, 20); @@ -19,7 +17,7 @@ public void ShouldEqualPageNumber() sut.PageNumber.ShouldBeEquivalentTo(expectedPageNumber); } - [Test] + [Fact] public void ShouldEqualItemCountPerPage() { var source = Enumerable.Range(11, 20); @@ -30,7 +28,7 @@ public void ShouldEqualItemCountPerPage() sut.ItemCountPerPage.ShouldBeEquivalentTo(expectedItemCountPerPage); } - [Test] + [Fact] public void ShouldEqualTotalItemCount() { var expectedTotalItemCount = 25; @@ -41,7 +39,7 @@ public void ShouldEqualTotalItemCount() sut.TotalItemCount.ShouldBeEquivalentTo(expectedTotalItemCount); } - [Test] + [Fact] public void ShouldEqualFirstElementNextPage() { var source = Enumerable.Range(1, 100); From 7ce55c2b0f51390ffc7b7a1d568a69ae00d5803e Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Fri, 21 Apr 2017 12:28:51 -0500 Subject: [PATCH 06/10] build updates --- PaginableCollections.sln | 5 +- build.cake | 113 +++++++++++------- build.sh | 93 ++++++++++++++ .../PaginableCollections.csproj | 9 +- .../PaginableCollections.Tests.csproj | 6 +- 5 files changed, 174 insertions(+), 52 deletions(-) create mode 100644 build.sh diff --git a/PaginableCollections.sln b/PaginableCollections.sln index 3d29d6a..c61cea7 100644 --- a/PaginableCollections.sln +++ b/PaginableCollections.sln @@ -1,13 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.10 +VisualStudioVersion = 15.0.26403.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B15992BA-EB0A-4096-BA64-A7E1B7F6FA32}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50BAA0E6-841D-4678-9679-38A2A3456F60}" ProjectSection(SolutionItems) = preProject - build.ps1 = build.ps1 + appveyor.yml = appveyor.yml + build.cake = build.cake EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaginableCollections", "src\PaginableCollections\PaginableCollections.csproj", "{8F6C7555-710F-443F-A5CA-BF50FC37484D}" diff --git a/build.cake b/build.cake index 056bc17..275db40 100644 --- a/build.cake +++ b/build.cake @@ -1,68 +1,89 @@ -#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0 -////////////////////////////////////////////////////////////////////// -// ARGUMENTS -////////////////////////////////////////////////////////////////////// +//#addin nuget:?package=Cake.AppVeyor -var target = Argument("target", "Default"); -var configuration = Argument("configuration", "Release"); +var target = Argument("Target", "Default"); -////////////////////////////////////////////////////////////////////// -// PREPARATION -////////////////////////////////////////////////////////////////////// +// Configuration - The build configuration (Debug/Release) to use. +// 1. If command line parameter parameter passed, use that. +// 2. Otherwise if an Environment variable exists, use that. +var configuration = "Release"; + // HasArgument("Configuration") ? Argument("Configuration") : + //EnvironmentVariable("Configuration") != null ? EnvironmentVariable("BuildNumber") : "Release"; -// Define directories. -var buildDir = Directory("./src/PaginableCollections/bin") + Directory(configuration); -var outputDir = Directory("./artifacts"); -var buildSettings = new DotNetCoreBuildSettings - { - Framework = "netcoreapp1.1", - Configuration = "Release", - OutputDirectory = buildDir - }; +var buildNumber = + HasArgument("BuildNumber") ? Argument("BuildNumber") : + AppVeyor.IsRunningOnAppVeyor ? AppVeyor.Environment.Build.Number : + EnvironmentVariable("BuildNumber") != null ? int.Parse(EnvironmentVariable("BuildNumber")) : 1; -////////////////////////////////////////////////////////////////////// -// TASKS -////////////////////////////////////////////////////////////////////// +var artifactsDirectory = Directory("./artifacts"); Task("Clean") .Does(() => -{ - CleanDirectory(buildDir); -}); + { + CleanDirectory(artifactsDirectory); + }); -Task("Restore-NuGet-Packages") +Task("Restore") .IsDependentOn("Clean") .Does(() => -{ - DotNetCoreRestore("./PaginableCollections.sln"); -}); + { + DotNetCoreRestore(); + }); Task("Build") - .IsDependentOn("Restore-NuGet-Packages") + .IsDependentOn("Restore") .Does(() => -{ -DotNetCoreBuild("./src/PaginableCollections/PaginableCollections.csproj"); -}); + { + var projects = GetFiles("./**/*.csproj"); + foreach(var project in projects) + { + DotNetCoreBuild( + project.GetDirectory().FullPath, + new DotNetCoreBuildSettings() + { + Configuration = configuration + }); + } + }); -Task("Run-Unit-Tests") +Task("Test") .IsDependentOn("Build") .Does(() => -{ - NUnit3("./tests/**/bin/" + configuration + "/**/*.Tests.dll", new NUnit3Settings { - NoResults = true - }); -}); + { + var projects = GetFiles("./tests/**/*.csproj"); + foreach(var project in projects) + { + DotNetCoreTest( + project.FullPath, + new DotNetCoreTestSettings() + { + Configuration = configuration, + NoBuild = true + }); + } + }); + +Task("Pack") + .IsDependentOn("Test") + .Does(() => + { + var projects = GetFiles("./src/**/*.csproj"); + foreach (var project in projects) + { + DotNetCorePack( + project.GetDirectory().FullPath, + new DotNetCorePackSettings() + { + Configuration = configuration, + OutputDirectory = artifactsDirectory, + }); + } + }); -////////////////////////////////////////////////////////////////////// -// TASK TARGETS -////////////////////////////////////////////////////////////////////// Task("Default") - .IsDependentOn("Run-Unit-Tests"); + .IsDependentOn("Pack"); + -////////////////////////////////////////////////////////////////////// -// EXECUTION -////////////////////////////////////////////////////////////////////// -RunTarget(target); +RunTarget(target); \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..db0efb7 --- /dev/null +++ b/build.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +########################################################################## +# This is the Cake bootstrapper script for Linux and OS X. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +NUGET_URL=https://dist.nuget.org/win-x86-commandline/latest/nuget.exe +CAKE_VERSION=0.19.4 +CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe + +# Define default arguments. +TARGET="Travis" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +########################################################################### +# INSTALL .NET CORE CLI +########################################################################### + +echo "Installing .NET CLI..." +if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then + mkdir "$SCRIPT_DIR/.dotnet" +fi +curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.sh +sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version 1.0.0-preview2-003121 --install-dir .dotnet --no-path +export PATH="$SCRIPT_DIR/.dotnet":$PATH +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +"$SCRIPT_DIR/.dotnet/dotnet" --info + +########################################################################### +# INSTALL NUGET +########################################################################### + +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" $NUGET_URL + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +########################################################################### +# INSTALL CAKE +########################################################################### + +if [ ! -f "$CAKE_EXE" ]; then + mono "$NUGET_EXE" install Cake -Version $CAKE_VERSION -OutputDirectory "$TOOLS_DIR" + if [ $? -ne 0 ]; then + echo "An error occured while installing Cake." + exit 1 + fi +fi + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_EXE" ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### + +# Start Cake +exec mono "$CAKE_EXE" build.cake --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" \ No newline at end of file diff --git a/src/PaginableCollections/PaginableCollections.csproj b/src/PaginableCollections/PaginableCollections.csproj index 355a5f7..bdfafde 100644 --- a/src/PaginableCollections/PaginableCollections.csproj +++ b/src/PaginableCollections/PaginableCollections.csproj @@ -3,7 +3,7 @@ A light weight pagination framework Copyright Nicholas Myers - 2.0.1 + 3.0.0 Nicholas Myers net45;netstandard1.3 PaginableCollections @@ -24,6 +24,11 @@ True + + bin\ + TRACE;DEBUG + + @@ -33,4 +38,4 @@ - + \ No newline at end of file diff --git a/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj index 01ab32e..5e3da12 100644 --- a/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj +++ b/tests/PaginableCollections.Tests/PaginableCollections.Tests.csproj @@ -22,8 +22,10 @@ - - + + + + From 86b6d5a27e3f17a0fb4c05b9dde471f7e1ac3e8b Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Fri, 21 Apr 2017 23:51:40 -0500 Subject: [PATCH 07/10] samples --- PaginableCollections.sln | 18 +++++- samples/ConsoleAppDotNet45/App.config | 6 ++ .../ConsoleAppDotNet45.csproj | 57 +++++++++++++++++++ samples/ConsoleAppDotNet45/Program.cs | 25 ++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++++ .../ConsoleAppDotNetCore.csproj | 12 ++++ samples/ConsoleAppDotNetCore/Program.cs | 25 ++++++++ 7 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 samples/ConsoleAppDotNet45/App.config create mode 100644 samples/ConsoleAppDotNet45/ConsoleAppDotNet45.csproj create mode 100644 samples/ConsoleAppDotNet45/Program.cs create mode 100644 samples/ConsoleAppDotNet45/Properties/AssemblyInfo.cs create mode 100644 samples/ConsoleAppDotNetCore/ConsoleAppDotNetCore.csproj create mode 100644 samples/ConsoleAppDotNetCore/Program.cs diff --git a/PaginableCollections.sln b/PaginableCollections.sln index c61cea7..02be37a 100644 --- a/PaginableCollections.sln +++ b/PaginableCollections.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.3 +VisualStudioVersion = 15.0.26228.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B15992BA-EB0A-4096-BA64-A7E1B7F6FA32}" EndProject @@ -15,6 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaginableCollections", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaginableCollections.Tests", "tests\PaginableCollections.Tests\PaginableCollections.Tests.csproj", "{1834508B-44C8-44AD-83F2-19ACEE028AAF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppDotNet45", "samples\ConsoleAppDotNet45\ConsoleAppDotNet45.csproj", "{0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppDotNetCore", "samples\ConsoleAppDotNetCore\ConsoleAppDotNetCore.csproj", "{5CEFB89D-72F7-4345-B3AA-B26091D7433C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{FC4DDD23-0F50-4F65-AA6D-DB5D2657C4D3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,11 +35,21 @@ Global {1834508B-44C8-44AD-83F2-19ACEE028AAF}.Debug|Any CPU.Build.0 = Debug|Any CPU {1834508B-44C8-44AD-83F2-19ACEE028AAF}.Release|Any CPU.ActiveCfg = Release|Any CPU {1834508B-44C8-44AD-83F2-19ACEE028AAF}.Release|Any CPU.Build.0 = Release|Any CPU + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5}.Release|Any CPU.Build.0 = Release|Any CPU + {5CEFB89D-72F7-4345-B3AA-B26091D7433C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CEFB89D-72F7-4345-B3AA-B26091D7433C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CEFB89D-72F7-4345-B3AA-B26091D7433C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CEFB89D-72F7-4345-B3AA-B26091D7433C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {1834508B-44C8-44AD-83F2-19ACEE028AAF} = {B15992BA-EB0A-4096-BA64-A7E1B7F6FA32} + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5} = {FC4DDD23-0F50-4F65-AA6D-DB5D2657C4D3} + {5CEFB89D-72F7-4345-B3AA-B26091D7433C} = {FC4DDD23-0F50-4F65-AA6D-DB5D2657C4D3} EndGlobalSection EndGlobal diff --git a/samples/ConsoleAppDotNet45/App.config b/samples/ConsoleAppDotNet45/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/samples/ConsoleAppDotNet45/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/samples/ConsoleAppDotNet45/ConsoleAppDotNet45.csproj b/samples/ConsoleAppDotNet45/ConsoleAppDotNet45.csproj new file mode 100644 index 0000000..f153c1a --- /dev/null +++ b/samples/ConsoleAppDotNet45/ConsoleAppDotNet45.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {0A23A5A4-8F3F-4D07-A9EB-31AADB95C2E5} + Exe + ConsoleAppDotNet45 + ConsoleAppDotNet45 + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {8f6c7555-710f-443f-a5ca-bf50fc37484d} + PaginableCollections + + + + \ No newline at end of file diff --git a/samples/ConsoleAppDotNet45/Program.cs b/samples/ConsoleAppDotNet45/Program.cs new file mode 100644 index 0000000..88f973b --- /dev/null +++ b/samples/ConsoleAppDotNet45/Program.cs @@ -0,0 +1,25 @@ +namespace ConsoleAppDotNet45 +{ + using System; + using System.Linq; + using PaginableCollections; + + class Program + { + static void Main(string[] args) + { + var itemCountPerPage = 25; + var pageNumber = 4; + + var paginable = + Enumerable.Range(1, 200) + .ToPaginable(pageNumber, itemCountPerPage); + + Console.WriteLine(string.Format("page number {0}", pageNumber)); + Console.WriteLine(string.Format("item count per page {0}", itemCountPerPage)); + Console.WriteLine(string.Join(",", paginable.Select(t => t.Item))); + Console.WriteLine(string.Format("showing items {0} to {1} of {2}", paginable.FirstItemNumber, paginable.LastItemNumber, paginable.TotalItemCount)); + Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/samples/ConsoleAppDotNet45/Properties/AssemblyInfo.cs b/samples/ConsoleAppDotNet45/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..babc6e0 --- /dev/null +++ b/samples/ConsoleAppDotNet45/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleAppDotNet45")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleAppDotNet45")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0a23a5a4-8f3f-4d07-a9eb-31aadb95c2e5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/samples/ConsoleAppDotNetCore/ConsoleAppDotNetCore.csproj b/samples/ConsoleAppDotNetCore/ConsoleAppDotNetCore.csproj new file mode 100644 index 0000000..fc3028a --- /dev/null +++ b/samples/ConsoleAppDotNetCore/ConsoleAppDotNetCore.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp1.1 + + + + + + + \ No newline at end of file diff --git a/samples/ConsoleAppDotNetCore/Program.cs b/samples/ConsoleAppDotNetCore/Program.cs new file mode 100644 index 0000000..0cb4773 --- /dev/null +++ b/samples/ConsoleAppDotNetCore/Program.cs @@ -0,0 +1,25 @@ +namespace ConsoleAppDotNetCore +{ + using System; + using System.Linq; + using PaginableCollections; + + class Program + { + static void Main(string[] args) + { + var itemCountPerPage = 25; + var pageNumber = 4; + + var paginable = + Enumerable.Range(1, 200) + .ToPaginable(pageNumber, itemCountPerPage); + + Console.WriteLine(string.Format("page number {0}", pageNumber)); + Console.WriteLine(string.Format("item count per page {0}", itemCountPerPage)); + Console.WriteLine(string.Join(",", paginable.Select(t => t.Item))); + Console.WriteLine(string.Format("showing items {0} to {1} of {2}", paginable.FirstItemNumber, paginable.LastItemNumber, paginable.TotalItemCount)); + Console.ReadLine(); + } + } +} \ No newline at end of file From b6d8f50aaf5371ddb70dbce7f1ac554e6ef3ea61 Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Sat, 22 Apr 2017 08:41:44 -0500 Subject: [PATCH 08/10] refactored some stuff --- PaginableCollections.sln | 2 +- .../PaginableCollections.csproj | 9 --------- src/PaginableCollections/PaginableExtensions.cs | 2 +- src/PaginableCollections/Properties/AssemblyInfo.cs | 13 ++----------- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/PaginableCollections.sln b/PaginableCollections.sln index 02be37a..833326a 100644 --- a/PaginableCollections.sln +++ b/PaginableCollections.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26228.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B15992BA-EB0A-4096-BA64-A7E1B7F6FA32}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50BAA0E6-841D-4678-9679-38A2A3456F60}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{50BAA0E6-841D-4678-9679-38A2A3456F60}" ProjectSection(SolutionItems) = preProject appveyor.yml = appveyor.yml build.cake = build.cake diff --git a/src/PaginableCollections/PaginableCollections.csproj b/src/PaginableCollections/PaginableCollections.csproj index bdfafde..272c7a2 100644 --- a/src/PaginableCollections/PaginableCollections.csproj +++ b/src/PaginableCollections/PaginableCollections.csproj @@ -13,15 +13,6 @@ git git://github.com/neekgreen/paginablecollections 1.6.0 - false - false - false - false - false - false - false - false - True diff --git a/src/PaginableCollections/PaginableExtensions.cs b/src/PaginableCollections/PaginableExtensions.cs index 81eba4a..0f5abf4 100644 --- a/src/PaginableCollections/PaginableExtensions.cs +++ b/src/PaginableCollections/PaginableExtensions.cs @@ -50,7 +50,7 @@ public static IPager ToPager(this IPaginable paginable, int maximumPageNumberCou /// /// /// - public static IEnumerable> ToPaginableItemList(this IEnumerable t, int pageNumber, int itemCountPerPage) + internal static IEnumerable> ToPaginableItemList(this IEnumerable t, int pageNumber, int itemCountPerPage) { var offset = (pageNumber - 1) * itemCountPerPage; var list = t.ToList(); diff --git a/src/PaginableCollections/Properties/AssemblyInfo.cs b/src/PaginableCollections/Properties/AssemblyInfo.cs index 764c26f..a46fb3b 100644 --- a/src/PaginableCollections/Properties/AssemblyInfo.cs +++ b/src/PaginableCollections/Properties/AssemblyInfo.cs @@ -1,12 +1,3 @@ -using System.Reflection; +using System; -[assembly: AssemblyTitle("PaginableCollections")] -[assembly: AssemblyDescription("A light weight pagination framework.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("PaginableCollections")] -[assembly: AssemblyProduct("PaginableCollections")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("3.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0")] \ No newline at end of file +[assembly: CLSCompliant(true)] \ No newline at end of file From 75f6d9ba653fde217d3957c4020679ffc58a9b6c Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Sat, 22 Apr 2017 09:08:49 -0500 Subject: [PATCH 09/10] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4bb6b55..45e48a1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ -# PaginableCollections [![Build status](https://ci.appveyor.com/api/projects/status/8hedo7ja62gaq022?svg=true)](https://ci.appveyor.com/project/neekgreen/paginablecollections) -A light weight pagination framework. +PaginableCollections +==================== + +[![Build status](https://ci.appveyor.com/api/projects/status/8hedo7ja62gaq022?svg=true)](https://ci.appveyor.com/project/neekgreen/paginablecollections) +[![NuGet](https://img.shields.io/nuget/v/paginablecollections.svg)](https://www.nuget.org/packages/paginablecollections) + +A light weight pagination framework for .NET and .NET Core. From 75da4f23842601f71ae9b6975e31e981dc41cb07 Mon Sep 17 00:00:00 2001 From: Nicholas Myers Date: Sat, 22 Apr 2017 09:22:14 -0500 Subject: [PATCH 10/10] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 45e48a1..12e4edd 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,11 @@ PaginableCollections [![NuGet](https://img.shields.io/nuget/v/paginablecollections.svg)](https://www.nuget.org/packages/paginablecollections) A light weight pagination framework for .NET and .NET Core. + +### Installing PaginableCollections + +You should install [PaginableCollections with NuGet](https://www.nuget.org/packages/paginablecollections): + + Install-Package PaginableCollections + +This command will download and install PaginableCollections. Let me know if you have questions!