Skip to content
Merged
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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="CSharpier.MsBuild" Version="1.2.6" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.3" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
Expand Down
9 changes: 5 additions & 4 deletions PowerKit.Tests/AggregateExceptionExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public void TryGetSingle_Test()
var inner = new Exception("only");

// Act & assert
new AggregateException(inner).TryGetSingle().Should().BeSameAs(inner);
new AggregateException(inner)
.TryGetSingle()
.Should()
.BeSameAs(inner);
}

[Fact]
Expand Down Expand Up @@ -44,9 +47,7 @@ public void TryGetSingle_Nested_Test()
public void TryGetSingle_NestedMultiple_Test()
{
// Act & assert
new AggregateException(
new AggregateException(new Exception("a"), new Exception("b"))
)
new AggregateException(new AggregateException(new Exception("a"), new Exception("b")))
.TryGetSingle()
.Should()
.BeNull();
Expand Down
4 changes: 3 additions & 1 deletion PowerKit.Tests/AssemblyExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public async Task ExtractManifestResourceAsync_Test()
await ThisAssembly.ExtractManifestResourceAsync(ResourceName, tempFile.Path);

// Assert
(await File.ReadAllTextAsync(tempFile.Path)).Should().Be("hello");
(await File.ReadAllTextAsync(tempFile.Path))
.Should()
.Be("hello");
}
}
8 changes: 2 additions & 6 deletions PowerKit.Tests/AsyncEnumerableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ public async Task TakeAsync_Test()
.Should()
.Equal(1, 2, 3);

(await ToAsyncEnumerable([1, 2, 3]).TakeAsync(0).ToListAsync())
.Should()
.BeEmpty();
(await ToAsyncEnumerable([1, 2, 3]).TakeAsync(0).ToListAsync()).Should().BeEmpty();

(await ToAsyncEnumerable([1, 2, 3]).TakeAsync(10).ToListAsync())
.Should()
.Equal(1, 2, 3);
(await ToAsyncEnumerable([1, 2, 3]).TakeAsync(10).ToListAsync()).Should().Equal(1, 2, 3);
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion PowerKit.Tests/BinaryReaderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,3 @@ public void ReadNullTerminatedString_Empty_Test()
result.Should().BeEmpty();
}
}

2 changes: 1 addition & 1 deletion PowerKit.Tests/CollectionExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CollectionExtensionsTests
public void RemoveAll_Test()
{
// Arrange
var collection = (ICollection<int>) new List<int> { 1, 2, 3, 4, 5 };
var collection = (ICollection<int>)new List<int> { 1, 2, 3, 4, 5 };

// Act
var removed = collection.RemoveAll(x => x % 2 == 0);
Expand Down
9 changes: 3 additions & 6 deletions PowerKit.Tests/CultureInfoExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public void GetParents_Test()
.Should()
.Equal(new CultureInfo("en"), CultureInfo.InvariantCulture);

new CultureInfo("en")
.GetParents()
.Should()
.Equal(CultureInfo.InvariantCulture);
new CultureInfo("en").GetParents().Should().Equal(CultureInfo.InvariantCulture);

CultureInfo.InvariantCulture.GetParents().Should().BeEmpty();
}
Expand All @@ -38,8 +35,8 @@ public void GetSelfAndParents_Test()
.Should()
.Equal(new CultureInfo("en"), CultureInfo.InvariantCulture);

CultureInfo.InvariantCulture
.GetSelfAndParents()
CultureInfo
.InvariantCulture.GetSelfAndParents()
.Should()
.Equal(CultureInfo.InvariantCulture);
}
Expand Down
7 changes: 4 additions & 3 deletions PowerKit.Tests/DateTimeOffsetExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class DateTimeOffsetExtensionsTests
public void ParseOrNull_Test()
{
// Act & assert
DateTimeOffset.ParseOrNull("2024-06-15T00:00:00+00:00").Should().Be(
new DateTimeOffset(2024, 6, 15, 0, 0, 0, TimeSpan.Zero)
);
DateTimeOffset
.ParseOrNull("2024-06-15T00:00:00+00:00")
.Should()
.Be(new DateTimeOffset(2024, 6, 15, 0, 0, 0, TimeSpan.Zero));
DateTimeOffset.ParseOrNull("not a date").Should().BeNull();
DateTimeOffset.ParseOrNull(null).Should().BeNull();
}
Expand Down
4 changes: 3 additions & 1 deletion PowerKit.Tests/DirectoryExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public void TryDelete_Test()
public void TryDelete_NonExisting_Test()
{
// Act
var result = Directory.TryDelete(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
var result = Directory.TryDelete(
Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
);

// Assert
result.Should().BeFalse();
Expand Down
25 changes: 20 additions & 5 deletions PowerKit.Tests/EnumerableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ public void ToSingletonEnumerable_Test()
public void WhereNotNull_Test()
{
// Act & assert
new string?[] { "a", null, "b", null, "c" }.WhereNotNull().Should().Equal("a", "b", "c");
new int?[] { 1, null, 2, null, 3 }.WhereNotNull().Should().Equal(1, 2, 3);
new string?[] { "a", null, "b", null, "c" }
.WhereNotNull()
.Should()
.Equal("a", "b", "c");
new int?[] { 1, null, 2, null, 3 }
.WhereNotNull()
.Should()
.Equal(1, 2, 3);
Array.Empty<string?>().WhereNotNull().Should().BeEmpty();
}

Expand Down Expand Up @@ -55,7 +61,10 @@ public void WhereNotNullOrWhiteSpace_Test()
public void FirstOrNull_Test()
{
// Act & assert
new[] { 5, 10, 15 }.FirstOrNull().Should().Be(5);
new[] { 5, 10, 15 }
.FirstOrNull()
.Should()
.Be(5);
new[] { 42 }.FirstOrNull().Should().Be(42);
Array.Empty<int>().FirstOrNull().Should().BeNull();
}
Expand All @@ -64,7 +73,10 @@ public void FirstOrNull_Test()
public void LastOrNull_Test()
{
// Act & assert
new[] { 5, 10, 15 }.LastOrNull().Should().Be(15);
new[] { 5, 10, 15 }
.LastOrNull()
.Should()
.Be(15);
new[] { 42 }.LastOrNull().Should().Be(42);
Array.Empty<int>().LastOrNull().Should().BeNull();
}
Expand All @@ -73,7 +85,10 @@ public void LastOrNull_Test()
public void ElementAtOrNull_Test()
{
// Act & assert
new[] { 10, 20, 30 }.ElementAtOrNull(1).Should().Be(20);
new[] { 10, 20, 30 }
.ElementAtOrNull(1)
.Should()
.Be(20);
new[] { 10, 20, 30 }.ElementAtOrNull(0).Should().Be(10);
new[] { 10, 20, 30 }.ElementAtOrNull(10).Should().BeNull();
new[] { 10, 20, 30 }.ElementAtOrNull(-1).Should().BeNull();
Expand Down
10 changes: 8 additions & 2 deletions PowerKit.Tests/FileExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public void CheckWriteAccess_ReadOnly_Test()

// Arrange
using var tempFile = TempFile.Create();
File.SetAttributes(tempFile.Path, File.GetAttributes(tempFile.Path) | FileAttributes.ReadOnly);
File.SetAttributes(
tempFile.Path,
File.GetAttributes(tempFile.Path) | FileAttributes.ReadOnly
);

try
{
Expand All @@ -43,7 +46,10 @@ public void CheckWriteAccess_ReadOnly_Test()
}
finally
{
File.SetAttributes(tempFile.Path, File.GetAttributes(tempFile.Path) & ~FileAttributes.ReadOnly);
File.SetAttributes(
tempFile.Path,
File.GetAttributes(tempFile.Path) & ~FileAttributes.ReadOnly
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions PowerKit.Tests/GuidExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class GuidExtensionsTests
public void ParseOrNull_Test()
{
// Act & assert
Guid.ParseOrNull("12345678-1234-1234-1234-123456789abc").Should().Be(
new Guid("12345678-1234-1234-1234-123456789abc")
);
Guid.ParseOrNull("12345678-1234-1234-1234-123456789abc")
.Should()
.Be(new Guid("12345678-1234-1234-1234-123456789abc"));
Guid.ParseOrNull("not-a-guid").Should().BeNull();
Guid.ParseOrNull(null).Should().BeNull();
}
Expand Down
4 changes: 1 addition & 3 deletions PowerKit.Tests/PowerKit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
Expand All @@ -22,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" PrivateAssets="all" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="GitHubActionsTestLogger" />
<PackageReference Include="FluentAssertions" />
Expand All @@ -31,6 +31,4 @@
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Xunit.SkippableFact" />
</ItemGroup>

</Project>

7 changes: 3 additions & 4 deletions PowerKit.Tests/ProcessExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ public void IsRunning_Running_Test()
public async Task IsRunning_NotRunning_Test()
{
// Arrange
using var process = Process.Start(new ProcessStartInfo("dotnet", "--version")
{
RedirectStandardOutput = true
})!;
using var process = Process.Start(
new ProcessStartInfo("dotnet", "--version") { RedirectStandardOutput = true }
)!;

await process.WaitForExitAsync();
var processId = process.Id;
Expand Down
1 change: 0 additions & 1 deletion PowerKit.Tests/StreamExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public async Task CopyToAsync_Progress_Test()
reports.Should().AllSatisfy(v => v.Should().BeInRange(0.0, 1.0));
reports[^1].Should().BeApproximately(1.0, precision: 1e-5);
}

}
12 changes: 10 additions & 2 deletions PowerKit.Tests/StringBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public class StringBuilderExtensionsTests
public void AppendIfNotEmpty_Test()
{
// Act & assert
new StringBuilder().AppendIfNotEmpty(',').ToString().Should().Be("");
new StringBuilder()
.AppendIfNotEmpty(',')
.ToString()
.Should()
.Be("");
new StringBuilder("hello").AppendIfNotEmpty(',').ToString().Should().Be("hello,");
new StringBuilder("a").AppendIfNotEmpty(',').Append("b").ToString().Should().Be("a,b");
}
Expand All @@ -20,7 +24,11 @@ public void AppendIfNotEmpty_Test()
public void Trim_Test()
{
// Act & assert
new StringBuilder(" hello ").Trim().ToString().Should().Be("hello");
new StringBuilder(" hello ")
.Trim()
.ToString()
.Should()
.Be("hello");
new StringBuilder(" hello").Trim().ToString().Should().Be("hello");
new StringBuilder("hello ").Trim().ToString().Should().Be("hello");
new StringBuilder("hello").Trim().ToString().Should().Be("hello");
Expand Down
2 changes: 1 addition & 1 deletion PowerKit/Extensions/ArrayPoolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable
using System;
using System.Buffers;
using System.Threading;
using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace PowerKit.Extensions;

Expand Down
5 changes: 3 additions & 2 deletions PowerKit/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

namespace PowerKit.Extensions;

Expand All @@ -24,7 +24,8 @@ internal static class AssemblyExtensions
public string? TryGetVersionString() =>
assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? assembly.GetName().Version?.ToString();
?.InformationalVersion
?? assembly.GetName().Version?.ToString();

/// <summary>
/// Reads the specified manifest resource as a string using the specified encoding.
Expand Down
17 changes: 4 additions & 13 deletions PowerKit/Extensions/AsyncEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public async IAsyncEnumerable<T> TakeAsync(

await using var enumerator = source.GetAsyncEnumerator(cancellationToken);

while (
currentCount < count
&& await enumerator.MoveNextAsync().ConfigureAwait(false)
)
while (currentCount < count && await enumerator.MoveNextAsync().ConfigureAwait(false))
{
yield return enumerator.Current;
currentCount++;
Expand All @@ -51,9 +48,7 @@ public async IAsyncEnumerable<TResult> SelectManyAsync<TResult>(
)
{
await foreach (
var item in source
.WithCancellation(cancellationToken)
.ConfigureAwait(false)
var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)
)
{
foreach (var result in transform(item))
Expand All @@ -66,16 +61,12 @@ var item in source
/// <summary>
/// Materializes the async sequence into a <see cref="List{T}" />.
/// </summary>
public async ValueTask<List<T>> ToListAsync(
CancellationToken cancellationToken = default
)
public async ValueTask<List<T>> ToListAsync(CancellationToken cancellationToken = default)
{
var list = new List<T>();

await foreach (
var item in source
.WithCancellation(cancellationToken)
.ConfigureAwait(false)
var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)
)
{
list.Add(item);
Expand Down
9 changes: 5 additions & 4 deletions PowerKit/Extensions/BinaryReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace PowerKit.Extensions;

Expand All @@ -15,9 +15,10 @@ internal static class BinaryReaderExtensions
/// <summary>
/// Gets a value indicating whether the reader has reached the end of the stream.
/// </summary>
public bool IsEndOfStream => reader.BaseStream.CanSeek
? reader.BaseStream.Position >= reader.BaseStream.Length
: reader.PeekChar() == -1;
public bool IsEndOfStream =>
reader.BaseStream.CanSeek
? reader.BaseStream.Position >= reader.BaseStream.Length
: reader.PeekChar() == -1;

/// <summary>
/// Skips bytes until the current position is aligned to the specified byte boundary.
Expand Down
2 changes: 1 addition & 1 deletion PowerKit/Extensions/BinaryWriterExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#nullable enable
using System.IO;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace PowerKit.Extensions;

Expand Down
2 changes: 1 addition & 1 deletion PowerKit/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace PowerKit.Extensions;

Expand Down
Loading