-
Notifications
You must be signed in to change notification settings - Fork 1
Create PowerKit: source-only NuGet package of shared utility extensions #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ead2da
be7137b
ad3489c
e588616
8c4b9aa
1c73873
24c1dae
6d9a8f0
ddd9770
edfb1bd
6f75348
4fc3616
476b3ca
efa44ba
a18e387
5e42489
754cc9e
92e1590
8569b05
b1fd164
06b9baa
3e9a7a5
bd9c9b9
65b6ff3
502c93a
ce89716
f562686
47da80b
ae8a23c
57870c8
231c828
1027ff4
fd61e32
b095af1
b79b77c
caedc29
0c1376c
fa53033
afbe49a
3891af9
b082066
381cb5f
d81f728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: main | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| package-version: | ||
| type: string | ||
| description: Package version | ||
| required: false | ||
| deploy: | ||
| type: boolean | ||
| description: Deploy package | ||
| required: false | ||
| default: false | ||
| push: | ||
| branches: | ||
| - prime | ||
| tags: | ||
| - "*" | ||
| pull_request: | ||
| branches: | ||
| - prime | ||
|
|
||
| jobs: | ||
| main: | ||
| uses: Tyrrrz/.github/.github/workflows/nuget.yml@prime | ||
| with: | ||
| deploy: ${{ inputs.deploy || github.ref_type == 'tag' }} | ||
| package-version: ${{ inputs.package-version || (github.ref_type == 'tag' && github.ref_name) || format('0.0.0-ci-{0}', github.sha) }} | ||
| secrets: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
| NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} | ||
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # User-specific files | ||
| .vs/ | ||
| .idea/ | ||
| *.suo | ||
| *.user | ||
|
|
||
| # Build results | ||
| bin/ | ||
| obj/ | ||
|
|
||
| # Test results | ||
| TestResults/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <Version>0.0.0-dev</Version> | ||
| <Company>Tyrrrz</Company> | ||
| <Copyright>Copyright (C) Oleksii Holub</Copyright> | ||
| <LangVersion>preview</LangVersion> | ||
| <Nullable>enable</Nullable> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Disable nullability warnings on older frameworks because there is no nullability info for BCL --> | ||
| <PropertyGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))"> | ||
| <Nullable>annotations</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Disable trim and AOT analyzers on older frameworks as they're not compatible with newer language features --> | ||
| <PropertyGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))"> | ||
| <EnableTrimAnalyzer>false</EnableTrimAnalyzer> | ||
| <EnableAotAnalyzer>false</EnableAotAnalyzer> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Authors>$(Company)</Authors> | ||
| <Description>Collection of utilities and extensions for rapid .NET development</Description> | ||
| <PackageTags>utils extensions utilities source</PackageTags> | ||
| <PackageProjectUrl>https://github.com/Tyrrrz/PowerKit</PackageProjectUrl> | ||
| <PackageReleaseNotes>https://github.com/Tyrrrz/PowerKit/releases</PackageReleaseNotes> | ||
| <PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
| </PropertyGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageVersion Include="coverlet.collector" Version="6.0.2" /> | ||
| <PackageVersion Include="FluentAssertions" Version="6.12.0" /> | ||
| <PackageVersion Include="Gress" Version="2.1.1" /> | ||
| <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
| <PackageVersion Include="PolyShim" Version="2.8.2" /> | ||
| <PackageVersion Include="xunit" Version="2.9.2" /> | ||
| <PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 Oleksii Holub | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <clear /> | ||
| <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
| </packageSources> | ||
| <config> | ||
| <add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" /> | ||
| </config> | ||
| </configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using FluentAssertions; | ||
| using PowerKit.Extensions; | ||
| using Xunit; | ||
|
|
||
| namespace PowerKit.Tests; | ||
|
|
||
| public class AggregateExceptionExtensionsTests | ||
| { | ||
| [Fact] | ||
| public void TryGetSingle_Test() | ||
| { | ||
| // Arrange | ||
| var inner = new Exception("only"); | ||
|
|
||
| // Act & assert | ||
| new AggregateException(inner).TryGetSingle().Should().BeSameAs(inner); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetSingle_Multiple_Test() | ||
| { | ||
| // Act & assert | ||
| new AggregateException(new Exception("a"), new Exception("b")) | ||
| .TryGetSingle() | ||
| .Should() | ||
| .BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetSingle_Nested_Test() | ||
| { | ||
| // Arrange | ||
| var leaf = new Exception("leaf"); | ||
|
|
||
| // Act & assert | ||
| new AggregateException(new AggregateException(leaf)) | ||
| .TryGetSingle() | ||
| .Should() | ||
| .BeSameAs(leaf); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetSingle_NestedMultiple_Test() | ||
| { | ||
| // Act & assert | ||
| new AggregateException( | ||
| new AggregateException(new Exception("a"), new Exception("b")) | ||
| ) | ||
| .TryGetSingle() | ||
| .Should() | ||
| .BeNull(); | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are way to detailed, you can probably merge some of them and remove some others @copilot
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3e9a7a5 — merged edge-case tests into the main test methods and removed overly detailed tests. Down from 12 test methods to 4:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in bd9c9b9 — merged from 12 test methods down to 4: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using PowerKit.Extensions; | ||
| using Xunit; | ||
|
|
||
| namespace PowerKit.Tests; | ||
|
|
||
| public class AsyncEnumerableExtensionsTests | ||
| { | ||
| private static async IAsyncEnumerable<T> ToAsyncEnumerable<T>(IEnumerable<T> source) | ||
| { | ||
| foreach (var item in source) | ||
| { | ||
| await Task.Yield(); | ||
| yield return item; | ||
|
Tyrrrz marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TakeAsync_Test() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the first test @copilot
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3e9a7a5 —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed as part of test merging in bd9c9b9 — |
||
| { | ||
| // Act & assert | ||
| (await ToAsyncEnumerable([1, 2, 3, 4, 5]).TakeAsync(3).ToListAsync()) | ||
| .Should() | ||
| .Equal(1, 2, 3); | ||
|
|
||
| (await ToAsyncEnumerable([1, 2, 3]).TakeAsync(0).ToListAsync()) | ||
| .Should() | ||
| .BeEmpty(); | ||
|
|
||
| (await ToAsyncEnumerable([1, 2, 3]).TakeAsync(10).ToListAsync()) | ||
| .Should() | ||
| .Equal(1, 2, 3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SelectManyAsync_Test() | ||
| { | ||
| // Act & assert | ||
| (await ToAsyncEnumerable(["ab", "cd"]).SelectManyAsync(s => s.ToCharArray()).ToListAsync()) | ||
| .Should() | ||
| .Equal('a', 'b', 'c', 'd'); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ToListAsync_Test() | ||
| { | ||
| // Act & assert | ||
| (await ToAsyncEnumerable([1, 2, 3]).ToListAsync()) | ||
| .Should() | ||
| .Equal(1, 2, 3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetAwaiter_Test() | ||
| { | ||
| // Act & assert | ||
| (await ToAsyncEnumerable([10, 20, 30])) | ||
| .Should() | ||
| .Equal(10, 20, 30); | ||
| } | ||
| } | ||
|
Tyrrrz marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using FluentAssertions; | ||
| using PowerKit.Extensions; | ||
| using Xunit; | ||
|
|
||
| namespace PowerKit.Tests; | ||
|
|
||
| public class ComparableExtensionsTests | ||
| { | ||
| [Fact] | ||
| public void Clamp_Test() | ||
| { | ||
| // Act & assert | ||
| 5.Clamp(1, 10).Should().Be(5); | ||
| 1.Clamp(3, 10).Should().Be(3); | ||
| 20.Clamp(1, 7).Should().Be(7); | ||
| 3.14.Clamp(0.0, 3.0).Should().Be(3.0); | ||
| "banana".Clamp("apple", "cherry").Should().Be("banana"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Min_Test() | ||
| { | ||
| // Act & assert | ||
| 5.Min(3).Should().Be(3); | ||
| 2.Min(7).Should().Be(2); | ||
| 4.Min(4).Should().Be(4); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Max_Test() | ||
| { | ||
| // Act & assert | ||
| 5.Max(3).Should().Be(5); | ||
| 2.Max(7).Should().Be(7); | ||
| 4.Max(4).Should().Be(4); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using FluentAssertions; | ||
| using PowerKit; | ||
| using Xunit; | ||
|
|
||
| namespace PowerKit.Tests; | ||
|
|
||
| public class DisposableTests | ||
| { | ||
| [Fact] | ||
| public void Create_Test() | ||
| { | ||
| // Arrange | ||
| var invoked = false; | ||
| var disposable = Disposable.Create(() => invoked = true); | ||
|
|
||
| // Act & assert | ||
| invoked.Should().BeFalse(); | ||
| disposable.Dispose(); | ||
| invoked.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Merge_Test() | ||
|
Tyrrrz marked this conversation as resolved.
|
||
| { | ||
| // Arrange | ||
| var order = new List<int>(); | ||
| var disposables = Enumerable | ||
| .Range(0, 3) | ||
| .Select(i => Disposable.Create(() => order.Add(i))) | ||
| .ToArray(); | ||
|
|
||
| // Act | ||
| Disposable.Merge(disposables).Dispose(); | ||
|
|
||
| // Assert | ||
| order.Should().Equal(0, 1, 2); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Merge_Exception_Test() | ||
| { | ||
| // Arrange | ||
| var disposed = new List<int>(); | ||
| var disposables = new[] | ||
| { | ||
| Disposable.Create(() => disposed.Add(0)), | ||
| Disposable.Create(() => | ||
| { | ||
| disposed.Add(1); | ||
| throw new InvalidOperationException("fail"); | ||
| }), | ||
| Disposable.Create(() => disposed.Add(2)), | ||
| }; | ||
|
|
||
| // Act | ||
| var ex = Assert.Throws<AggregateException>(() => Disposable.Merge(disposables).Dispose()); | ||
|
|
||
| // Assert | ||
| disposed.Should().Equal(0, 1, 2); | ||
| ex.InnerExceptions.Should().ContainSingle(); | ||
| ex.InnerExceptions[0].Should().BeOfType<InvalidOperationException>(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.