Skip to content
Merged

11.2 #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/publish-github-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
jobs:
push:
permissions:
checks: write
contents: read
packages: write
uses: NetChris/workflows/.github/workflows/pre-release-nuget-github.yml@v0.0
uses: NetChris/workflows/.github/workflows/pre-release-nuget-github.yml@v2
secrets: inherit
3 changes: 2 additions & 1 deletion .github/workflows/publish-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
jobs:
push:
permissions:
checks: write
contents: read
packages: write
uses: NetChris/workflows/.github/workflows/release-nuget-github.yml@v0.0
uses: NetChris/workflows/.github/workflows/release-nuget-github.yml@v2
secrets: inherit
3 changes: 2 additions & 1 deletion .github/workflows/publish-nuget-org-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
jobs:
push:
permissions:
checks: write
contents: read
packages: write
uses: NetChris/workflows/.github/workflows/pre-release-nuget-org.yml@v0.0
uses: NetChris/workflows/.github/workflows/pre-release-nuget-org.yml@v2
secrets: inherit
3 changes: 2 additions & 1 deletion .github/workflows/publish-nuget-org-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
jobs:
push:
permissions:
checks: write
contents: read
packages: write
uses: NetChris/workflows/.github/workflows/release-nuget-org.yml@v0.0
uses: NetChris/workflows/.github/workflows/release-nuget-org.yml@v2
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
checks: write
contents: read
packages: write
uses: NetChris/workflows/.github/workflows/push-dotnet-build-test-pack-push-default.yml@v1
uses: NetChris/workflows/.github/workflows/push-dotnet-build-test-pack-push-default.yml@v2
11 changes: 0 additions & 11 deletions NetChris.Core.UnitTests/ApplicationMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ public void ApplicationComponentShort_should_flow_through()
applicationAggregate.Should().Be("eac");
}

[Fact]
public void ApplicationVersion_is_formatted_correctly()
{
// Arrange
// Act
var applicationVersion = _appMetadata.ApplicationVersion;

// Assert
applicationVersion.Should().Be(new Version("1.2.3.0"));
}

[Fact]
public void InformationalVersion_is_formatted_correctly()
{
Expand Down
80 changes: 80 additions & 0 deletions NetChris.Core.UnitTests/Paging/MapToTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NetChris.Core.Paging;
using Xunit;

namespace NetChris.Core.UnitTests.Paging;

public class MapToTests
{
private class FromType
{
public string Name { get; set; } = null!;
public int Age { get; set; }
}

private class ToType
{
public string PersonName { get; set; } = null!;
public TimeSpan Age { get; set; }
}


private readonly List<FromType> _fromTypes = new()
{
new FromType { Name = "Alice", Age = 30 },
new FromType { Name = "Bob", Age = 25 },
new FromType { Name = "Charlie", Age = 35 },
new FromType { Name = "Diana", Age = 28 }
};


private readonly Page<FromType> _sourcePage;
private readonly Page<ToType> _targetPage;

private static ToType MappingFunction(FromType from)
{
return new ToType
{
PersonName = from.Name,
Age = TimeSpan.FromDays(from.Age * 365.25),
};
}

public MapToTests()
{
_sourcePage = new Page<FromType>(_fromTypes, 2, 4, 500);
_targetPage = _sourcePage.MapTo(MappingFunction);
}

[Fact]
public void TotalPagesShouldBeCorrect()
{
_targetPage.TotalPages.Should().Be(_sourcePage.TotalPages);
}

[Fact]
public void CurrentPageShouldBeCorrect()
{
_targetPage.CurrentPage.Should().Be(_sourcePage.CurrentPage);
}

[Fact]
public void PageSizeShouldBeCorrect()
{
_targetPage.PageSize.Should().Be(_sourcePage.PageSize);
}

[Fact]
public void MappedItemShouldMatch()
{
var charlieFromSourcePage = _sourcePage.Items.ElementAt(2);
var charlieFromTargetPage = _targetPage.Items.ElementAt(2);

charlieFromTargetPage.PersonName.Should().Be(charlieFromSourcePage.Name);
charlieFromTargetPage.Age.Should().Be(
TimeSpan.FromDays(charlieFromSourcePage.Age * 365.25));
}
}
11 changes: 11 additions & 0 deletions NetChris.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution
ProjectSection(SolutionItems) = preProject
README.md = README.md
Directory.Build.props = Directory.Build.props
.github\.DS_Store = .github\.DS_Store
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetChris.Core", "NetChris.Core\NetChris.Core.csproj", "{24F1F7DC-1F68-4F45-BD2B-97CD9A1BF532}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetChris.Core.UnitTests", "NetChris.Core.UnitTests\NetChris.Core.UnitTests.csproj", "{18EFFC4F-2289-4469-B930-8E6F500F1BCE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{F173C738-53A9-459E-A0C9-DF7F791A3AE5}"
ProjectSection(SolutionItems) = preProject
.github\workflows\publish-github-pre-release.yml = .github\workflows\publish-github-pre-release.yml
.github\workflows\publish-github-release.yml = .github\workflows\publish-github-release.yml
.github\workflows\publish-nuget-org-pre-release.yml = .github\workflows\publish-nuget-org-pre-release.yml
.github\workflows\publish-nuget-org-release.yml = .github\workflows\publish-nuget-org-release.yml
.github\workflows\push.yml = .github\workflows\push.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -32,5 +42,6 @@ Global
{18EFFC4F-2289-4469-B930-8E6F500F1BCE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F173C738-53A9-459E-A0C9-DF7F791A3AE5} = {0B8D2CDC-5BCE-45C8-8928-4EFE52528923}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions NetChris.Core/Paging/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Linq;

namespace NetChris.Core.Paging;

/// <summary>
/// Extension methods for paging
/// </summary>
public static class Extensions
{
/// <summary>
/// Get a page of items of type <typeparamref name="TTo"/>
/// mapped from a page of items of type <typeparamref name="T"/>
/// </summary>
/// <param name="sourcePage">The source page</param>
/// <param name="mappingFunction">The mapping function from <typeparamref name="T"/> to <typeparamref name="TTo"/></param>
public static Page<TTo> MapTo<T, TTo>(this Page<T> sourcePage, Func<T, TTo> mappingFunction)
{
var resultItems = sourcePage.Items.Select(mappingFunction).ToList();

return new Page<TTo>(
resultItems,
sourcePage.CurrentPage,
sourcePage.PageSize,
sourcePage.TotalItems);
}
}
6 changes: 6 additions & 0 deletions NetChris.Core/Time/StoppedTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public override DateTimeOffset GetUtcNow()
{
return _stoppedTime.ToUniversalTime();
}

/// <inheritdoc />
public override long GetTimestamp()
{
return _stoppedTime.Ticks;
}
}
39 changes: 29 additions & 10 deletions NetChris.Core/Values/SimpleResult.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace NetChris.Core.Values;
using System;

namespace NetChris.Core.Values;

/// <summary>
/// Lightweight object with an code and message.
/// Lightweight object with a code and message.
/// A glorified key/value pair.
/// </summary>
/// <remarks>
Expand All @@ -10,34 +12,51 @@
/// or throw errors with unique-ish codes and an explanatory message.
/// </para>
/// </remarks>
[Obsolete]
public class SimpleResult
{
/// <summary>
/// Gets the code
/// The result type
/// </summary>
/// <value>The result code</value>
public string ResultCode
/// <remarks>
/// This is implemented as a <see cref="Uri"/> to communicate that the result is of a unique type
/// </remarks>
public Uri ResultType
{
get;
}

/// <summary>
/// Gets the message.
/// The message
/// </summary>
/// <value>The message</value>
public string Message
{
get;
}

/// <summary>
/// Whether the message can be publicly displayed
/// (e.g. in a RFC 9457 Problem Details from a web API).
/// </summary>
/// <remarks>
/// It is implementation dependent how this is used.
/// The default is <c>true</c>, meaning the message can be displayed publicly.
/// </remarks>
public bool IsPublic
{
get;
}

/// <summary>
/// Initializes a new instance of the <see cref="SimpleResult" /> class.
/// </summary>
/// <param name="resultCode">The result code</param>
/// <param name="resultType">The result type</param>
/// <param name="message">The message</param>
public SimpleResult(string resultCode, string message)
/// <param name="isPublic">Whether the message can be publicly displayed</param>
public SimpleResult(Uri resultType, string message, bool isPublic = true)
{
ResultCode = resultCode;
ResultType = resultType;
Message = message;
IsPublic = isPublic;
}
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# NetChris.Core

Base metadata and operational classes for .NET Core development.

## [Reserved Numeric Range](https://github.com/NetChris/reference/wiki/Number-reservations)

The `NetChris.Core` library reserves `5,000,000` through `5,999,999` for use by such purposes as:

- Event IDs
- Advisory lock numbers
Loading