Skip to content

Commit a4b7066

Browse files
authored
11.2 (#23)
- Page `MapTo` method - Modernize GitHub actions - `StoppedTimeProvider.GetTimestamp()` - `SimpleResult` is obsolete - Reserved numeric range is 5000000 - 5999999
1 parent edc43c3 commit a4b7066

12 files changed

Lines changed: 169 additions & 26 deletions

.github/workflows/publish-github-pre-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
jobs:
88
push:
99
permissions:
10+
checks: write
1011
contents: read
1112
packages: write
12-
uses: NetChris/workflows/.github/workflows/pre-release-nuget-github.yml@v0.0
13+
uses: NetChris/workflows/.github/workflows/pre-release-nuget-github.yml@v2
1314
secrets: inherit

.github/workflows/publish-github-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
jobs:
88
push:
99
permissions:
10+
checks: write
1011
contents: read
1112
packages: write
12-
uses: NetChris/workflows/.github/workflows/release-nuget-github.yml@v0.0
13+
uses: NetChris/workflows/.github/workflows/release-nuget-github.yml@v2
1314
secrets: inherit

.github/workflows/publish-nuget-org-pre-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
jobs:
88
push:
99
permissions:
10+
checks: write
1011
contents: read
1112
packages: write
12-
uses: NetChris/workflows/.github/workflows/pre-release-nuget-org.yml@v0.0
13+
uses: NetChris/workflows/.github/workflows/pre-release-nuget-org.yml@v2
1314
secrets: inherit

.github/workflows/publish-nuget-org-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
jobs:
88
push:
99
permissions:
10+
checks: write
1011
contents: read
1112
packages: write
12-
uses: NetChris/workflows/.github/workflows/release-nuget-org.yml@v0.0
13+
uses: NetChris/workflows/.github/workflows/release-nuget-org.yml@v2
1314
secrets: inherit

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
checks: write
99
contents: read
1010
packages: write
11-
uses: NetChris/workflows/.github/workflows/push-dotnet-build-test-pack-push-default.yml@v1
11+
uses: NetChris/workflows/.github/workflows/push-dotnet-build-test-pack-push-default.yml@v2

NetChris.Core.UnitTests/ApplicationMetadataTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ public void ApplicationComponentShort_should_flow_through()
8888
applicationAggregate.Should().Be("eac");
8989
}
9090

91-
[Fact]
92-
public void ApplicationVersion_is_formatted_correctly()
93-
{
94-
// Arrange
95-
// Act
96-
var applicationVersion = _appMetadata.ApplicationVersion;
97-
98-
// Assert
99-
applicationVersion.Should().Be(new Version("1.2.3.0"));
100-
}
101-
10291
[Fact]
10392
public void InformationalVersion_is_formatted_correctly()
10493
{
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using FluentAssertions;
5+
using NetChris.Core.Paging;
6+
using Xunit;
7+
8+
namespace NetChris.Core.UnitTests.Paging;
9+
10+
public class MapToTests
11+
{
12+
private class FromType
13+
{
14+
public string Name { get; set; } = null!;
15+
public int Age { get; set; }
16+
}
17+
18+
private class ToType
19+
{
20+
public string PersonName { get; set; } = null!;
21+
public TimeSpan Age { get; set; }
22+
}
23+
24+
25+
private readonly List<FromType> _fromTypes = new()
26+
{
27+
new FromType { Name = "Alice", Age = 30 },
28+
new FromType { Name = "Bob", Age = 25 },
29+
new FromType { Name = "Charlie", Age = 35 },
30+
new FromType { Name = "Diana", Age = 28 }
31+
};
32+
33+
34+
private readonly Page<FromType> _sourcePage;
35+
private readonly Page<ToType> _targetPage;
36+
37+
private static ToType MappingFunction(FromType from)
38+
{
39+
return new ToType
40+
{
41+
PersonName = from.Name,
42+
Age = TimeSpan.FromDays(from.Age * 365.25),
43+
};
44+
}
45+
46+
public MapToTests()
47+
{
48+
_sourcePage = new Page<FromType>(_fromTypes, 2, 4, 500);
49+
_targetPage = _sourcePage.MapTo(MappingFunction);
50+
}
51+
52+
[Fact]
53+
public void TotalPagesShouldBeCorrect()
54+
{
55+
_targetPage.TotalPages.Should().Be(_sourcePage.TotalPages);
56+
}
57+
58+
[Fact]
59+
public void CurrentPageShouldBeCorrect()
60+
{
61+
_targetPage.CurrentPage.Should().Be(_sourcePage.CurrentPage);
62+
}
63+
64+
[Fact]
65+
public void PageSizeShouldBeCorrect()
66+
{
67+
_targetPage.PageSize.Should().Be(_sourcePage.PageSize);
68+
}
69+
70+
[Fact]
71+
public void MappedItemShouldMatch()
72+
{
73+
var charlieFromSourcePage = _sourcePage.Items.ElementAt(2);
74+
var charlieFromTargetPage = _targetPage.Items.ElementAt(2);
75+
76+
charlieFromTargetPage.PersonName.Should().Be(charlieFromSourcePage.Name);
77+
charlieFromTargetPage.Age.Should().Be(
78+
TimeSpan.FromDays(charlieFromSourcePage.Age * 365.25));
79+
}
80+
}

NetChris.Core.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution
77
ProjectSection(SolutionItems) = preProject
88
README.md = README.md
99
Directory.Build.props = Directory.Build.props
10+
.github\.DS_Store = .github\.DS_Store
1011
EndProjectSection
1112
EndProject
1213
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetChris.Core", "NetChris.Core\NetChris.Core.csproj", "{24F1F7DC-1F68-4F45-BD2B-97CD9A1BF532}"
1314
EndProject
1415
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetChris.Core.UnitTests", "NetChris.Core.UnitTests\NetChris.Core.UnitTests.csproj", "{18EFFC4F-2289-4469-B930-8E6F500F1BCE}"
1516
EndProject
17+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{F173C738-53A9-459E-A0C9-DF7F791A3AE5}"
18+
ProjectSection(SolutionItems) = preProject
19+
.github\workflows\publish-github-pre-release.yml = .github\workflows\publish-github-pre-release.yml
20+
.github\workflows\publish-github-release.yml = .github\workflows\publish-github-release.yml
21+
.github\workflows\publish-nuget-org-pre-release.yml = .github\workflows\publish-nuget-org-pre-release.yml
22+
.github\workflows\publish-nuget-org-release.yml = .github\workflows\publish-nuget-org-release.yml
23+
.github\workflows\push.yml = .github\workflows\push.yml
24+
EndProjectSection
25+
EndProject
1626
Global
1727
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1828
Debug|Any CPU = Debug|Any CPU
@@ -32,5 +42,6 @@ Global
3242
{18EFFC4F-2289-4469-B930-8E6F500F1BCE}.Release|Any CPU.Build.0 = Release|Any CPU
3343
EndGlobalSection
3444
GlobalSection(NestedProjects) = preSolution
45+
{F173C738-53A9-459E-A0C9-DF7F791A3AE5} = {0B8D2CDC-5BCE-45C8-8928-4EFE52528923}
3546
EndGlobalSection
3647
EndGlobal

NetChris.Core/Paging/Extensions.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace NetChris.Core.Paging;
5+
6+
/// <summary>
7+
/// Extension methods for paging
8+
/// </summary>
9+
public static class Extensions
10+
{
11+
/// <summary>
12+
/// Get a page of items of type <typeparamref name="TTo"/>
13+
/// mapped from a page of items of type <typeparamref name="T"/>
14+
/// </summary>
15+
/// <param name="sourcePage">The source page</param>
16+
/// <param name="mappingFunction">The mapping function from <typeparamref name="T"/> to <typeparamref name="TTo"/></param>
17+
public static Page<TTo> MapTo<T, TTo>(this Page<T> sourcePage, Func<T, TTo> mappingFunction)
18+
{
19+
var resultItems = sourcePage.Items.Select(mappingFunction).ToList();
20+
21+
return new Page<TTo>(
22+
resultItems,
23+
sourcePage.CurrentPage,
24+
sourcePage.PageSize,
25+
sourcePage.TotalItems);
26+
}
27+
}

NetChris.Core/Time/StoppedTimeProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ public override DateTimeOffset GetUtcNow()
3434
{
3535
return _stoppedTime.ToUniversalTime();
3636
}
37+
38+
/// <inheritdoc />
39+
public override long GetTimestamp()
40+
{
41+
return _stoppedTime.Ticks;
42+
}
3743
}

0 commit comments

Comments
 (0)