diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 878b324f..f807c2e5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,17 +17,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: - dotnet-version: '9.0.x' + dotnet-version: '10.0.x' - name: Create packages run: dotnet pack --configuration Release --output ./packages - name: Upload a Build Artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: NuGet packages path: packages/*.* @@ -40,12 +40,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout sources - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v4 - - uses: actions/download-artifact@v4 + uses: actions/setup-dotnet@v5 + - uses: actions/download-artifact@v6 with: name: NuGet packages path: packages diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d9bcbd8c..d6b92982 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,15 +18,16 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 - - uses: actions/setup-dotnet@v4 + - uses: actions/setup-dotnet@v5 with: dotnet-version: | 6.0.x 8.0.x 9.0.x + 10.0.x - name: Build & Test in Release Mode run: dotnet test --configuration Release --logger "GitHubActions" \ No newline at end of file diff --git a/CommonUtilities.sln b/CommonUtilities.sln deleted file mode 100644 index 7b71a5c3..00000000 --- a/CommonUtilities.sln +++ /dev/null @@ -1,107 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31717.71 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommonUtilities", "CommonUtilities", "{9CD34E8E-2082-46F9-B7EE-3DD4D1385B04}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities", "src\CommonUtilities\src\CommonUtilities.csproj", "{59CB2F45-CC0C-46C3-B6D6-581A7C123295}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.Test", "src\CommonUtilities\test\CommonUtilities.Test.csproj", "{EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommonUtilities.FileSystem", "CommonUtilities.FileSystem", "{6DC3D9F6-3394-46E3-B582-6A022FCCE397}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commonutilities.FileSystem", "src\CommonUtilities.FileSystem\src\Commonutilities.FileSystem.csproj", "{629247FB-648B-4F7D-9039-15D74102B4C5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.FileSystem.Test", "src\CommonUtilities.FileSystem\test\CommonUtilities.FileSystem.Test.csproj", "{C6AB748E-AEC2-4793-A8D6-F91F46CE098C}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommonUtilities.Registry", "CommonUtilities.Registry", "{EDF446DD-BE04-4FE2-93A5-6171A0EC8C82}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.Registry", "src\CommonUtilities.Registry\src\CommonUtilities.Registry.csproj", "{2BE46A1C-8D01-422D-8FD5-A2885305A92D}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.Registry.Test", "src\CommonUtilities.Registry\test\CommonUtilities.Registry.Test.csproj", "{375178FD-0D91-43B7-A731-1419808718E5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommonUtilities.DownloadManager", "CommonUtilities.DownloadManager", "{F306B877-4E2C-4D6F-BF68-96D2BD23FB69}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.DownloadManager", "src\CommonUtilities.DownloadManager\src\CommonUtilities.DownloadManager.csproj", "{9F9E1DA3-E4DC-4590-A3BF-09AA9286271E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.DownloadManager.Test", "src\CommonUtilities.DownloadManager\test\CommonUtilities.DownloadManager.Test.csproj", "{B67F61B6-489C-4036-9380-8B8DB45AB295}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CommonUtilities.SimplePipeline", "CommonUtilities.SimplePipeline", "{9D9B958B-7495-4614-8D0D-47587C8FEBC4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.SimplePipeline", "src\CommonUtilities.SimplePipeline\src\CommonUtilities.SimplePipeline.csproj", "{283BBAA8-482D-4DB5-9707-3F325D2AE41F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.SimplePipeline.Test", "src\CommonUtilities.SimplePipeline\test\CommonUtilities.SimplePipeline.Test.csproj", "{C8BF3F01-B1D5-4C29-9164-6DC7B9744589}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonUtilities.TestingUtilities", "src\CommonUtilities.TestingUtilities\CommonUtilities.TestingUtilities.csproj", "{99A3B9B4-6482-410A-A001-9D62F4B259CC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {59CB2F45-CC0C-46C3-B6D6-581A7C123295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59CB2F45-CC0C-46C3-B6D6-581A7C123295}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59CB2F45-CC0C-46C3-B6D6-581A7C123295}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59CB2F45-CC0C-46C3-B6D6-581A7C123295}.Release|Any CPU.Build.0 = Release|Any CPU - {EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4}.Release|Any CPU.Build.0 = Release|Any CPU - {629247FB-648B-4F7D-9039-15D74102B4C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {629247FB-648B-4F7D-9039-15D74102B4C5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {629247FB-648B-4F7D-9039-15D74102B4C5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {629247FB-648B-4F7D-9039-15D74102B4C5}.Release|Any CPU.Build.0 = Release|Any CPU - {C6AB748E-AEC2-4793-A8D6-F91F46CE098C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C6AB748E-AEC2-4793-A8D6-F91F46CE098C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C6AB748E-AEC2-4793-A8D6-F91F46CE098C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C6AB748E-AEC2-4793-A8D6-F91F46CE098C}.Release|Any CPU.Build.0 = Release|Any CPU - {2BE46A1C-8D01-422D-8FD5-A2885305A92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2BE46A1C-8D01-422D-8FD5-A2885305A92D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2BE46A1C-8D01-422D-8FD5-A2885305A92D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2BE46A1C-8D01-422D-8FD5-A2885305A92D}.Release|Any CPU.Build.0 = Release|Any CPU - {375178FD-0D91-43B7-A731-1419808718E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {375178FD-0D91-43B7-A731-1419808718E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {375178FD-0D91-43B7-A731-1419808718E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {375178FD-0D91-43B7-A731-1419808718E5}.Release|Any CPU.Build.0 = Release|Any CPU - {9F9E1DA3-E4DC-4590-A3BF-09AA9286271E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F9E1DA3-E4DC-4590-A3BF-09AA9286271E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F9E1DA3-E4DC-4590-A3BF-09AA9286271E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F9E1DA3-E4DC-4590-A3BF-09AA9286271E}.Release|Any CPU.Build.0 = Release|Any CPU - {B67F61B6-489C-4036-9380-8B8DB45AB295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B67F61B6-489C-4036-9380-8B8DB45AB295}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B67F61B6-489C-4036-9380-8B8DB45AB295}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B67F61B6-489C-4036-9380-8B8DB45AB295}.Release|Any CPU.Build.0 = Release|Any CPU - {283BBAA8-482D-4DB5-9707-3F325D2AE41F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {283BBAA8-482D-4DB5-9707-3F325D2AE41F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {283BBAA8-482D-4DB5-9707-3F325D2AE41F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {283BBAA8-482D-4DB5-9707-3F325D2AE41F}.Release|Any CPU.Build.0 = Release|Any CPU - {C8BF3F01-B1D5-4C29-9164-6DC7B9744589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C8BF3F01-B1D5-4C29-9164-6DC7B9744589}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C8BF3F01-B1D5-4C29-9164-6DC7B9744589}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C8BF3F01-B1D5-4C29-9164-6DC7B9744589}.Release|Any CPU.Build.0 = Release|Any CPU - {99A3B9B4-6482-410A-A001-9D62F4B259CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {99A3B9B4-6482-410A-A001-9D62F4B259CC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {99A3B9B4-6482-410A-A001-9D62F4B259CC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {99A3B9B4-6482-410A-A001-9D62F4B259CC}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {59CB2F45-CC0C-46C3-B6D6-581A7C123295} = {9CD34E8E-2082-46F9-B7EE-3DD4D1385B04} - {EAEF69D0-BA59-4397-ABC0-5E7ED397FDB4} = {9CD34E8E-2082-46F9-B7EE-3DD4D1385B04} - {629247FB-648B-4F7D-9039-15D74102B4C5} = {6DC3D9F6-3394-46E3-B582-6A022FCCE397} - {C6AB748E-AEC2-4793-A8D6-F91F46CE098C} = {6DC3D9F6-3394-46E3-B582-6A022FCCE397} - {2BE46A1C-8D01-422D-8FD5-A2885305A92D} = {EDF446DD-BE04-4FE2-93A5-6171A0EC8C82} - {375178FD-0D91-43B7-A731-1419808718E5} = {EDF446DD-BE04-4FE2-93A5-6171A0EC8C82} - {9F9E1DA3-E4DC-4590-A3BF-09AA9286271E} = {F306B877-4E2C-4D6F-BF68-96D2BD23FB69} - {B67F61B6-489C-4036-9380-8B8DB45AB295} = {F306B877-4E2C-4D6F-BF68-96D2BD23FB69} - {283BBAA8-482D-4DB5-9707-3F325D2AE41F} = {9D9B958B-7495-4614-8D0D-47587C8FEBC4} - {C8BF3F01-B1D5-4C29-9164-6DC7B9744589} = {9D9B958B-7495-4614-8D0D-47587C8FEBC4} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {FAF1C2A9-02FC-459D-BE1E-BDB46E72F077} - EndGlobalSection -EndGlobal diff --git a/CommonUtilities.slnx b/CommonUtilities.slnx new file mode 100644 index 00000000..da8c736f --- /dev/null +++ b/CommonUtilities.slnx @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Directory.Build.props b/Directory.Build.props index f7a8bf77..9fa329ed 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -25,7 +25,7 @@ all - 3.7.115 + 3.9.50 diff --git a/src/CommonUtilities.DownloadManager/src/CommonUtilities.DownloadManager.csproj b/src/CommonUtilities.DownloadManager/src/CommonUtilities.DownloadManager.csproj index da8222cb..b3c74e58 100644 --- a/src/CommonUtilities.DownloadManager/src/CommonUtilities.DownloadManager.csproj +++ b/src/CommonUtilities.DownloadManager/src/CommonUtilities.DownloadManager.csproj @@ -30,8 +30,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/CommonUtilities.DownloadManager/src/DownloadManager.cs b/src/CommonUtilities.DownloadManager/src/DownloadManager.cs index 14430dff..55f7b156 100644 --- a/src/CommonUtilities.DownloadManager/src/DownloadManager.cs +++ b/src/CommonUtilities.DownloadManager/src/DownloadManager.cs @@ -90,7 +90,7 @@ public Task DownloadAsync( if (!uri.IsAbsoluteUri) throw new ArgumentException("Uri must be absolute.", nameof(uri)); - _logger?.LogTrace($"Download requested: {uri.AbsoluteUri}"); + _logger?.LogTrace("Download requested: {Uri}", uri.AbsoluteUri); if (uri is { IsFile: false, IsUnc: false }) { @@ -139,7 +139,7 @@ private async Task DownloadWithRetry( var length = outputStream.Length; try { - _logger?.LogTrace($"Attempting download '{uri.AbsoluteUri}' using provider '{provider.Name}'"); + _logger?.LogTrace("Attempting download '{Uri}' using provider '{ProviderName}'", uri.AbsoluteUri, provider.Name); var summary = await provider.DownloadAsync(uri, outputStream, status => { @@ -193,7 +193,7 @@ private async Task DownloadWithRetry( } } - _logger?.LogInformation($"Download of '{uri.AbsoluteUri}' succeeded using provider '{provider.Name}'"); + _logger?.LogInformation("Download of '{Uri}' succeeded using provider '{ProviderName}'", uri.AbsoluteUri, provider.Name); _leastRecentlyUsedDownloadProviders.LastSuccessfulProvider = provider.Name; summary.DownloadProvider = provider.Name; @@ -207,7 +207,7 @@ private async Task DownloadWithRetry( catch (Exception ex) { failureList.Add(new DownloadFailureInformation(ex, provider.Name)); - _logger?.LogTrace($"Download failed using {provider.Name} provider. {ex}"); + _logger?.LogTrace("Download failed using {Provider} provider. {Exception}", provider.Name, ex); if (provider.Equals(providers.LastOrDefault())) throw new DownloadFailedException(failureList); @@ -222,7 +222,7 @@ private async Task DownloadWithRetry( if (millisecondsTimeout <= 0) continue; - _logger?.LogTrace($"Sleeping {millisecondsTimeout} before retrying download."); + _logger?.LogTrace("Sleeping {WaitTime} before retrying download.", millisecondsTimeout); await Task.Delay(TimeSpan.FromMilliseconds(millisecondsTimeout), cancellationToken); } diff --git a/src/CommonUtilities.DownloadManager/src/Providers/HttpClientDownloader.cs b/src/CommonUtilities.DownloadManager/src/Providers/HttpClientDownloader.cs index 581a9639..fc2609d9 100644 --- a/src/CommonUtilities.DownloadManager/src/Providers/HttpClientDownloader.cs +++ b/src/CommonUtilities.DownloadManager/src/Providers/HttpClientDownloader.cs @@ -143,15 +143,15 @@ private static HttpRequestMessage CreateRequest(Uri uri) if (cancellationToken.IsCancellationRequested) { _logger?.LogTrace( - "HttpClient error with '" + uri.AbsoluteUri + "' - " + errorMessage); + "HttpClient error with '{Uri}' - {Message}", uri.AbsoluteUri, errorMessage); cancellationToken.ThrowIfCancellationRequested(); } - _logger?.LogTrace("WebClient error - '" + uri.AbsoluteUri + "'."); + _logger?.LogTrace("WebClient error - '{Uri}'.", uri.AbsoluteUri); throw; } catch (Exception ex) { - _logger?.LogError(ex, "General exception error in HttpClient"); + _logger?.LogError(ex, "General exception error in HttpClient: {Message}", ex.Message); throw; } finally diff --git a/src/CommonUtilities.DownloadManager/src/Providers/WebClientDownloader.cs b/src/CommonUtilities.DownloadManager/src/Providers/WebClientDownloader.cs index acfea4c4..4031c19f 100644 --- a/src/CommonUtilities.DownloadManager/src/Providers/WebClientDownloader.cs +++ b/src/CommonUtilities.DownloadManager/src/Providers/WebClientDownloader.cs @@ -91,13 +91,12 @@ protected override async Task DownloadAsyncCore( : "DownloadCore failed"; if (cancellationToken.IsCancellationRequested) { - _logger?.LogTrace("WebClient error '" + ex.Status + "' with '" + uri.AbsoluteUri + "' - " + - message); + _logger?.LogTrace("WebClient error '{Status}' with '{Uri}' - {Message}", ex.Status, uri.AbsoluteUri, message); cancellationToken.ThrowIfCancellationRequested(); } else { - _logger?.LogTrace("WebClient error '" + ex.Status + "' with '" + uri.AbsoluteUri + "'."); + _logger?.LogTrace("WebClient error '{Status}' with '{Uri}'.", ex.Status, uri.AbsoluteUri); throw; } } @@ -160,7 +159,7 @@ private static HttpWebRequest CreateRequest(Uri uri, DownloadOptions? downloadOp success = true; return httpWebResponse; default: - _logger?.LogTrace($"WebResponse error for '{uri.AbsoluteUri}' ({httpWebResponse.StatusCode})."); + _logger?.LogTrace("WebResponse error for '{Uri}' ({Status}).", uri.AbsoluteUri, httpWebResponse.StatusCode); break; } } @@ -171,12 +170,11 @@ private static HttpWebRequest CreateRequest(Uri uri, DownloadOptions? downloadOp : "GetWebResponse failed"; if (cancellationToken.IsCancellationRequested) { - _logger?.LogTrace( - "WebClient error '" + ex.Status + "' with '" + uri.AbsoluteUri + "' - " + errorMessage); + _logger?.LogTrace("WebClient error '{Status}' with '{Uri}' - {Message}", ex.Status, uri.AbsoluteUri, errorMessage); cancellationToken.ThrowIfCancellationRequested(); } - _logger?.LogTrace("WebClient error '" + ex.Status + "' - '" + uri.AbsoluteUri + "'."); + _logger?.LogTrace("WebClient error '{Status}' - '{Uri}'.", ex.Status, uri.AbsoluteUri); throw; } catch (Exception ex) diff --git a/src/CommonUtilities.DownloadManager/src/Validation/HashDownloadValidator.cs b/src/CommonUtilities.DownloadManager/src/Validation/HashDownloadValidator.cs index 33364d89..636952e5 100644 --- a/src/CommonUtilities.DownloadManager/src/Validation/HashDownloadValidator.cs +++ b/src/CommonUtilities.DownloadManager/src/Validation/HashDownloadValidator.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using System.Threading; using System.Threading.Tasks; using AnakinRaW.CommonUtilities.Hashing; diff --git a/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj b/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj index 41050136..4ead415b 100644 --- a/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj +++ b/src/CommonUtilities.DownloadManager/test/CommonUtilities.DownloadManager.Test.csproj @@ -1,8 +1,8 @@ - net9.0;net8.0 - $(TargetFrameworks);net48 + net10.0;net8.0 + $(TargetFrameworks);net481 false true @@ -17,16 +17,16 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CommonUtilities.DownloadManager/test/DownloadManagerTest.cs b/src/CommonUtilities.DownloadManager/test/DownloadManagerTest.cs index be76d264..58cb97b9 100644 --- a/src/CommonUtilities.DownloadManager/test/DownloadManagerTest.cs +++ b/src/CommonUtilities.DownloadManager/test/DownloadManagerTest.cs @@ -216,7 +216,7 @@ public async Task DownloadAsync_GithubApi() await DownloadAsyncTest(provider, uri, true, new DownloadOptions { UserAgent = "AnakinRaw.DownloadManager.Test" }, null); - Assert.Equal(2566, FileSystem.File.ReadAllText(Destination).Length); + Assert.Equal(2620, FileSystem.File.ReadAllText(Destination).Length); } #if NETFRAMEWORK @@ -405,12 +405,12 @@ public async Task DownloadAsync_CancellationDoesNotRetry_Throws() { counter++; cts.Cancel(); - }, ServiceProvider); + }); var provider2 = new DelegatingFileDownloadProvider("B", () => { counter++; cts.Cancel(); - }, ServiceProvider); + }); manager.AddDownloadProvider(provider1); manager.AddDownloadProvider(provider2); @@ -470,7 +470,7 @@ public Task Validate(Stream stream, long downloadedBytes, CancellationToke } } - private class DelegatingFileDownloadProvider(string name, Action onDownload, IServiceProvider serviceProvider) : IDownloadProvider + private class DelegatingFileDownloadProvider(string name, Action onDownload) : IDownloadProvider { public string Name => name; @@ -549,10 +549,10 @@ public override void Write(byte[] buffer, int offset, int count) throw new NotImplementedException(); } - public override bool CanRead { get; } - public override bool CanSeek { get; } + public override bool CanRead => false; + public override bool CanSeek => false; public override bool CanWrite => false; - public override long Length { get; } + public override long Length => 0; public override long Position { get; set; } } } \ No newline at end of file diff --git a/src/CommonUtilities.DownloadManager/test/Providers/HttpClientDownloadTest.cs b/src/CommonUtilities.DownloadManager/test/Providers/HttpClientDownloadTest.cs index 84b48446..184248a2 100644 --- a/src/CommonUtilities.DownloadManager/test/Providers/HttpClientDownloadTest.cs +++ b/src/CommonUtilities.DownloadManager/test/Providers/HttpClientDownloadTest.cs @@ -5,6 +5,7 @@ namespace AnakinRaW.CommonUtilities.DownloadManager.Test.Providers; +// ReSharper disable once UnusedMember.Global public class HttpClientDownloadTest : InternetDownloadTest { protected override Type ExpectedSourceNotFoundExceptionType => typeof(HttpRequestException); diff --git a/src/CommonUtilities.DownloadManager/test/Validation/HashDownloadValidatorTest.cs b/src/CommonUtilities.DownloadManager/test/Validation/HashDownloadValidatorTest.cs index 10d3ac41..1b83269c 100644 --- a/src/CommonUtilities.DownloadManager/test/Validation/HashDownloadValidatorTest.cs +++ b/src/CommonUtilities.DownloadManager/test/Validation/HashDownloadValidatorTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Threading.Tasks; using AnakinRaW.CommonUtilities.DownloadManager.Validation; @@ -8,6 +7,9 @@ using AnakinRaW.CommonUtilities.Testing; using Microsoft.Extensions.DependencyInjection; using Xunit; +#if !NET +using System.Globalization; +#endif namespace AnakinRaW.CommonUtilities.DownloadManager.Test.Validation; @@ -188,10 +190,10 @@ public override void Write(byte[] buffer, int offset, int count) throw new NotImplementedException(); } - public override bool CanRead { get; } - public override bool CanSeek { get; } - public override bool CanWrite { get; } - public override long Length { get; } + public override bool CanRead => false; + public override bool CanSeek => false; + public override bool CanWrite => false; + public override long Length => 0; public override long Position { get; set; } } } \ No newline at end of file diff --git a/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj b/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj index e2e2045d..06387b7c 100644 --- a/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj +++ b/src/CommonUtilities.FileSystem/src/Commonutilities.FileSystem.csproj @@ -26,14 +26,14 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/CommonUtilities.FileSystem/src/Extensions/FileSystemExtensions.cs b/src/CommonUtilities.FileSystem/src/Extensions/FileSystemExtensions.cs index 032051d1..e972643f 100644 --- a/src/CommonUtilities.FileSystem/src/Extensions/FileSystemExtensions.cs +++ b/src/CommonUtilities.FileSystem/src/Extensions/FileSystemExtensions.cs @@ -13,17 +13,15 @@ public static class FileSystemExtensions /// Tries to create a new file and returns an open to the created file, or if the file could not be created. /// An existing file will be overwritten. /// - /// /// The file's location. /// A bitwise combination of the enumeration values that determines how the file can be accessed by the object. /// A bitwise combination of the enumeration values that determines how the file will be shared by processes. /// Number of retry attempts tempts until the operation fails. /// Delay time in ms between each new attempt. + /// /// Open file stream or if the file could not be created. /// or is . - public static FileSystemStream? CreateFileWithRetry( - this IFileSystem fs, - string path, + public static FileSystemStream? CreateFileWithRetry(this IFileSystem fs, string path, FileAccess fileAccess = FileAccess.ReadWrite, FileShare fileShare = FileShare.None, int retryCount = 2, @@ -43,9 +41,9 @@ public static class FileSystemExtensions /// /// Tries to create a new unique folder within the current users temporary directory. /// - /// /// Number of retry attempts tempts until the operation fails. /// Delay time in ms between each new attempt. + /// /// The of the created folder or . /// is . public static IDirectoryInfo? CreateTemporaryFolderInTempWithRetry(this IFileSystem fs, int retryCount = 2, int retryDelay = 500) diff --git a/src/CommonUtilities.FileSystem/src/Extensions/FileSystemInfoExtensions.cs b/src/CommonUtilities.FileSystem/src/Extensions/FileSystemInfoExtensions.cs index e9375ad6..49c24fac 100644 --- a/src/CommonUtilities.FileSystem/src/Extensions/FileSystemInfoExtensions.cs +++ b/src/CommonUtilities.FileSystem/src/Extensions/FileSystemInfoExtensions.cs @@ -27,33 +27,33 @@ public static long GetDriveFreeSpace(this IFileSystemInfo fsItem) /// /// Removes attributes from a given filesystem entry. /// - /// The target filesystem handle. /// Attributes to remove. - /// is . - public static void RemoveAttributes(this IFileSystemInfo fsInfo, FileAttributes attributesToRemove) + /// Some file or directory at the targeted drive. + /// is . + public static void RemoveAttributes(this IFileSystemInfo fsItem, FileAttributes attributesToRemove) { - if (fsInfo == null) - throw new ArgumentNullException(nameof(fsInfo)); + if (fsItem == null) + throw new ArgumentNullException(nameof(fsItem)); - var currentAttributes = fsInfo.Attributes; + var currentAttributes = fsItem.Attributes; var newAttributes = currentAttributes & ~attributesToRemove; - fsInfo.Attributes = newAttributes; - fsInfo.Refresh(); + fsItem.Attributes = newAttributes; + fsItem.Refresh(); } /// /// Set attributes from a given filesystem entry. /// - /// The target filesystem handle. /// Attributes to add. - /// is . - public static void SetAttributes(this IFileSystemInfo fsInfo, FileAttributes attributesToAdd) + /// Some file or directory at the targeted drive. + /// is . + public static void SetAttributes(this IFileSystemInfo fsItem, FileAttributes attributesToAdd) { - if (fsInfo == null) - throw new ArgumentNullException(nameof(fsInfo)); + if (fsItem == null) + throw new ArgumentNullException(nameof(fsItem)); - var currentAttributes = fsInfo.Attributes; - fsInfo.Attributes = currentAttributes | attributesToAdd; - fsInfo.Refresh(); + var currentAttributes = fsItem.Attributes; + fsItem.Attributes = currentAttributes | attributesToAdd; + fsItem.Refresh(); } } \ No newline at end of file diff --git a/src/CommonUtilities.FileSystem/src/Extensions/PathExtensions.NetFramework.cs b/src/CommonUtilities.FileSystem/src/Extensions/PathExtensions.NetFramework.cs index 9608d9cf..28bac173 100644 --- a/src/CommonUtilities.FileSystem/src/Extensions/PathExtensions.NetFramework.cs +++ b/src/CommonUtilities.FileSystem/src/Extensions/PathExtensions.NetFramework.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using System; using System.IO; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem; @@ -22,7 +23,7 @@ public static partial class PathExtensions /// /// The path to search for an extension. /// if the characters that follow the last directory separator character or volume separator - /// in the path include a period (".") followed by one or more characters; otherwise, . + /// in the path include a period ('.') followed by one or more characters; otherwise, . public static bool HasExtension(this IPath _, ReadOnlySpan path) { for (var i = path.Length - 1; i >= 0; i--) @@ -347,7 +348,7 @@ private static bool IsDeviceUNC(ReadOnlySpan path) private static bool IsExtended(ReadOnlySpan path) { // While paths like "//?/C:/" will work, they're treated the same as "\\.\" paths. - // Skipping of normalization will *only* occur if back slashes ('\') are used. + // Skipping of normalization will *only* occur if backslashes ('\') are used. return path.Length >= DevicePrefixLength && path[0] == '\\' && (path[1] == '\\' || path[1] == '?') diff --git a/src/CommonUtilities.FileSystem/src/Utilities/ValueStringBuilder.cs b/src/CommonUtilities.FileSystem/src/Utilities/ValueStringBuilder.cs index 1e4e1cec..88952b52 100644 --- a/src/CommonUtilities.FileSystem/src/Utilities/ValueStringBuilder.cs +++ b/src/CommonUtilities.FileSystem/src/Utilities/ValueStringBuilder.cs @@ -270,13 +270,13 @@ private void Grow(int additionalCapacityBeyondPos) Debug.Assert(additionalCapacityBeyondPos > 0); Debug.Assert(_pos > _chars.Length - additionalCapacityBeyondPos, "Grow called incorrectly, no resize is needed."); - const uint ArrayMaxLength = 0x7FFFFFC7; // same as Array.MaxLength + const uint arrayMaxLength = 0x7FFFFFC7; // same as Array.MaxLength // Increase to at least the required size (_pos + additionalCapacityBeyondPos), but try // to double the size if possible, bounding the doubling to not go beyond the max array length. var newCapacity = (int)Math.Max( (uint)(_pos + additionalCapacityBeyondPos), - Math.Min((uint)_chars.Length * 2, ArrayMaxLength)); + Math.Min((uint)_chars.Length * 2, arrayMaxLength)); // Make sure to let Rent throw an exception if the caller has a bug and the desired capacity is negative. // This could also go negative if the actual required length wraps around. diff --git a/src/CommonUtilities.FileSystem/src/Windows/WindowsFileSystemExtensions.cs b/src/CommonUtilities.FileSystem/src/Windows/WindowsFileSystemExtensions.cs index 603635ea..15a3447a 100644 --- a/src/CommonUtilities.FileSystem/src/Windows/WindowsFileSystemExtensions.cs +++ b/src/CommonUtilities.FileSystem/src/Windows/WindowsFileSystemExtensions.cs @@ -68,7 +68,7 @@ private static bool AddPendingFileRename(string source, string? destination) try { using var registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default); - using var subKey = registryKey.CreateSubKey(sessionManagerKeyPath)!; + using var subKey = registryKey.CreateSubKey(sessionManagerKeyPath); var stringBuilder = new StringBuilder("\\??\\" + source + "\0"); if (!string.IsNullOrEmpty(destination)) stringBuilder.Append("\\??\\" + destination); diff --git a/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj b/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj index 78a56700..f98eaedc 100644 --- a/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj +++ b/src/CommonUtilities.FileSystem/test/CommonUtilities.FileSystem.Test.csproj @@ -1,8 +1,8 @@ - net9.0;net8.0 - $(TargetFrameworks);net48 + net10.0;net8.0 + $(TargetFrameworks);net481 false true enable @@ -15,7 +15,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -23,14 +23,14 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetDirectoryName.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetDirectoryName.cs index 8bf80586..aecfd0d8 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetDirectoryName.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetDirectoryName.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetExtension.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetExtension.cs index f6011ec5..0510d357 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetExtension.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetExtension.cs @@ -2,6 +2,7 @@ using System.IO.Abstractions; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; @@ -11,12 +12,12 @@ public class GetExtensionTest public static TheoryData TestData_GetExtension => new() { - { @"file.exe", ".exe" }, - { @"file", "" }, - { @"file.", "" }, - { @"file.s", ".s" }, - { @"test/file", "" }, - { @"test/file.extension", ".extension" }, + { "file.exe", ".exe" }, + { "file", "" }, + { "file.", "" }, + { "file.s", ".s" }, + { "test/file", "" }, + { "test/file.extension", ".extension" }, { @"test\file", "" }, { @"test\file.extension", ".extension" }, { "file.e xe", ".e xe"}, diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetFileName.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetFileName.cs index c591fd38..0b3f3218 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetFileName.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetFileName.cs @@ -5,6 +5,7 @@ using AnakinRaW.CommonUtilities.Testing; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetPathRoot.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetPathRoot.cs index 370a5fc6..464f5d83 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetPathRoot.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetPathRoot.cs @@ -4,6 +4,7 @@ using AnakinRaW.CommonUtilities.Testing; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; @@ -28,44 +29,44 @@ public void GetPathRoot_Basic() Assert.True(_fileSystem.Path.IsPathRooted(cwd)); - Assert.Equal(string.Empty, _fileSystem.Path.GetPathRoot(@"file.exe")); - Assert.True(_fileSystem.Path.GetPathRoot(@"file.exe".AsSpan()).IsEmpty); + Assert.Equal(string.Empty, _fileSystem.Path.GetPathRoot("file.exe")); + Assert.True(_fileSystem.Path.GetPathRoot("file.exe".AsSpan()).IsEmpty); Assert.False(_fileSystem.Path.IsPathRooted("file.exe")); } [PlatformSpecificTheory(TestPlatformIdentifier.Linux)] - [InlineData(@"/../../.././tmp/..")] - [InlineData(@"/../../../")] - [InlineData(@"/../../../tmp/bar/..")] - [InlineData(@"/../.././././bar/../../../")] - [InlineData(@"/../../././tmp/..")] - [InlineData(@"/../../tmp/../../")] - [InlineData(@"/../../tmp/bar/..")] - [InlineData(@"/../tmp/../..")] - [InlineData(@"/././../../../../")] - [InlineData(@"/././../../../")] - [InlineData(@"/./././bar/../../../")] - [InlineData(@"/")] - [InlineData(@"/bar")] - [InlineData(@"/bar/././././../../..")] - [InlineData(@"/bar/tmp")] - [InlineData(@"/tmp/..")] - [InlineData(@"/tmp/../../../../../bar")] - [InlineData(@"/tmp/../../../bar")] - [InlineData(@"/tmp/../bar/../..")] - [InlineData(@"/tmp/bar")] - [InlineData(@"/tmp/bar/..")] + [InlineData("/../../.././tmp/..")] + [InlineData("/../../../")] + [InlineData("/../../../tmp/bar/..")] + [InlineData("/../.././././bar/../../../")] + [InlineData("/../../././tmp/..")] + [InlineData("/../../tmp/../../")] + [InlineData("/../../tmp/bar/..")] + [InlineData("/../tmp/../..")] + [InlineData("/././../../../../")] + [InlineData("/././../../../")] + [InlineData("/./././bar/../../../")] + [InlineData("/")] + [InlineData("/bar")] + [InlineData("/bar/././././../../..")] + [InlineData("/bar/tmp")] + [InlineData("/tmp/..")] + [InlineData("/tmp/../../../../../bar")] + [InlineData("/tmp/../../../bar")] + [InlineData("/tmp/../bar/../..")] + [InlineData("/tmp/bar")] + [InlineData("/tmp/bar/..")] public void GePathRoot_Unix(string path) { - var expected = @"/"; + var expected = "/"; Assert.Equal(expected, _fileSystem.Path.GetPathRoot(path)); PathAssert.Equal(expected.AsSpan(), _fileSystem.Path.GetPathRoot(path.AsSpan())); } public static TheoryData TestData_GetPathRoot_Windows => new() { - { @"C:", @"C:" }, + { "C:", "C:" }, { @"C:\", @"C:\" }, { @"C:\\", @"C:\" }, { @"C:\foo1", @"C:\" }, diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetRelativePathEx.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetRelativePathEx.cs index a76cfa60..3beb813c 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetRelativePathEx.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.GetRelativePathEx.cs @@ -12,30 +12,30 @@ public class GetRelativePathExTest private readonly IFileSystem _fileSystem = new RealFileSystem(); [PlatformSpecificTheory(TestPlatformIdentifier.Windows)] - [InlineData(@"C:\", @"C:\", @".")] - [InlineData(@"C:\a", @"C:\a\", @".")] - [InlineData(@"C:\A", @"C:\a\", @".")] - [InlineData(@"C:\a\", @"C:\a", @".")] - [InlineData(@"C:\", @"C:\b", @"b")] + [InlineData(@"C:\", @"C:\", ".")] + [InlineData(@"C:\a", @"C:\a\", ".")] + [InlineData(@"C:\A", @"C:\a\", ".")] + [InlineData(@"C:\a\", @"C:\a", ".")] + [InlineData(@"C:\", @"C:\b", "b")] [InlineData(@"C:\a", @"C:\b", @"..\b")] [InlineData(@"C:\a", @"C:\b\", @"..\b\")] - [InlineData(@"C:\a\b", @"C:\a", @"..")] - [InlineData(@"C:\a\b", @"C:\a\", @"..")] - [InlineData(@"C:\a\b\", @"C:\a", @"..")] - [InlineData(@"C:\a\b\", @"C:\a\", @"..")] - [InlineData(@"C:\a\b\c", @"C:\a\b", @"..")] - [InlineData(@"C:\a\b\c", @"C:\a\b\", @"..")] + [InlineData(@"C:\a\b", @"C:\a", "..")] + [InlineData(@"C:\a\b", @"C:\a\", "..")] + [InlineData(@"C:\a\b\", @"C:\a", "..")] + [InlineData(@"C:\a\b\", @"C:\a\", "..")] + [InlineData(@"C:\a\b\c", @"C:\a\b", "..")] + [InlineData(@"C:\a\b\c", @"C:\a\b\", "..")] [InlineData(@"C:\a\b\c", @"C:\a", @"..\..")] [InlineData(@"C:\a\b\c", @"C:\a\", @"..\..")] - [InlineData(@"C:\a\b\c\", @"C:\a\b", @"..")] - [InlineData(@"C:\a\b\c\", @"C:\a\b\", @"..")] + [InlineData(@"C:\a\b\c\", @"C:\a\b", "..")] + [InlineData(@"C:\a\b\c\", @"C:\a\b\", "..")] [InlineData(@"C:\a\b\c\", @"C:\a", @"..\..")] [InlineData(@"C:\a\b\c\", @"C:\a\", @"..\..")] [InlineData(@"C:\a\", @"C:\b", @"..\b")] - [InlineData(@"C:\a", @"C:\a\b", @"b")] - [InlineData(@"C:\a", @"C:\A\b", @"b")] + [InlineData(@"C:\a", @"C:\a\b", "b")] + [InlineData(@"C:\a", @"C:\A\b", "b")] [InlineData(@"C:\a", @"C:\b\c", @"..\b\c")] - [InlineData(@"C:\a\", @"C:\a\b", @"b")] + [InlineData(@"C:\a\", @"C:\a\b", "b")] [InlineData(@"C:\", @"D:\", @"D:\")] [InlineData(@"C:\", @"D:\b", @"D:\b")] [InlineData(@"C:\", @"D:\b\", @"D:\b\")] @@ -46,7 +46,7 @@ public class GetRelativePathExTest [InlineData(@"C:\", @"\\LOCALHOST\Share\b", @"\\LOCALHOST\Share\b")] [InlineData(@"\\LOCALHOST\Share\a", @"\\LOCALHOST\Share\b", @"..\b")] // Tests which don't exist from .NET runtime - [InlineData(@"C:\a", @"C:\a\.\.", @".")] + [InlineData(@"C:\a", @"C:\a\.\.", ".")] public void GetRelativePathEx_FromAbsolute_Windows(string root, string path, string expected) { var result = _fileSystem.Path.GetRelativePathEx(root, path); @@ -60,7 +60,7 @@ public void GetRelativePathEx_FromAbsolute_Windows(string root, string path, str } [PlatformSpecificTheory(TestPlatformIdentifier.Windows)] - [InlineData(@"C:\a", @"b", @"b")] + [InlineData(@"C:\a", "b", "b")] [InlineData(@"C:\a", @"a\b", @"a\b")] [InlineData(@"C:\a", @"a\..\b", @"a\..\b")] public void GetRelativePathEx_FromRelative_Windows(string root, string path, string expected) @@ -70,11 +70,11 @@ public void GetRelativePathEx_FromRelative_Windows(string root, string path, str } [PlatformSpecificTheory(TestPlatformIdentifier.Windows)] - [InlineData(@"C:\", @"C:a", @"current\a")] - [InlineData(@"C:\a", @"C:a", @"..\current\a")] + [InlineData(@"C:\", "C:a", @"current\a")] + [InlineData(@"C:\a", "C:a", @"..\current\a")] [InlineData(@"C:\a", @"C:a\", @"..\current\a\")] [InlineData(@"C:\a\b", @"C:a\b", @"..\..\current\a\b")] - [InlineData(@"C:\a", @"X:a", @"X:\a")] + [InlineData(@"C:\a", "X:a", @"X:\a")] public void GetRelativePathEx_FromDriveRelative_Windows(string root, string path, string expected) { var fileSystem = new MockFileSystem(); @@ -92,22 +92,22 @@ public void GetRelativePathEx_FromDriveRelative_Windows(string root, string path } [PlatformSpecificTheory(TestPlatformIdentifier.Linux)] - [InlineData("/", @"/", @".")] - [InlineData("/a", @"/a/", @".")] - [InlineData("/a/", @"/a", @".")] - [InlineData("/", @"/b", @"b")] - [InlineData("/a", @"/b", @"../b")] - [InlineData("/a/", @"/b", @"../b")] - [InlineData("/a", @"/a/b", @"b")] - [InlineData("/a", @"/b/c", @"../b/c")] - [InlineData("/a/", @"/a/b", @"b")] - [InlineData("/ab", @"/a", @"../a")] - [InlineData("/a", @"/ab", @"../ab")] - [InlineData("/a", @"/A/", @"../A/")] - [InlineData("/a/", @"/A", @"../A")] - [InlineData("/a/", @"/A/b", @"../A/b")] + [InlineData("/", "/", ".")] + [InlineData("/a", "/a/", ".")] + [InlineData("/a/", "/a", ".")] + [InlineData("/", "/b", "b")] + [InlineData("/a", "/b", "../b")] + [InlineData("/a/", "/b", "../b")] + [InlineData("/a", "/a/b", "b")] + [InlineData("/a", "/b/c", "../b/c")] + [InlineData("/a/", "/a/b", "b")] + [InlineData("/ab", "/a", "../a")] + [InlineData("/a", "/ab", "../ab")] + [InlineData("/a", "/A/", "../A/")] + [InlineData("/a/", "/A", "../A")] + [InlineData("/a/", "/A/b", "../A/b")] // Tests which don't exist from .NET runtime - [InlineData(@"/a", @"/a/./.", @".")] + [InlineData("/a", "/a/./.", ".")] public void GetRelativePathEx_FromAbsolute_Linux(string root, string path, string expected) { var result = _fileSystem.Path.GetRelativePathEx(root, path); diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasLeadingPathSeparator.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasLeadingPathSeparator.cs index 27fd8af4..e33c6220 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasLeadingPathSeparator.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasLeadingPathSeparator.cs @@ -3,6 +3,7 @@ using AnakinRaW.CommonUtilities.Testing; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; @@ -25,19 +26,19 @@ public void HasLeadingPathSeparator(string? input) public static TheoryData TestData_StartsWithDirectorySeparator_Windows => new() { { @"\", true }, - { @"/", true }, + { "/", true }, { @"C:\folder\", false }, - { @"C:/folder/", false }, + { "C:/folder/", false }, { @"C:\", false }, - { @"C:/", false }, + { "C:/", false }, { @"\\", true }, - { @"//", true }, + { "//", true }, { @"\\server\share\", true }, { @"\\?\UNC\a\", true }, { @"\\?\C:\", true }, { @"\\?\UNC\", true }, { @"\folder", true }, - { @"folder", false }, + { "folder", false }, }; [PlatformSpecificTheory(TestPlatformIdentifier.Windows)] @@ -51,11 +52,11 @@ public void HasLeadingPathSeparator_Windows(string input, bool expected) public static TheoryData TestData_StartsWithDirectorySeparator_Linux => new() { - { @"/", true }, - { @"/folder/", true }, - { @"//", true }, - { @"folder", false }, - { @"/folder", true } + { "/", true }, + { "/folder/", true }, + { "//", true }, + { "folder", false }, + { "/folder", true } }; [PlatformSpecificTheory(TestPlatformIdentifier.Linux)] diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasTrailingPathSeparator.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasTrailingPathSeparator.cs index b9e555e6..3422769f 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasTrailingPathSeparator.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.HasTrailingPathSeparator.cs @@ -6,6 +6,7 @@ #if NET using System.IO; #endif +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; @@ -31,19 +32,19 @@ public void HasTrailingPathSeparator(string? input) public static TheoryData TestData_EndsInDirectorySeparator_Windows => new() { { @"\", true }, - { @"/", true }, + { "/", true }, { @"C:\folder\", true }, - { @"C:/folder/", true }, + { "C:/folder/", true }, { @"C:\", true }, - { @"C:/", true }, + { "C:/", true }, { @"\\", true }, - { @"//", true }, + { "//", true }, { @"\\server\share\", true }, { @"\\?\UNC\a\", true }, { @"\\?\C:\", true }, { @"\\?\UNC\", true }, { @"folder\", true }, - { @"folder", false }, + { "folder", false }, }; [PlatformSpecificTheory(TestPlatformIdentifier.Windows)] @@ -59,11 +60,11 @@ public void HasTrailingPathSeparator_Windows(string input, bool expected) public static TheoryData TestData_EndsInDirectorySeparator_Linux => new() { - { @"/", true }, - { @"/folder/", true }, - { @"//", true }, - { @"folder", false }, - { @"folder/", true } + { "/", true }, + { "/folder/", true }, + { "//", true }, + { "folder", false }, + { "folder/", true } }; [PlatformSpecificTheory(TestPlatformIdentifier.Linux)] diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.IsPathFullyQualified.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.IsPathFullyQualified.cs index 663c5ec8..71886a34 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.IsPathFullyQualified.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.IsPathFullyQualified.cs @@ -46,10 +46,10 @@ public void IsPathFullyQualified_Windows_Invalid(string path) [InlineData(@"C:\foo1")] [InlineData(@"C:\\")] [InlineData(@"C:\\foo2")] - [InlineData(@"C:/")] - [InlineData(@"C:/foo1")] - [InlineData(@"C://")] - [InlineData(@"C://foo2")] + [InlineData("C:/")] + [InlineData("C:/foo1")] + [InlineData("C://")] + [InlineData("C://foo2")] public void IsPathFullyQualified_Windows_Valid(string path) { Assert.True(_fileSystem.Path.IsPathFullyQualified(path)); @@ -63,9 +63,9 @@ public void IsPathFullyQualified_Windows_Valid(string path) [InlineData("./foo.txt")] [InlineData("..")] [InlineData("../foo.txt")] - [InlineData(@"C:")] - [InlineData(@"C:/")] - [InlineData(@"C://")] + [InlineData("C:")] + [InlineData("C:/")] + [InlineData("C://")] public void IsPathFullyQualified_Unix_Invalid(string path) { Assert.False(_fileSystem.Path.IsPathFullyQualified(path)); diff --git a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.Join.cs b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.Join.cs index 6b3f819c..9cafe96b 100644 --- a/src/CommonUtilities.FileSystem/test/PathExtensionsTest.Join.cs +++ b/src/CommonUtilities.FileSystem/test/PathExtensionsTest.Join.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using Testably.Abstractions; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.FileSystem.Test; diff --git a/src/CommonUtilities.FileSystem/test/PathNormalizerTest.Normalize.cs b/src/CommonUtilities.FileSystem/test/PathNormalizerTest.Normalize.cs index 7191087e..dbef7e45 100644 --- a/src/CommonUtilities.FileSystem/test/PathNormalizerTest.Normalize.cs +++ b/src/CommonUtilities.FileSystem/test/PathNormalizerTest.Normalize.cs @@ -358,7 +358,7 @@ private static IEnumerable NormalizeTestDataSource() Input = new string('a', 300), ExpectedLinux = new string('a', 300) + "/", ExpectedWindows = new string('a', 300) + "\\", - Options = new PathNormalizeOptions() + Options = new PathNormalizeOptions { TrailingDirectorySeparatorBehavior = TrailingDirectorySeparatorBehavior.Ensure } @@ -368,7 +368,7 @@ private static IEnumerable NormalizeTestDataSource() Input = new string('a', 300) + "/", ExpectedLinux = new string('a', 300), ExpectedWindows = new string('a', 300), - Options = new PathNormalizeOptions() + Options = new PathNormalizeOptions { TrailingDirectorySeparatorBehavior = TrailingDirectorySeparatorBehavior.Trim } diff --git a/src/CommonUtilities.FileSystem/test/Utilities/ValueStringBuilderTest.cs b/src/CommonUtilities.FileSystem/test/Utilities/ValueStringBuilderTest.cs index fd1987a4..b5b4cf79 100644 --- a/src/CommonUtilities.FileSystem/test/Utilities/ValueStringBuilderTest.cs +++ b/src/CommonUtilities.FileSystem/test/Utilities/ValueStringBuilderTest.cs @@ -46,7 +46,7 @@ public void Append_Char_MatchesStringBuilder() { var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { sb.Append((char)i); vsb.Append((char)i); @@ -61,9 +61,9 @@ public void Append_String_MatchesStringBuilder() { var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { - string s = i.ToString(); + var s = i.ToString(); sb.Append(s); vsb.Append(s); } @@ -81,7 +81,7 @@ public void Append_String_Large_MatchesStringBuilder(int initialLength, int stri var sb = new StringBuilder(initialLength); var vsb = new ValueStringBuilder(new char[initialLength]); - string s = new string('a', stringLength); + var s = new string('a', stringLength); sb.Append(s); vsb.Append(s); @@ -94,7 +94,7 @@ public void Append_CharInt_MatchesStringBuilder() { var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { sb.Append((char)i, i); vsb.Append((char)i, i); @@ -109,9 +109,9 @@ public unsafe void Append_PtrInt_MatchesStringBuilder() { var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { - string s = i.ToString(); + var s = i.ToString(); fixed (char* p = s) { sb.Append(p, s.Length); @@ -129,13 +129,13 @@ public void AppendSpan_DataAppendedCorrectly() var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 1000; i++) + for (var i = 1; i <= 1000; i++) { - string s = i.ToString(); + var s = i.ToString(); sb.Append(s); - Span span = vsb.AppendSpan(s.Length); + var span = vsb.AppendSpan(s.Length); Assert.Equal(sb.Length, vsb.Length); s.AsSpan().CopyTo(span); @@ -152,9 +152,9 @@ public void Insert_IntCharInt_MatchesStringBuilder() var vsb = new ValueStringBuilder(); var rand = new Random(42); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { - int index = rand.Next(sb.Length); + var index = rand.Next(sb.Length); sb.Insert(index, new string((char)i, 1), i); vsb.Insert(index, (char)i, i); } @@ -169,9 +169,9 @@ public void AsSpan_ReturnsCorrectValue_DoesntClearBuilder() var sb = new StringBuilder(); var vsb = new ValueStringBuilder(); - for (int i = 1; i <= 100; i++) + for (var i = 1; i <= 100; i++) { - string s = i.ToString(); + var s = i.ToString(); sb.Append(s); vsb.Append(s); } @@ -187,23 +187,23 @@ public void AsSpan_ReturnsCorrectValue_DoesntClearBuilder() [Fact] public void ToString_ClearsBuilder_ThenReusable() { - const string Text1 = "test"; + const string text1 = "test"; var vsb = new ValueStringBuilder(); - vsb.Append(Text1); - Assert.Equal(Text1.Length, vsb.Length); + vsb.Append(text1); + Assert.Equal(text1.Length, vsb.Length); - string s = vsb.ToString(); - Assert.Equal(Text1, s); + var s = vsb.ToString(); + Assert.Equal(text1, s); Assert.Equal(0, vsb.Length); Assert.Equal(string.Empty, vsb.ToString()); Assert.True(vsb.TryCopyTo(Span.Empty, out _)); - const string Text2 = "another test"; - vsb.Append(Text2); - Assert.Equal(Text2.Length, vsb.Length); - Assert.Equal(Text2, vsb.ToString()); + const string text2 = "another test"; + vsb.Append(text2); + Assert.Equal(text2.Length, vsb.Length); + Assert.Equal(text2, vsb.ToString()); } [Fact] @@ -211,12 +211,12 @@ public void TryCopyTo_FailsWhenDestinationIsTooSmall_SucceedsWhenItsLargeEnough( { var vsb = new ValueStringBuilder(); - const string Text = "expected text"; - vsb.Append(Text); - Assert.Equal(Text.Length, vsb.Length); + const string text = "expected text"; + vsb.Append(text); + Assert.Equal(text.Length, vsb.Length); - Span dst = new char[Text.Length - 1]; - Assert.False(vsb.TryCopyTo(dst, out int charsWritten)); + Span dst = new char[text.Length - 1]; + Assert.False(vsb.TryCopyTo(dst, out var charsWritten)); Assert.Equal(0, charsWritten); Assert.Equal(0, vsb.Length); } @@ -224,35 +224,35 @@ public void TryCopyTo_FailsWhenDestinationIsTooSmall_SucceedsWhenItsLargeEnough( [Fact] public void TryCopyTo_ClearsBuilder_ThenReusable() { - const string Text1 = "test"; + const string text1 = "test"; var vsb = new ValueStringBuilder(); - vsb.Append(Text1); - Assert.Equal(Text1.Length, vsb.Length); + vsb.Append(text1); + Assert.Equal(text1.Length, vsb.Length); - Span dst = new char[Text1.Length]; - Assert.True(vsb.TryCopyTo(dst, out int charsWritten)); - Assert.Equal(Text1.Length, charsWritten); - Assert.Equal(Text1, dst.ToString()); + Span dst = new char[text1.Length]; + Assert.True(vsb.TryCopyTo(dst, out var charsWritten)); + Assert.Equal(text1.Length, charsWritten); + Assert.Equal(text1, dst.ToString()); Assert.Equal(0, vsb.Length); Assert.Equal(string.Empty, vsb.ToString()); Assert.True(vsb.TryCopyTo(Span.Empty, out _)); - const string Text2 = "another test"; - vsb.Append(Text2); - Assert.Equal(Text2.Length, vsb.Length); - Assert.Equal(Text2, vsb.ToString()); + const string text2 = "another test"; + vsb.Append(text2); + Assert.Equal(text2.Length, vsb.Length); + Assert.Equal(text2, vsb.ToString()); } [Fact] public void Dispose_ClearsBuilder_ThenReusable() { - const string Text1 = "test"; + const string text1 = "test"; var vsb = new ValueStringBuilder(); - vsb.Append(Text1); - Assert.Equal(Text1.Length, vsb.Length); + vsb.Append(text1); + Assert.Equal(text1.Length, vsb.Length); vsb.Dispose(); @@ -260,19 +260,19 @@ public void Dispose_ClearsBuilder_ThenReusable() Assert.Equal(string.Empty, vsb.ToString()); Assert.True(vsb.TryCopyTo(Span.Empty, out _)); - const string Text2 = "another test"; - vsb.Append(Text2); - Assert.Equal(Text2.Length, vsb.Length); - Assert.Equal(Text2, vsb.ToString()); + const string text2 = "another test"; + vsb.Append(text2); + Assert.Equal(text2.Length, vsb.Length); + Assert.Equal(text2, vsb.ToString()); } [Fact] - public unsafe void Indexer() + public void Indexer() { - const string Text1 = "foobar"; + const string text1 = "foobar"; var vsb = new ValueStringBuilder(); - vsb.Append(Text1); + vsb.Append(text1); Assert.Equal('b', vsb[3]); vsb[3] = 'c'; diff --git a/src/CommonUtilities.Registry/src/IRegistryKey.cs b/src/CommonUtilities.Registry/src/IRegistryKey.cs index d782643e..64070510 100644 --- a/src/CommonUtilities.Registry/src/IRegistryKey.cs +++ b/src/CommonUtilities.Registry/src/IRegistryKey.cs @@ -4,8 +4,7 @@ namespace AnakinRaW.CommonUtilities.Registry; /// -/// High-Level abstraction layer for the a Registry Key implementation. -/// Read and write operations are supported. +/// Represents a key node in of an . /// public interface IRegistryKey : IDisposable { diff --git a/src/CommonUtilities.Registry/src/InMemoryRegistryKeyData.cs b/src/CommonUtilities.Registry/src/InMemoryRegistryKeyData.cs index f3305d6d..cf9cc251 100644 --- a/src/CommonUtilities.Registry/src/InMemoryRegistryKeyData.cs +++ b/src/CommonUtilities.Registry/src/InMemoryRegistryKeyData.cs @@ -242,7 +242,7 @@ public override void Dispose() var subKeyNames = subPath.Split(Separator); foreach (var subKeyName in subKeyNames) { - if (currentKey._subKeys.TryGetValue(subKeyName, out var key) == false) + if (!currentKey._subKeys.TryGetValue(subKeyName, out var key)) return null; currentKey = key; } diff --git a/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj b/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj index 771d3374..cb770513 100644 --- a/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj +++ b/src/CommonUtilities.Registry/test/CommonUtilities.Registry.Test.csproj @@ -1,8 +1,8 @@  - net9.0 - $(TargetFrameworks);net48 + net10.0 + $(TargetFrameworks);net481 false true enable @@ -26,13 +26,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CommonUtilities.Registry/test/Extensions/InMemoryKeyExtensionsTest.cs b/src/CommonUtilities.Registry/test/Extensions/InMemoryKeyExtensionsTest.cs index 88a576d8..ecef9a3d 100644 --- a/src/CommonUtilities.Registry/test/Extensions/InMemoryKeyExtensionsTest.cs +++ b/src/CommonUtilities.Registry/test/Extensions/InMemoryKeyExtensionsTest.cs @@ -1,5 +1,6 @@ namespace AnakinRaW.CommonUtilities.Registry.Test.Extensions; +// ReSharper disable once UnusedMember.Global public class InMemoryKeyExtensionsTest : RegistryKeyExtensionsTestBase { protected override RegKeyTest CreateTestKey() diff --git a/src/CommonUtilities.Registry/test/Extensions/RegistryKeyExtensionsTestBase.cs b/src/CommonUtilities.Registry/test/Extensions/RegistryKeyExtensionsTestBase.cs index b74e3556..fa8b58da 100644 --- a/src/CommonUtilities.Registry/test/Extensions/RegistryKeyExtensionsTestBase.cs +++ b/src/CommonUtilities.Registry/test/Extensions/RegistryKeyExtensionsTestBase.cs @@ -382,7 +382,7 @@ public async Task AwaitRegKeyChange_CallingThreadDestroyed() thread.Join(); // Verify that the watching task is still watching. - var completedTask = await Task.WhenAny(watchingTask!, Task.Delay(AsyncDelay)); + var completedTask = await Task.WhenAny(watchingTask, Task.Delay(AsyncDelay)); Assert.NotSame(watchingTask, completedTask); test.CreateSubKey().Dispose(); diff --git a/src/CommonUtilities.Registry/test/Extensions/WindowsKeyExtensionsTest.cs b/src/CommonUtilities.Registry/test/Extensions/WindowsKeyExtensionsTest.cs index 6d8c056a..ad03bf7f 100644 --- a/src/CommonUtilities.Registry/test/Extensions/WindowsKeyExtensionsTest.cs +++ b/src/CommonUtilities.Registry/test/Extensions/WindowsKeyExtensionsTest.cs @@ -4,6 +4,7 @@ namespace AnakinRaW.CommonUtilities.Registry.Test.Extensions; +// ReSharper disable once UnusedMember.Global public class WindowsKeyExtensionsTest : RegistryKeyExtensionsTestBase { protected override RegKeyTest CreateTestKey() diff --git a/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrDefault.cs b/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrDefault.cs index c7c7db98..6f44e798 100644 --- a/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrDefault.cs +++ b/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrDefault.cs @@ -57,7 +57,7 @@ public void GetValueOrDefault_GetByteArrayTest() byte[] expected = [1, 2, 3]; TestRegistryKey.SetValue(valueName, expected); - Assert.Equal(expected, TestRegistryKey.GetValueOrDefault(valueName, [0, 0], out var exists)); + Assert.Equal(expected, TestRegistryKey.GetValueOrDefault(valueName, "\0\0"u8.ToArray(), out var exists)); Assert.True(exists); TestRegistryKey.DeleteValue(valueName); } diff --git a/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrSetDefault.cs b/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrSetDefault.cs index 1d8ea274..104d9e35 100644 --- a/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrSetDefault.cs +++ b/src/CommonUtilities.Registry/test/RegistryKey_GetValueOrSetDefault.cs @@ -84,7 +84,7 @@ public void GetValueOrSetDefault_GetByteArrayTest() byte[] expected = [1, 2, 3]; TestRegistryKey.SetValue(valueName, expected); - Assert.Equal(expected, TestRegistryKey.GetValueOrSetDefault(valueName, [0, 0], out var defaultUsed)); + Assert.Equal(expected, TestRegistryKey.GetValueOrSetDefault(valueName, "\0\0"u8.ToArray(), out var defaultUsed)); Assert.False(defaultUsed); TestRegistryKey.DeleteValue(valueName); } diff --git a/src/CommonUtilities.Registry/test/RegistryTestsBase.cs b/src/CommonUtilities.Registry/test/RegistryTestsBase.cs index 8ced84a9..cc7af332 100644 --- a/src/CommonUtilities.Registry/test/RegistryTestsBase.cs +++ b/src/CommonUtilities.Registry/test/RegistryTestsBase.cs @@ -50,14 +50,14 @@ public void Dispose() public static readonly object[][] TestRegistrySubKeyNames = [ - [@"Foo", @"Foo"], + ["Foo", "Foo"], [@"Foo\Bar", @"Foo\Bar"], // Multiple/trailing slashes should be removed. - [@"Foo", @"Foo\"], - [@"Foo", @"Foo\\"], - [@"Foo", @"Foo\\\"], - [@"Foo", @"Foo\\\\"], + ["Foo", @"Foo\"], + ["Foo", @"Foo\\"], + ["Foo", @"Foo\\\"], + ["Foo", @"Foo\\\\"], [@"Foo\Bar", @"Foo\\Bar"], [@"Foo\Bar", @"Foo\\\Bar"], [@"Foo\Bar", @"Foo\\\\Bar"], @@ -74,16 +74,16 @@ public void Dispose() // If there are multiple slashes, any extra slash chars will be // replaced with a marker char ('\uffff'), and then all '\uffff' // chars will be removed, including any pre-existing '\uffff' chars. - InsertMarkerChar(@"Foo", @"{0}Foo\\"), - InsertMarkerChar(@"Foo", @"Foo{0}\\"), - InsertMarkerChar(@"Foo", @"Foo\\{0}"), - InsertMarkerChar(@"Foo", @"Fo{0}o\\"), - InsertMarkerChar(@"Foo", @"{0}Fo{0}o{0}\\{0}"), - InsertMarkerChar(@"Foo", @"{0}Foo\\\"), - InsertMarkerChar(@"Foo", @"Foo{0}\\\"), - InsertMarkerChar(@"Foo", @"Foo\\\{0}"), - InsertMarkerChar(@"Foo", @"Fo{0}o\\\"), - InsertMarkerChar(@"Foo", @"{0}Fo{0}o{0}\\\{0}"), + InsertMarkerChar("Foo", @"{0}Foo\\"), + InsertMarkerChar("Foo", @"Foo{0}\\"), + InsertMarkerChar("Foo", @"Foo\\{0}"), + InsertMarkerChar("Foo", @"Fo{0}o\\"), + InsertMarkerChar("Foo", @"{0}Fo{0}o{0}\\{0}"), + InsertMarkerChar("Foo", @"{0}Foo\\\"), + InsertMarkerChar("Foo", @"Foo{0}\\\"), + InsertMarkerChar("Foo", @"Foo\\\{0}"), + InsertMarkerChar("Foo", @"Fo{0}o\\\"), + InsertMarkerChar("Foo", @"{0}Fo{0}o{0}\\\{0}"), InsertMarkerChar(@"Foo\Bar", @"{0}Foo\\Bar"), InsertMarkerChar(@"Foo\Bar", @"Foo{0}\\Bar"), InsertMarkerChar(@"Foo\Bar", @"Foo\\{0}Bar"), @@ -109,10 +109,10 @@ public void Dispose() InsertMarkerChar(@"Foo\Bar", @"{0}Fo{0}o{0}\{0}B{0}ar{0}\\{0}"), // If there aren't multiple slashes, any '\uffff' chars should remain. - InsertMarkerChar(@"{0}Foo"), - InsertMarkerChar(@"Foo{0}"), - InsertMarkerChar(@"Fo{0}o"), - InsertMarkerChar(@"{0}Fo{0}o{0}"), + InsertMarkerChar("{0}Foo"), + InsertMarkerChar("Foo{0}"), + InsertMarkerChar("Fo{0}o"), + InsertMarkerChar("{0}Fo{0}o{0}"), InsertMarkerChar(@"{0}Foo\"), InsertMarkerChar(@"Foo{0}\"), InsertMarkerChar(@"Fo{0}o\"), @@ -155,18 +155,18 @@ protected void Verify_CreateSubKey_KeyExists_OpensKeyWithFixedUpName(string expe using var key = createSubKey(); Assert.NotNull(key); - Assert.Single(TestRegistryKey.GetSubKeyNames()!); + Assert.Single(TestRegistryKey.GetSubKeyNames()); Assert.Equal(TestRegistryKey.Name + @"\" + expected, key.Name); } protected void Verify_CreateSubKey_KeyDoesNotExist_CreatesKeyWithFixedUpName(string expected, Func createSubKey) { Assert.Null(TestRegistryKey.OpenSubKey(expected)); - Assert.Empty(TestRegistryKey.GetSubKeyNames()!); + Assert.Empty(TestRegistryKey.GetSubKeyNames()); using var key = createSubKey(); Assert.NotNull(key); - Assert.Single(TestRegistryKey.GetSubKeyNames()!); + Assert.Single(TestRegistryKey.GetSubKeyNames()); Assert.Equal(TestRegistryKey.Name + @"\" + expected, key.Name); } @@ -181,7 +181,7 @@ protected void Verify_DeleteSubKey_KeyExists_KeyDeleted(string expected, Action protected void Verify_DeleteSubKey_KeyDoesNotExists_DoesNotThrow(string expected, Action deleteSubKey) { Assert.Null(TestRegistryKey.OpenSubKey(expected)); - Assert.Empty(TestRegistryKey.GetSubKeyNames()!); + Assert.Empty(TestRegistryKey.GetSubKeyNames()); deleteSubKey(); } @@ -192,14 +192,14 @@ protected void Verify_OpenSubKey_KeyExists_OpensWithFixedUpName(string expected, using var key = openSubKey(); Assert.NotNull(key); - Assert.Single(TestRegistryKey.GetSubKeyNames()!); + Assert.Single(TestRegistryKey.GetSubKeyNames()); Assert.Equal(TestRegistryKey.Name + @"\" + expected, key.Name); } protected void Verify_OpenSubKey_KeyDoesNotExist_ReturnsNull(string expected, Func openSubKey) { Assert.Null(TestRegistryKey.OpenSubKey(expected)); - Assert.Empty(TestRegistryKey.GetSubKeyNames()!); + Assert.Empty(TestRegistryKey.GetSubKeyNames()); Assert.Null(openSubKey()); } diff --git a/src/CommonUtilities.SimplePipeline/src/CommonUtilities.SimplePipeline.csproj b/src/CommonUtilities.SimplePipeline/src/CommonUtilities.SimplePipeline.csproj index f5ae696a..318ea7f4 100644 --- a/src/CommonUtilities.SimplePipeline/src/CommonUtilities.SimplePipeline.csproj +++ b/src/CommonUtilities.SimplePipeline/src/CommonUtilities.SimplePipeline.csproj @@ -25,8 +25,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities.SimplePipeline/src/Extensions.cs b/src/CommonUtilities.SimplePipeline/src/Extensions.cs index 49a4769f..fc6bdd49 100644 --- a/src/CommonUtilities.SimplePipeline/src/Extensions.cs +++ b/src/CommonUtilities.SimplePipeline/src/Extensions.cs @@ -5,14 +5,17 @@ namespace AnakinRaW.CommonUtilities.SimplePipeline; internal static class Extensions { - public static bool IsExceptionType(this Exception error) where T : Exception + extension(Exception error) { - return error switch + public bool IsExceptionType() where T : Exception { - T _ => true, - AggregateException aggregateException => aggregateException.InnerExceptions.Any(p => - p.IsExceptionType()), - _ => false - }; + return error switch + { + T _ => true, + AggregateException aggregateException => aggregateException.InnerExceptions.Any(p => + p.IsExceptionType()), + _ => false + }; + } } } \ No newline at end of file diff --git a/src/CommonUtilities.SimplePipeline/src/Runners/StepRunnerBase.cs b/src/CommonUtilities.SimplePipeline/src/Runners/StepRunnerBase.cs index b29f6344..2db72601 100644 --- a/src/CommonUtilities.SimplePipeline/src/Runners/StepRunnerBase.cs +++ b/src/CommonUtilities.SimplePipeline/src/Runners/StepRunnerBase.cs @@ -20,7 +20,7 @@ public abstract class StepRunnerBase : IStepRunner /// /// Gets a modifiable bag of all executed steps. /// - protected readonly ConcurrentBag ExecutedStepsBag = new(); + protected readonly ConcurrentBag ExecutedStepsBag = []; /// /// Gets the logger instance of this stepRunner. @@ -87,9 +87,9 @@ protected void RunSteps(CancellationToken token) if (!alreadyCancelled) { if (e.IsExceptionType()) - Logger?.LogTrace($"Step {step} cancelled"); + Logger?.LogTrace("Step {Step} cancelled", step); else - Logger?.LogTrace(e, $"Step {step} threw an exception: {e.GetType()}: {e.Message}"); + Logger?.LogTrace(e, "Step {Step} threw an exception: {Exception}: {EMessage}", step, e.GetType(), e.Message); } var error = new StepRunnerErrorEventArgs(e, step) diff --git a/src/CommonUtilities.SimplePipeline/src/Steps/PipelineStep.cs b/src/CommonUtilities.SimplePipeline/src/Steps/PipelineStep.cs index e15d1190..94f4c41d 100644 --- a/src/CommonUtilities.SimplePipeline/src/Steps/PipelineStep.cs +++ b/src/CommonUtilities.SimplePipeline/src/Steps/PipelineStep.cs @@ -40,11 +40,11 @@ protected PipelineStep(IServiceProvider serviceProvider) /// public void Run(CancellationToken token) { - Logger?.LogTrace($"BEGIN: {this}"); + Logger?.LogTrace("BEGIN: {Step}", this); try { RunCore(token); - Logger?.LogTrace($"END: {this}"); + Logger?.LogTrace("END: {Step}", this); } catch (OperationCanceledException ex) { diff --git a/src/CommonUtilities.SimplePipeline/src/Steps/RunPipelineStep.cs b/src/CommonUtilities.SimplePipeline/src/Steps/RunPipelineStep.cs index b977ef19..7a13f29b 100644 --- a/src/CommonUtilities.SimplePipeline/src/Steps/RunPipelineStep.cs +++ b/src/CommonUtilities.SimplePipeline/src/Steps/RunPipelineStep.cs @@ -17,11 +17,12 @@ public class RunPipelineStep(IPipeline pipeline, IServiceProvider serviceProvide /// protected override void RunSynchronized(CancellationToken token) { - Logger?.LogTrace($"Running {_pipeline}..."); + Logger?.LogTrace("Running {Pipeline}...", _pipeline); try { + // ReSharper disable once MethodSupportsCancellation _pipeline.RunAsync(token).Wait(); - Logger?.LogTrace($"Finished {_pipeline}"); + Logger?.LogTrace("Finished {Pipeline}", _pipeline); } catch (AggregateException e) { diff --git a/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj b/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj index f8aa949d..fd1fc46e 100644 --- a/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj +++ b/src/CommonUtilities.SimplePipeline/test/CommonUtilities.SimplePipeline.Test.csproj @@ -1,8 +1,8 @@ - net9.0;net8.0 - $(TargetFrameworks);net48 + net10.0;net8.0 + $(TargetFrameworks);net481 false true @@ -17,16 +17,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelPipelineTests.cs b/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelPipelineTests.cs index c8f73bd3..744dd018 100644 --- a/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelPipelineTests.cs +++ b/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelPipelineTests.cs @@ -5,6 +5,7 @@ namespace AnakinRaW.CommonUtilities.SimplePipeline.Test.Pipelines; +// ReSharper disable once UnusedMember.Global public class ParallelPipelineTests : StepRunnerPipelineTest { protected override Pipeline CreatePipeline(IList steps) diff --git a/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelProducerConsumerPipelineTest.cs b/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelProducerConsumerPipelineTest.cs index 3691e8e1..e899338a 100644 --- a/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelProducerConsumerPipelineTest.cs +++ b/src/CommonUtilities.SimplePipeline/test/Pipelines/ParallelProducerConsumerPipelineTest.cs @@ -77,7 +77,9 @@ public async Task RunAsync_DelayedAdd_PrepareFails(bool failFast) return; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async IAsyncEnumerable ValueFunction() +#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { yield return s1; yield return s2; @@ -97,7 +99,9 @@ public async Task PrepareAsync_PrepareFails() return; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async IAsyncEnumerable ValueFunction() +#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { yield return s1; yield return s2; diff --git a/src/CommonUtilities.SimplePipeline/test/Progress/AggregatedProgressReporterTests.cs b/src/CommonUtilities.SimplePipeline/test/Progress/AggregatedProgressReporterTests.cs index 68b030a9..099142d3 100644 --- a/src/CommonUtilities.SimplePipeline/test/Progress/AggregatedProgressReporterTests.cs +++ b/src/CommonUtilities.SimplePipeline/test/Progress/AggregatedProgressReporterTests.cs @@ -3,9 +3,11 @@ using AnakinRaW.CommonUtilities.SimplePipeline.Progress; using AnakinRaW.CommonUtilities.Testing; using Xunit; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.SimplePipeline.Test.Progress; +// ReSharper disable once UnusedMember.Global public class AggregatedProgressReporterTest_Struct : AggregatedProgressReporterTestBase { protected override TestInfoStruct CreateCustomProgressInfo(TestProgressStep step, double progress) @@ -17,6 +19,7 @@ protected override TestInfoStruct CreateCustomProgressInfo(TestProgressStep { protected override TestInfoClass CreateCustomProgressInfo(TestProgressStep step, double progress) diff --git a/src/CommonUtilities.SimplePipeline/test/Progress/ProgressTypeTest.cs b/src/CommonUtilities.SimplePipeline/test/Progress/ProgressTypeTest.cs index 8ea839cf..e559be48 100644 --- a/src/CommonUtilities.SimplePipeline/test/Progress/ProgressTypeTest.cs +++ b/src/CommonUtilities.SimplePipeline/test/Progress/ProgressTypeTest.cs @@ -57,10 +57,10 @@ public void EqualsGetHashCode() Assert.True(pt.Equals(pt)); Assert.True(pt.Equals((object)pt)); - // ReSharper disable once EqualExpressionComparison +#pragma warning disable CS1718 // ReSharper disable EqualExpressionComparison Assert.True(pt == pt); - // ReSharper disable once EqualExpressionComparison Assert.False(pt != pt); +#pragma warning restore CS1718 Assert.True(pt.Equals(equal)); Assert.True(pt == equal); Assert.False(pt != equal); diff --git a/src/CommonUtilities.SimplePipeline/test/Steps/WaitStepTest.cs b/src/CommonUtilities.SimplePipeline/test/Steps/WaitStepTest.cs index 2dfe1811..019f5b6d 100644 --- a/src/CommonUtilities.SimplePipeline/test/Steps/WaitStepTest.cs +++ b/src/CommonUtilities.SimplePipeline/test/Steps/WaitStepTest.cs @@ -29,7 +29,7 @@ public void Wait() var step = new WaitStep(runner, ServiceProvider); - var runnerTask = runner.RunAsync(CancellationToken.None); + _ = runner.RunAsync(CancellationToken.None); step.Run(CancellationToken.None); // We cannot assert on the runnerTask task, diff --git a/src/CommonUtilities.SimplePipeline/test/TestStep.cs b/src/CommonUtilities.SimplePipeline/test/TestStep.cs index 6f3ac5f9..bfef8bb7 100644 --- a/src/CommonUtilities.SimplePipeline/test/TestStep.cs +++ b/src/CommonUtilities.SimplePipeline/test/TestStep.cs @@ -88,7 +88,7 @@ public override int GetHashCode() } } -public class TestSyncStep(Action action, IServiceProvider serviceProvider) +public class TestSyncStep(Action? action, IServiceProvider serviceProvider) : SynchronizedStep(serviceProvider) { public ProgressType Type => new() { Id = "test", DisplayName = "Test" }; diff --git a/src/CommonUtilities.TestingUtilities/Collections/CollectionsTestSuite.cs b/src/CommonUtilities.TestingUtilities/Collections/CollectionsTestSuite.cs index 02cda4ea..1fc1d512 100644 --- a/src/CommonUtilities.TestingUtilities/Collections/CollectionsTestSuite.cs +++ b/src/CommonUtilities.TestingUtilities/Collections/CollectionsTestSuite.cs @@ -96,8 +96,8 @@ protected IEnumerable CreateEnumerable(IEnumerable? enumerableToMatchTo, i } /// - /// Helper function to create an List fulfilling the given specific parameters. The function will - /// create an List and then add values + /// Helper function to create a List fulfilling the given specific parameters. The function will + /// create a List and then add values /// to it until it is full. It will begin by adding the desired number of matching, /// followed by random (deterministic) elements until the desired count is reached. /// diff --git a/src/CommonUtilities.TestingUtilities/Collections/ICollectionTestSuite.cs b/src/CommonUtilities.TestingUtilities/Collections/ICollectionTestSuite.cs index 431ab5b1..cf077a4a 100644 --- a/src/CommonUtilities.TestingUtilities/Collections/ICollectionTestSuite.cs +++ b/src/CommonUtilities.TestingUtilities/Collections/ICollectionTestSuite.cs @@ -14,7 +14,7 @@ public abstract class ICollectionTestSuite : IEnumerableTestSuite { protected virtual Type ICollection_Generic_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentException); - protected virtual IEnumerable InvalidValues => Array.Empty(); + protected virtual IEnumerable InvalidValues => []; protected virtual bool DefaultValueAllowed => true; diff --git a/src/CommonUtilities.TestingUtilities/Collections/INonModifyingEnumerableTestSuite.cs b/src/CommonUtilities.TestingUtilities/Collections/INonModifyingEnumerableTestSuite.cs index 0bf2a39b..a273bd56 100644 --- a/src/CommonUtilities.TestingUtilities/Collections/INonModifyingEnumerableTestSuite.cs +++ b/src/CommonUtilities.TestingUtilities/Collections/INonModifyingEnumerableTestSuite.cs @@ -368,8 +368,10 @@ public void IEnumerable_Generic_Enumerator_Current_ReturnsSameObjectsOnDifferent // Ensures that the elements returned from enumeration are exactly the same collection of // elements returned from a previous enumeration var enumerable = GenericIEnumerableFactory(count); +#pragma warning disable CS8714 var firstValues = new Dictionary(count); var secondValues = new Dictionary(count); +#pragma warning restore CS8714 foreach (var item in enumerable) firstValues[item] = firstValues.ContainsKey(item) ? firstValues[item]++ : 1; foreach (var item in enumerable) diff --git a/src/CommonUtilities.TestingUtilities/Collections/IReadOnlyListTestSuite.cs b/src/CommonUtilities.TestingUtilities/Collections/IReadOnlyListTestSuite.cs index cc7cc527..fb0ef1b1 100644 --- a/src/CommonUtilities.TestingUtilities/Collections/IReadOnlyListTestSuite.cs +++ b/src/CommonUtilities.TestingUtilities/Collections/IReadOnlyListTestSuite.cs @@ -40,7 +40,9 @@ protected override IReadOnlyCollection GenericIReadOnlyCollectionFactory(IEnu [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void From_IEnumerable(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { var enumerable = CreateEnumerable(null, enumerableLength, 0, numberOfDuplicateElements); var list = GenericIReadOnlyListFactory(enumerable); diff --git a/src/CommonUtilities.TestingUtilities/CommonUtilities.TestingUtilities.csproj b/src/CommonUtilities.TestingUtilities/CommonUtilities.TestingUtilities.csproj index 3006fe05..f80f3b13 100644 --- a/src/CommonUtilities.TestingUtilities/CommonUtilities.TestingUtilities.csproj +++ b/src/CommonUtilities.TestingUtilities/CommonUtilities.TestingUtilities.csproj @@ -1,8 +1,8 @@ - + - net9.0;net6.0 - $(TargetFrameworks);net48 + net10.0;net8.0 + $(TargetFrameworks);net481 enable enable false @@ -15,22 +15,23 @@ xUnit2013 - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/CommonUtilities/src/Collections/FrugalList.cs b/src/CommonUtilities/src/Collections/FrugalList.cs index 048757d0..b4e489c1 100644 --- a/src/CommonUtilities/src/Collections/FrugalList.cs +++ b/src/CommonUtilities/src/Collections/FrugalList.cs @@ -44,11 +44,11 @@ namespace AnakinRaW.CommonUtilities.Collections; /// /// Usage advise: /// -/// a) To ensure that all changes get reflected to other variables (including the first item) +/// a. To ensure that all changes get reflected to other variables (including the first item) /// either box this structure (e.g, to [this allocates memory though]) or pass this structure as by-. /// /// -/// b) If a copy shall not reflect any changes from its source use +/// b. If a copy shall not reflect any changes from its source use /// which creates a full shallow-copy of all items in this list. /// /// @@ -292,9 +292,9 @@ public void RemoveAt(int index) // Natively implementing frequent Linq functions avoids boxing. Add more if necessary. /// - /// Creates a from an this instance. + /// Creates a from the . /// - /// A that contains elements from the this list. + /// A that contains elements from the . public readonly List ToList() { if (_tailList is null) @@ -319,7 +319,7 @@ public readonly T[] ToArray() } /// - /// Returns the first element of of the . + /// Returns the first element of the . /// /// The first element of the specified /// The is empty. diff --git a/src/CommonUtilities/src/Collections/ReadOnlyFrugalList.cs b/src/CommonUtilities/src/Collections/ReadOnlyFrugalList.cs index 5d2fa815..7b5119a7 100644 --- a/src/CommonUtilities/src/Collections/ReadOnlyFrugalList.cs +++ b/src/CommonUtilities/src/Collections/ReadOnlyFrugalList.cs @@ -65,9 +65,9 @@ public void CopyTo(T[] array, int index) // Natively implementing frequent Linq functions avoids boxing. Add more if necessary. /// - /// Creates a from an this instance. + /// Creates a from the . /// - /// A that contains elements from this list. + /// A that contains elements from the . public List ToList() { return _list.ToList(); @@ -146,11 +146,16 @@ public int IndexOf(T item) /// Returns an enumerator that iterates through the /// /// A for the . - public FrugalList.FrugalEnumerator GetEnumerator() => _list.GetEnumerator(); + public FrugalList.FrugalEnumerator GetEnumerator() + { + // ReSharper disable once PossiblyImpureMethodCallOnReadonlyVariable + return _list.GetEnumerator(); + } /// IEnumerator IEnumerable.GetEnumerator() { + // ReSharper disable once PossiblyImpureMethodCallOnReadonlyVariable return _list.GetEnumerator(); } diff --git a/src/CommonUtilities/src/CommonUtilities.csproj b/src/CommonUtilities/src/CommonUtilities.csproj index 879548bd..b2951cdb 100644 --- a/src/CommonUtilities/src/CommonUtilities.csproj +++ b/src/CommonUtilities/src/CommonUtilities.csproj @@ -26,9 +26,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CommonUtilities/src/Extensions/EncodingExtensions.NetFramework.cs b/src/CommonUtilities/src/Extensions/EncodingExtensions.NetFramework.cs index a86af2a5..70b12730 100644 --- a/src/CommonUtilities/src/Extensions/EncodingExtensions.NetFramework.cs +++ b/src/CommonUtilities/src/Extensions/EncodingExtensions.NetFramework.cs @@ -8,56 +8,56 @@ namespace AnakinRaW.CommonUtilities.Extensions; public static partial class EncodingExtensions { - /// - /// Encodes into a span of bytes a set of characters from the specified read-only span. - /// /// The encoding to use. - /// The span containing the set of characters to encode. - /// The byte span to hold the encoded bytes. - /// The number of encoded bytes. - public static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan value, Span destination) + extension(Encoding encoding) { - fixed (char* charsPtr = &GetNonNullPinnableReference(value)) - fixed (byte* bytesPtr = &GetNonNullPinnableReference(destination)) - return encoding.GetBytes(charsPtr, value.Length, bytesPtr, destination.Length); - } + /// + /// Encodes into a span of bytes a set of characters from the specified read-only span. + /// + /// The span containing the set of characters to encode. + /// The byte span to hold the encoded bytes. + /// The number of encoded bytes. + public unsafe int GetBytes(ReadOnlySpan value, Span destination) + { + fixed (char* charsPtr = &GetNonNullPinnableReference(value)) + fixed (byte* bytesPtr = &GetNonNullPinnableReference(destination)) + return encoding.GetBytes(charsPtr, value.Length, bytesPtr, destination.Length); + } - /// - /// Decodes all the bytes in the specified read-only byte span into a character span. - /// - /// The encoding to use. - /// A read-only span containing the sequence of bytes to decode. - /// The character span receiving the decoded bytes. - /// The actual number of characters written at the span indicated by the parameter. - public static unsafe int GetChars(this Encoding encoding, ReadOnlySpan bytes, Span chars) - { - fixed (byte* pBytes = &GetNonNullPinnableReference(bytes)) - fixed (char* pChar = &GetNonNullPinnableReference(chars)) - return encoding.GetChars(pBytes, bytes.Length, pChar, chars.Length); - } + /// + /// Decodes all the bytes in the specified read-only byte span into a character span. + /// + /// A read-only span containing the sequence of bytes to decode. + /// The character span receiving the decoded bytes. + /// The actual number of characters written at the span indicated by the parameter. + public unsafe int GetChars(ReadOnlySpan bytes, Span chars) + { + fixed (byte* pBytes = &GetNonNullPinnableReference(bytes)) + fixed (char* pChar = &GetNonNullPinnableReference(chars)) + return encoding.GetChars(pBytes, bytes.Length, pChar, chars.Length); + } - /// - /// Decodes all the bytes in the specified byte span into a string. - /// - /// The encoding to use - /// A read-only byte span to decode to a Unicode string. - /// A string that contains the decoded bytes from the provided read-only span. - public static unsafe string GetString(this Encoding encoding, ReadOnlySpan bytes) - { - fixed (byte* bytesPtr = &GetNonNullPinnableReference(bytes)) - return encoding.GetString(bytesPtr, bytes.Length); - } + /// + /// Decodes all the bytes in the specified byte span into a string. + /// + /// A read-only byte span to decode to a Unicode string. + /// A string that contains the decoded bytes from the provided read-only span. + public unsafe string GetString(ReadOnlySpan bytes) + { + fixed (byte* bytesPtr = &GetNonNullPinnableReference(bytes)) + return encoding.GetString(bytesPtr, bytes.Length); + } - /// - /// Calculates the number of bytes produced by encoding the characters in the specified character span. - /// - /// The encoding to use. - /// The span of characters to encode. - /// The number of bytes produced by encoding the specified character span. - public static unsafe int GetByteCount(this Encoding encoding, ReadOnlySpan value) - { - fixed (char* charsPtr = &GetNonNullPinnableReference(value)) - return encoding.GetByteCount(charsPtr, value.Length); + /// + /// Calculates the number of bytes produced by encoding the characters in the specified character span. + /// + /// The span of characters to encode. + /// The number of bytes produced by encoding the specified character span. + public unsafe int GetByteCount(ReadOnlySpan value) + { + fixed (char* charsPtr = &GetNonNullPinnableReference(value)) + return encoding.GetByteCount(charsPtr, value.Length); + } } diff --git a/src/CommonUtilities/src/Extensions/EncodingExtensions.cs b/src/CommonUtilities/src/Extensions/EncodingExtensions.cs index a017ab6e..204917ea 100644 --- a/src/CommonUtilities/src/Extensions/EncodingExtensions.cs +++ b/src/CommonUtilities/src/Extensions/EncodingExtensions.cs @@ -81,9 +81,9 @@ public static unsafe string EncodeString(this Encoding encoding, ReadOnlySpan /// Encodes into a span of characters a set of characters from the specified read-only span. /// - /// The encoding to use. /// The span of characters to encode. /// The character span to hold the encoded characters. + /// The encoding to use. /// The actual number of characters written at the span indicated by the parameter. public static int EncodeString(this Encoding encoding, ReadOnlySpan source, Span destination) { @@ -96,10 +96,10 @@ public static int EncodeString(this Encoding encoding, ReadOnlySpan source /// /// Encodes into a span of characters a set of characters from the specified read-only span. /// - /// The encoding to use. /// The span of characters to encode. /// The character span to hold the encoded characters. /// Maximum bytes *not characters!* required for encoding. + /// The encoding to use. /// The actual number of characters written at the span indicated by the parameter. /// is . /// is less than actually required. @@ -123,9 +123,9 @@ public static unsafe int EncodeString(this Encoding encoding, ReadOnlySpan /// The returned read-only span is sliced from . /// This means, modifying might also modify the returned read-only span. /// - /// The encoding to use. /// The span of characters to encode. /// The byte span to hold the encoded bytes. + /// The encoding to use. /// The read-only byte span that holds the encoded bytes. public static ReadOnlySpan GetBytesReadOnly(this Encoding encoding, ReadOnlySpan value, Span inputBuffer) { diff --git a/src/CommonUtilities/src/Hashing/HashTypeKey.cs b/src/CommonUtilities/src/Hashing/HashTypeKey.cs index adae1fcd..946da33b 100644 --- a/src/CommonUtilities/src/Hashing/HashTypeKey.cs +++ b/src/CommonUtilities/src/Hashing/HashTypeKey.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.Hashing; diff --git a/src/CommonUtilities/src/Hashing/Providers/MD5HashProvider.cs b/src/CommonUtilities/src/Hashing/Providers/MD5HashProvider.cs index 0e261193..d64bd69a 100644 --- a/src/CommonUtilities/src/Hashing/Providers/MD5HashProvider.cs +++ b/src/CommonUtilities/src/Hashing/Providers/MD5HashProvider.cs @@ -6,6 +6,7 @@ namespace AnakinRaW.CommonUtilities.Hashing.Providers; +// ReSharper disable once InconsistentNaming internal class MD5HashProvider : HashAlgorithmProviderBase { public override HashTypeKey SupportedHashType => HashTypeKey.MD5; diff --git a/src/CommonUtilities/src/Hashing/Providers/SHA1HashProvider.cs b/src/CommonUtilities/src/Hashing/Providers/SHA1HashProvider.cs index 41c8997e..fe0bc4ad 100644 --- a/src/CommonUtilities/src/Hashing/Providers/SHA1HashProvider.cs +++ b/src/CommonUtilities/src/Hashing/Providers/SHA1HashProvider.cs @@ -6,6 +6,7 @@ namespace AnakinRaW.CommonUtilities.Hashing.Providers; +// ReSharper disable once InconsistentNaming internal class SHA1HashProvider : HashAlgorithmProviderBase { public override HashTypeKey SupportedHashType => HashTypeKey.SHA1; diff --git a/src/CommonUtilities/src/Hashing/Providers/SHA256HashProvider.cs b/src/CommonUtilities/src/Hashing/Providers/SHA256HashProvider.cs index 79756dbc..99082bc4 100644 --- a/src/CommonUtilities/src/Hashing/Providers/SHA256HashProvider.cs +++ b/src/CommonUtilities/src/Hashing/Providers/SHA256HashProvider.cs @@ -6,6 +6,7 @@ namespace AnakinRaW.CommonUtilities.Hashing.Providers; +// ReSharper disable once InconsistentNaming internal class SHA256HashProvider : HashAlgorithmProviderBase { public override HashTypeKey SupportedHashType => HashTypeKey.SHA256; diff --git a/src/CommonUtilities/src/Hashing/Providers/SHA384HashProvider.cs b/src/CommonUtilities/src/Hashing/Providers/SHA384HashProvider.cs index 3c21e690..5198ba45 100644 --- a/src/CommonUtilities/src/Hashing/Providers/SHA384HashProvider.cs +++ b/src/CommonUtilities/src/Hashing/Providers/SHA384HashProvider.cs @@ -6,6 +6,7 @@ namespace AnakinRaW.CommonUtilities.Hashing.Providers; +// ReSharper disable once InconsistentNaming internal class SHA384HashProvider : HashAlgorithmProviderBase { public override HashTypeKey SupportedHashType => HashTypeKey.SHA384; diff --git a/src/CommonUtilities/src/Hashing/Providers/SHA512HashProvider.cs b/src/CommonUtilities/src/Hashing/Providers/SHA512HashProvider.cs index a0d73747..af086bfc 100644 --- a/src/CommonUtilities/src/Hashing/Providers/SHA512HashProvider.cs +++ b/src/CommonUtilities/src/Hashing/Providers/SHA512HashProvider.cs @@ -6,6 +6,7 @@ namespace AnakinRaW.CommonUtilities.Hashing.Providers; +// ReSharper disable once InconsistentNaming internal class SHA512HashProvider : HashAlgorithmProviderBase { public override HashTypeKey SupportedHashType => HashTypeKey.SHA512; diff --git a/src/CommonUtilities/src/NativeMethods/AdvApi32.cs b/src/CommonUtilities/src/NativeMethods/AdvApi32.cs index 55a054ec..59975990 100644 --- a/src/CommonUtilities/src/NativeMethods/AdvApi32.cs +++ b/src/CommonUtilities/src/NativeMethods/AdvApi32.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Runtime.InteropServices; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.NativeMethods; diff --git a/src/CommonUtilities/test/Collections/FrugalListTest.cs b/src/CommonUtilities/test/Collections/FrugalListTest.cs index d834dbd1..264e3200 100644 --- a/src/CommonUtilities/test/Collections/FrugalListTest.cs +++ b/src/CommonUtilities/test/Collections/FrugalListTest.cs @@ -1,4 +1,5 @@ using System; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.Test.Collections; diff --git a/src/CommonUtilities/test/Collections/FrugalListTestBase.cs b/src/CommonUtilities/test/Collections/FrugalListTestBase.cs index 551fdceb..c58981f4 100644 --- a/src/CommonUtilities/test/Collections/FrugalListTestBase.cs +++ b/src/CommonUtilities/test/Collections/FrugalListTestBase.cs @@ -7,6 +7,8 @@ namespace AnakinRaW.CommonUtilities.Test.Collections; +#pragma warning disable xUnit2013 + /// /// Contains tests that ensure the correctness of the class. /// @@ -82,7 +84,9 @@ public void Constructor_OtherFrugalList_Creates_Copy(int count) [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void Constructor_IEnumerable(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { var enumerable = CreateEnumerable(null, enumerableLength, 0, numberOfDuplicateElements); var list = new FrugalList(enumerable); @@ -98,7 +102,9 @@ public void Constructor_IEnumerable(int _, int enumerableLength, int __, int num [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void Constructor_IEnumerable_Creates_Copy(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { foreach (var modifyEnumerable in GetModifyEnumerables(ModifyEnumeratorThrows)) { @@ -316,7 +322,9 @@ public void ToArray(int count) [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void GetEnumerator(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { var enumerable = CreateEnumerable(null, enumerableLength, 0, numberOfDuplicateElements); var list = new FrugalList(enumerable); diff --git a/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTestBase.cs b/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTestBase.cs index 1134afbb..53313a0c 100644 --- a/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTestBase.cs +++ b/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTestBase.cs @@ -8,6 +8,8 @@ namespace AnakinRaW.CommonUtilities.Test.Collections; +#pragma warning disable xUnit2013 + /// /// Contains tests that ensure the correctness of the class. /// @@ -37,7 +39,9 @@ protected override IReadOnlyList GenericIReadOnlyListFactory(IEnumerable e [Fact] public void Empty_Idempotent() { + #pragma warning disable xUnit2002 Assert.NotNull(ReadOnlyFrugalList.Empty); + #pragma warning restore xUnit2002 Assert.Equal(0, ReadOnlyFrugalList.Empty.Count); Assert.Equal(ReadOnlyFrugalList.Empty, ReadOnlyFrugalList.Empty); } @@ -63,7 +67,9 @@ public void Ctor_Single() [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void Ctor_ModificationsGetNotReflectedWhenOriginalListChanges(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { var enumerable = CreateEnumerable(null, enumerableLength, 0, numberOfDuplicateElements); @@ -228,7 +234,9 @@ public void ToArray(int count) [Theory] [MemberData(nameof(GetEnumerableTestData))] + #pragma warning disable xUnit1026 public void GetEnumerator(int _, int enumerableLength, int __, int numberOfDuplicateElements) + #pragma warning restore xUnit1026 { var enumerable = CreateEnumerable(null, enumerableLength, 0, numberOfDuplicateElements); var list = new FrugalList(enumerable); diff --git a/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTests.cs b/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTests.cs index 7d38d7f4..aca8c84f 100644 --- a/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTests.cs +++ b/src/CommonUtilities/test/Collections/ReadOnlyFrugalListTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using AnakinRaW.CommonUtilities.Collections; +// ReSharper disable InconsistentNaming namespace AnakinRaW.CommonUtilities.Test.Collections; diff --git a/src/CommonUtilities/test/CommonUtilities.Test.csproj b/src/CommonUtilities/test/CommonUtilities.Test.csproj index 9622cead..39482011 100644 --- a/src/CommonUtilities/test/CommonUtilities.Test.csproj +++ b/src/CommonUtilities/test/CommonUtilities.Test.csproj @@ -1,8 +1,8 @@ - + - net9.0;net6.0 - $(TargetFrameworks);net48 + net10.0;net8.0 + $(TargetFrameworks);net481 false true @@ -14,16 +14,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/CommonUtilities/test/Extensions/EncodingExtensionsTest.cs b/src/CommonUtilities/test/Extensions/EncodingExtensionsTest.cs index 429ad521..dc35d933 100644 --- a/src/CommonUtilities/test/Extensions/EncodingExtensionsTest.cs +++ b/src/CommonUtilities/test/Extensions/EncodingExtensionsTest.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using AnakinRaW.CommonUtilities.Extensions; @@ -133,13 +134,14 @@ public void GetChars() #region EncodeString [Fact] + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] public void EncodeString_NullArgs_Throws() { Encoding encoding = null!; Assert.Throws(() => encoding.EncodeString("")); Assert.Throws(() => encoding.EncodeString("", 0)); - Assert.Throws(() => encoding!.EncodeString("".AsSpan(), Span.Empty)); - Assert.Throws(() => encoding!.EncodeString("".AsSpan(), Span.Empty, 0)); + Assert.Throws(() => encoding.EncodeString("".AsSpan(), Span.Empty)); + Assert.Throws(() => encoding.EncodeString("".AsSpan(), Span.Empty, 0)); ForEachEncoding(e => { diff --git a/src/CommonUtilities/test/Hashing/HashTypeKeyTest.cs b/src/CommonUtilities/test/Hashing/HashTypeKeyTest.cs index dbd0c50b..1d68209a 100644 --- a/src/CommonUtilities/test/Hashing/HashTypeKeyTest.cs +++ b/src/CommonUtilities/test/Hashing/HashTypeKeyTest.cs @@ -18,9 +18,9 @@ public void Ctor() public void None() { var key = HashTypeKey.None; - Assert.Null(key.Name); Assert.Equal(0, key.GetHashCode()); Assert.Equal(0, key.HashSize); + Assert.Null(key.Name); } [Fact] diff --git a/src/CommonUtilities/test/Hashing/HashingServiceTest.cs b/src/CommonUtilities/test/Hashing/HashingServiceTest.cs index d92e4717..8082c671 100644 --- a/src/CommonUtilities/test/Hashing/HashingServiceTest.cs +++ b/src/CommonUtilities/test/Hashing/HashingServiceTest.cs @@ -197,7 +197,7 @@ public void GetHash_AlwaysOneProvider() var someSource = Array.Empty(); var someStream = new MemoryStream(someSource); - var destination = new byte[] { 0, 0 }; + var destination = "\0\0"u8.ToArray(); var expectedHashExact = new byte[] { 1 }; var expectedHashJoint = new byte[] { 1, 0 }; @@ -235,7 +235,7 @@ public async Task GetHashAsync_AlwaysOneProvider() var someSource = Array.Empty(); var someStream = new MemoryStream(someSource); - var destination = new byte[] { 0, 0 }; + var destination = "\0\0"u8.ToArray(); var expectedHashExact = new byte[] { 1 }; var expectedHashJoint = new byte[] { 1, 0 };