Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8ead2da
Initial plan
Copilot Apr 7, 2026
be7137b
feat: create PowerKit source-only NuGet package with shared BCL-only …
Copilot Apr 7, 2026
ad3489c
refactor: remove Utils namespace/dir, move files one level up
Copilot Apr 7, 2026
e588616
Change copyright year to 2026
Tyrrrz Apr 7, 2026
8c4b9aa
refactor: address review feedback — rename classes, split files, nets…
Copilot Apr 7, 2026
1c73873
fix: address automated review feedback — TakeAsync guard, ConfigureAw…
Copilot Apr 7, 2026
24c1dae
test: add PowerKit.Tests xunit project with 90 tests covering all uti…
Copilot Apr 7, 2026
6d9a8f0
test: adopt PolyShim naming and assertion conventions in test files
Copilot Apr 7, 2026
ddd9770
Replace TimeSpanExtensions.Clamp with generic ComparableExtensions.Cl…
Copilot Apr 8, 2026
edfb1bd
Add GitHub Actions workflow (mirrors CliWrap main.yml)
Copilot Apr 8, 2026
6f75348
Update PolyShim to 2.8.0; mark Microsoft.Bcl.AsyncInterfaces as Priva…
Copilot Apr 9, 2026
4fc3616
Update PolyShim to 2.8.1, keep Microsoft.Bcl.AsyncInterfaces workaround
Copilot Apr 10, 2026
476b3ca
Update PolyShim to 2.8.2, remove Microsoft.Bcl.AsyncInterfaces workar…
Copilot Apr 10, 2026
efa44ba
Replace FQNs with using statements in AsyncEnumerableExtensions and S…
Copilot Apr 10, 2026
a18e387
Add braces in AsyncEnumerableExtensions; add Min/Max to ComparableExt…
Copilot Apr 10, 2026
5e42489
Add LastOrNull, NullIfEmpty/NullIfWhiteSpace for strings, Trim for St…
Copilot Apr 10, 2026
754cc9e
Optimize LastOrNull with IReadOnlyList fast path and StringBuilder.Tr…
Copilot Apr 10, 2026
92e1590
Update Directory.Build.props
Tyrrrz Apr 10, 2026
8569b05
Rename ToSpaceSeparatedWords to SeparateWords with char separator par…
Copilot Apr 10, 2026
b1fd164
Use central package management (Directory.Packages.props), move packa…
Copilot Apr 10, 2026
06b9baa
Add await Task.Yield() to ToAsyncEnumerable test helper
Copilot Apr 10, 2026
3e9a7a5
Simplify tests: remove global usings, merge AsyncEnumerable/Comparabl…
Copilot Apr 10, 2026
bd9c9b9
Use .NET 10, remove ImplicitUsings, merge tests (1 per implementation…
Copilot Apr 10, 2026
65b6ff3
Add non-default Guid test case to NullIfDefault_Test
Copilot Apr 10, 2026
502c93a
Add ToKebabCase() and ToSnakeCase() string extensions with tests
Copilot Apr 10, 2026
ce89716
Address review feedback: unmerge tests, fix Disposable.Merge exceptio…
Copilot Apr 10, 2026
f562686
Use ToArray() instead of ToList() in ToSingletonEnumerable test
Copilot Apr 11, 2026
47da80b
Replace Progress<T> with synchronous IProgress<T> in stream tests
Copilot Apr 11, 2026
ae8a23c
Add WhereNotNullOrEmpty, refactor StreamExtensions to share code, laz…
Copilot Apr 11, 2026
57870c8
Add empty-array test case for WhereNotNullOrEmpty
Copilot Apr 11, 2026
231c828
Replace custom SynchronousProgress<T> with Gress package's DelegatePr…
Copilot Apr 11, 2026
1027ff4
Use Gress ProgressCollector in stream tests; reorder StreamExtensions…
Copilot Apr 11, 2026
fd61e32
Remove duplicate CopyToAsync_ContentLength_Progress_Test (same as Cop…
Copilot Apr 11, 2026
b095af1
Update PowerKit/Extensions/StreamExtensions.cs
Tyrrrz Apr 11, 2026
b79b77c
Update PowerKit/Extensions/AggregateExceptionExtensions.cs
Tyrrrz Apr 11, 2026
caedc29
Expand InvalidFileNameChars to include ASCII control characters 0x01-…
Copilot Apr 12, 2026
0c1376c
Rename char variable 'c' to 'ch' in PathExtensions and StringExtensions
Copilot Apr 12, 2026
fa53033
Address PR review comments: pattern matching in AggregateExceptionExt…
Copilot Apr 12, 2026
afbe49a
Cache cross-platform invalid char arrays to avoid repeated allocations
Copilot Apr 12, 2026
3891af9
Update PowerKit/Extensions/AsyncEnumerableExtensions.cs
Tyrrrz Apr 12, 2026
b082066
Derive CrossPlatformInvalidPathChars from CrossPlatformInvalidFileNam…
Copilot Apr 12, 2026
381cb5f
Update PathExtensions.cs
Tyrrrz Apr 12, 2026
d81f728
Update PathExtensions.cs
Tyrrrz Apr 12, 2026
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
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
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 }}
12 changes: 12 additions & 0 deletions .gitignore
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/
31 changes: 31 additions & 0 deletions Directory.Build.props
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>
15 changes: 15 additions & 0 deletions Directory.Packages.props
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>
21 changes: 21 additions & 0 deletions License.txt
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.
10 changes: 10 additions & 0 deletions NuGet.config
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>
54 changes: 54 additions & 0 deletions PowerKit.Tests/AggregateExceptionExtensionsTests.cs
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()
Comment thread
Tyrrrz marked this conversation as resolved.
{
// 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();
}
}
63 changes: 63 additions & 0 deletions PowerKit.Tests/AsyncEnumerableExtensionsTests.cs
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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: TakeAsync_Test, SelectManyAsync_Test, ToListAsync_Test, GetAwaiter_Test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in bd9c9b9 — merged from 12 test methods down to 4: TakeAsync_Test, SelectManyAsync_Test, ToListAsync_Test, GetAwaiter_Test.

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;
Comment thread
Tyrrrz marked this conversation as resolved.
}
}

[Fact]
public async Task TakeAsync_Test()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the first test @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3e9a7a5TakeAsync_Test is now the first test in the class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed as part of test merging in bd9c9b9TakeAsync_Test is now the first test in the class.

{
// 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);
}
}
37 changes: 37 additions & 0 deletions PowerKit.Tests/ComparableExtensionsTests.cs
Comment thread
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);
}
}
66 changes: 66 additions & 0 deletions PowerKit.Tests/DisposableTests.cs
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()
Comment thread
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>();
}
}
Loading