From 7222528eed114bc62a001f1cb89516e16fb6708e Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Thu, 2 Jun 2022 10:42:34 +0200 Subject: [PATCH] Update dependencies (#16) * Update dependencies Implement AsyncLazy Fix namespaces Fix CD pipeline * Fix code issues Fix Int64BitStruct test --- .github/workflows/cd.yaml | 31 +++++------- .../Configuration/OptionsResolverTests.cs | 3 +- ...tStandard.DependencyInjection.Tests.csproj | 15 +++--- ...ons.NetStandard.DependencyInjection.csproj | 4 +- ...8DeriveBytesPasswordHashingServiceTests.cs | 36 +++++++------- ...tensions.NetStandard.Security.Tests.csproj | 13 +++-- ...stemExtensions.NetStandard.Security.csproj | 2 +- .../Extensions/BytesExtensions.cs | 14 +++--- .../Http/HttpClient.cs | 3 +- .../Http/HttpClientEventMessage.cs | 2 +- .../Http/IHttpClient.cs | 3 +- .../SystemExtensions.NetStandard.csproj | 4 +- .../Threading/AsyncLazy.cs | 26 ++++++++++ .../Threading/PriorityThreadPool.cs | 25 ++++------ .../Collections/AVLTreeTests.cs | 3 +- .../Collections/BinaryHeapTests.cs | 1 - .../Collections/FibonacciHeapTests.cs | 5 +- .../Collections/PriorityQueueTests.cs | 1 - .../Collections/SkipListTests.cs | 5 +- .../Collections/TreapTests.cs | 1 - .../Http/HttpClientTests.cs | 4 +- .../Structures/Int64BitStructTests.cs | 2 +- .../SystemExtensions.NetStandard.Tests.csproj | 10 ++-- .../Threading/AsyncLazyTests.cs | 47 +++++++++++++++++++ .../Threading/PriorityThreadPoolTests.cs | 2 +- 25 files changed, 155 insertions(+), 107 deletions(-) create mode 100644 SystemExtensions.NetStandard/Threading/AsyncLazy.cs create mode 100644 SystemExtensions.Tests/Threading/AsyncLazyTests.cs diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 9271a70..603f1a1 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -55,26 +55,17 @@ jobs: - name: Build SystemExtensions.NetStandard.Security project run: dotnet build SystemExtensions.NetStandard.Security -c $env:Configuration - - name: Push SystemExtensions.NetStandard nuget package - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: SystemExtensions.NetStandard\SystemExtensions.NetStandard.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} + - name: Package SystemExtensions.NetStandard + run: dotnet pack -c Release -o . SystemExtensions.NetStandard\SystemExtensions.NetStandard.csproj - - name: Push SystemExtensions.NetCore nuget package - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: SystemExtensions.NetCore\SystemExtensions.NetCore.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} + - name: Package SystemExtensions.NetCore + run: dotnet pack -c Release -o . SystemExtensions.NetCore\SystemExtensions.NetCore.csproj - - name: Push SystemExtensions.NetStandard.DependencyInjection nuget package - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: SystemExtensions.NetStandard.DependencyInjection\SystemExtensions.NetStandard.DependencyInjection.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} + - name: Package SystemExtensions.NetStandard.DependencyInjection + run: dotnet pack -c Release -o . SystemExtensions.NetStandard.DependencyInjection\SystemExtensions.NetStandard.DependencyInjection.csproj - - name: Push SystemExtensions.NetStandard.Security nuget package - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: SystemExtensions.NetStandard.Security\SystemExtensions.NetStandard.Security.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} \ No newline at end of file + - name: Package SystemExtensions.NetStandard.Security + run: dotnet pack -c Release -o . SystemExtensions.NetStandard.Security\SystemExtensions.NetStandard.Security.csproj + + - name: Publish + run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs index 6b556ba..82125ac 100644 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs +++ b/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs @@ -12,9 +12,8 @@ namespace SystemExtensions.DependencyInjection.Tests.Configuration { private readonly OptionsResolver optionsResolver = new(); private readonly Mock serviceProviderMock = new(); - private readonly Mock optionsManagerMock = new(); - public Mock OptionsManagerMock => optionsManagerMock; + public Mock OptionsManagerMock { get; } = new(); [TestMethod] public void CanResolve_ILiveOptions_ReturnsTrue() diff --git a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj index 4e77438..e879d4d 100644 --- a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj +++ b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj @@ -7,12 +7,15 @@ - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj b/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj index 700b3a4..fb84a79 100644 --- a/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj +++ b/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj @@ -22,8 +22,8 @@ - - + + diff --git a/SystemExtensions.NetStandard.Security.Tests/Rfc2898DeriveBytesPasswordHashingServiceTests.cs b/SystemExtensions.NetStandard.Security.Tests/Rfc2898DeriveBytesPasswordHashingServiceTests.cs index 6435968..ac0e3b3 100644 --- a/SystemExtensions.NetStandard.Security.Tests/Rfc2898DeriveBytesPasswordHashingServiceTests.cs +++ b/SystemExtensions.NetStandard.Security.Tests/Rfc2898DeriveBytesPasswordHashingServiceTests.cs @@ -47,126 +47,126 @@ namespace SystemExtensions.NetStandard.Security.Tests { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(null, this.saltBytes, DesiredHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void PasswordNull_HashString_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(null, this.saltString, DesiredHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void SaltNull_HashBytes_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordBytes, null, DesiredHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void SaltNull_HashString_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordString, null, DesiredHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void HashLengthTooSmall_HashBytes_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordBytes, this.saltBytes, TooShortHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void HashLengthTooSmall_HashString_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordString, this.saltString, TooShortHashLength, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooLittleIterations_HashBytes_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordBytes, this.saltBytes, DesiredHashLength, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooLittleIterations_HashString_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordString, this.saltString, DesiredHashLength, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooShortSalt_HashBytes_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordBytes, this.tooShortSaltBytes, DesiredHashLength, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooShortSalt_HashString_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.Hash(this.passwordString, this.tooShortSaltString, DesiredHashLength, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void PasswordNull_VerifyBytes_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(null, this.incorrectPasswordBytes, this.saltBytes, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void PasswordNull_VerifyString_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(null, this.incorrectPasswordString, this.saltString, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void HashNull_VerifyBytes_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordBytes, null, this.saltBytes, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void HashNull_VerifyString_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordString, null, this.saltString, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void SaltNull_VerifyBytes_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordBytes, this.incorrectPasswordBytes, null, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void SaltNull_VerifyString_Throws_ArgumentNullException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordString, this.incorrectPasswordString, null, Iterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooLittleIterations_VerifyBytes_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordBytes, this.incorrectPasswordBytes, this.saltBytes, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public void TooLittleIterations_VerifyString_Throws_InvalidOperationException() { var action = new Func>(() => this.rfc2898DeriveBytesPasswordHashingService.VerifyPassword(this.passwordString, this.incorrectPasswordString, this.saltString, TooLittleIterations)); - action.Should().Throw(); + action.Should().ThrowAsync(); } [TestMethod] public async Task HashBytes_ReturnsHashedBytes() diff --git a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj index 60ecee8..f4fc466 100644 --- a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj +++ b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj @@ -7,11 +7,14 @@ - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/SystemExtensions.NetStandard.Security/SystemExtensions.NetStandard.Security.csproj b/SystemExtensions.NetStandard.Security/SystemExtensions.NetStandard.Security.csproj index c453bad..69cbdc3 100644 --- a/SystemExtensions.NetStandard.Security/SystemExtensions.NetStandard.Security.csproj +++ b/SystemExtensions.NetStandard.Security/SystemExtensions.NetStandard.Security.csproj @@ -21,7 +21,7 @@ - + \ No newline at end of file diff --git a/SystemExtensions.NetStandard/Extensions/BytesExtensions.cs b/SystemExtensions.NetStandard/Extensions/BytesExtensions.cs index ebcd22a..cbbe825 100644 --- a/SystemExtensions.NetStandard/Extensions/BytesExtensions.cs +++ b/SystemExtensions.NetStandard/Extensions/BytesExtensions.cs @@ -12,16 +12,14 @@ namespace System.Extensions } var buffer = new byte[256]; - using (var ms = new MemoryStream()) + using var ms = new MemoryStream(); + int read; + while ((read = stream.Read(buffer, 0, 256)) > 0) { - int read; - while ((read = stream.Read(buffer, 0, 256)) > 0) - { - ms.Write(buffer, 0, read); - } - - return ms.ToArray(); + ms.Write(buffer, 0, read); } + + return ms.ToArray(); } } } diff --git a/SystemExtensions.NetStandard/Http/HttpClient.cs b/SystemExtensions.NetStandard/Http/HttpClient.cs index ecf2bef..f622213 100644 --- a/SystemExtensions.NetStandard/Http/HttpClient.cs +++ b/SystemExtensions.NetStandard/Http/HttpClient.cs @@ -1,10 +1,9 @@ using System.IO; -using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -namespace System.Http +namespace System.Net.Http { public sealed class HttpClient : IHttpClient, IDisposable { diff --git a/SystemExtensions.NetStandard/Http/HttpClientEventMessage.cs b/SystemExtensions.NetStandard/Http/HttpClientEventMessage.cs index 2393989..ed1b2b6 100644 --- a/SystemExtensions.NetStandard/Http/HttpClientEventMessage.cs +++ b/SystemExtensions.NetStandard/Http/HttpClientEventMessage.cs @@ -1,4 +1,4 @@ -namespace System.Http +namespace System.Net.Http { public sealed class HttpClientEventMessage { diff --git a/SystemExtensions.NetStandard/Http/IHttpClient.cs b/SystemExtensions.NetStandard/Http/IHttpClient.cs index ddd7334..8453a8a 100644 --- a/SystemExtensions.NetStandard/Http/IHttpClient.cs +++ b/SystemExtensions.NetStandard/Http/IHttpClient.cs @@ -1,10 +1,9 @@ using System.IO; -using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -namespace System.Http +namespace System.Net.Http { public interface IHttpClient { diff --git a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj index 3b419a0..1a18e4e 100644 --- a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj +++ b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj @@ -7,7 +7,7 @@ LICENSE true System - 1.4.1 + 1.5 Alexandru Macocian https://github.com/AlexMacocian/SystemExtensions Extensions for the System namespace @@ -21,7 +21,7 @@ - + diff --git a/SystemExtensions.NetStandard/Threading/AsyncLazy.cs b/SystemExtensions.NetStandard/Threading/AsyncLazy.cs new file mode 100644 index 0000000..9ee1efe --- /dev/null +++ b/SystemExtensions.NetStandard/Threading/AsyncLazy.cs @@ -0,0 +1,26 @@ +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace System; + +/// +/// Async implementation of . +/// +/// +/// Credits: https://devblogs.microsoft.com/pfxteam/asynclazyt/ +/// +/// Type of value to be returned. +public sealed class AsyncLazy : Lazy> +{ + public TaskAwaiter GetAwaiter() => this.Value.GetAwaiter(); + + public AsyncLazy(Func valueFactory) + : base(() => Task.Factory.StartNew(valueFactory)) + { + } + + public AsyncLazy(Func> taskFactory) + : base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) + { + } +} diff --git a/SystemExtensions.NetStandard/Threading/PriorityThreadPool.cs b/SystemExtensions.NetStandard/Threading/PriorityThreadPool.cs index b30d989..66e68a3 100644 --- a/SystemExtensions.NetStandard/Threading/PriorityThreadPool.cs +++ b/SystemExtensions.NetStandard/Threading/PriorityThreadPool.cs @@ -42,6 +42,7 @@ namespace System.Threading priority1 = 0; break; } + switch (other.TaskPriority) { case TaskPriority.Highest: @@ -60,6 +61,7 @@ namespace System.Threading priority2 = 0; break; } + if (priority1 == priority2) { return 0; @@ -111,7 +113,6 @@ namespace System.Threading private volatile PriorityQueue tasks; private Thread observer; private CancellationTokenSource observerCancellationTokenSource = new CancellationTokenSource(); - private int maxThreads; private readonly object tasksLock = new object(); private struct WorkerThread { @@ -152,17 +153,7 @@ namespace System.Threading /// /// Maximum amount of threads that the pool can utilize /// - public int MaxThreads - { - set - { - maxThreads = value; - } - get - { - return maxThreads; - } - } + public int MaxThreads { set; get; } #endregion #region Constructors /// @@ -173,8 +164,8 @@ namespace System.Threading { threadpool = new List(); tasks = new PriorityQueue(); - maxThreads = System.Environment.ProcessorCount; - for (var i = 0; i < maxThreads; i++) + MaxThreads = System.Environment.ProcessorCount; + for (var i = 0; i < MaxThreads; i++) { this.CreateAndStartWorkerThread(); } @@ -193,7 +184,7 @@ namespace System.Threading { threadpool = new List(); tasks = new PriorityQueue(); - this.maxThreads = Math.Max(maxThreads, 1); + this.MaxThreads = Math.Max(maxThreads, 1); for (var i = 0; i < maxThreads; i++) { this.CreateAndStartWorkerThread(); @@ -415,7 +406,7 @@ namespace System.Threading //This part of code modifies the number of active threads based on the current performance of the threadpool if (statistics.PerformanceCounter >= 5) { - if (threadpool.Count < this.maxThreads) + if (threadpool.Count < this.MaxThreads) { //Add a thread to the threadpool. //Reset counter to 0. @@ -425,7 +416,7 @@ namespace System.Threading } else if (statistics.PerformanceCounter <= -10) { - if (threadpool.Count > maxThreads / 4) + if (threadpool.Count > MaxThreads / 4) { //Remove the last thread in the threadpool. //If thread is currently working, notify it to close. diff --git a/SystemExtensions.Tests/Collections/AVLTreeTests.cs b/SystemExtensions.Tests/Collections/AVLTreeTests.cs index 6661859..357aaf5 100644 --- a/SystemExtensions.Tests/Collections/AVLTreeTests.cs +++ b/SystemExtensions.Tests/Collections/AVLTreeTests.cs @@ -119,7 +119,7 @@ namespace System.Collections.Tests avlTree.Add(i); } - var array = avlTree.ToArray(); + _ = avlTree.ToArray(); } [TestMethod()] @@ -131,7 +131,6 @@ namespace System.Collections.Tests avlTree.Add(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, avlTree); diff --git a/SystemExtensions.Tests/Collections/BinaryHeapTests.cs b/SystemExtensions.Tests/Collections/BinaryHeapTests.cs index f5ec870..a3aa2e9 100644 --- a/SystemExtensions.Tests/Collections/BinaryHeapTests.cs +++ b/SystemExtensions.Tests/Collections/BinaryHeapTests.cs @@ -179,7 +179,6 @@ namespace System.Collections.Tests binaryHeap.Add(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, binaryHeap); stream.Position = 0; diff --git a/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs b/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs index 7ec1690..e8bb56e 100644 --- a/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs +++ b/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs @@ -62,11 +62,11 @@ namespace System.Collections.Tests fibonacciHeap.Remove(); Assert.Fail(); } - catch(IndexOutOfRangeException exception) + catch (IndexOutOfRangeException) { } - catch(Exception e) + catch (Exception) { Assert.Fail(); } @@ -181,7 +181,6 @@ namespace System.Collections.Tests fibonacciHeap.Add(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, fibonacciHeap); diff --git a/SystemExtensions.Tests/Collections/PriorityQueueTests.cs b/SystemExtensions.Tests/Collections/PriorityQueueTests.cs index fcd65b5..5776b0c 100644 --- a/SystemExtensions.Tests/Collections/PriorityQueueTests.cs +++ b/SystemExtensions.Tests/Collections/PriorityQueueTests.cs @@ -87,7 +87,6 @@ namespace System.Collections.Tests priorityQueue.Enqueue(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, priorityQueue); diff --git a/SystemExtensions.Tests/Collections/SkipListTests.cs b/SystemExtensions.Tests/Collections/SkipListTests.cs index 24342f4..e0b4e19 100644 --- a/SystemExtensions.Tests/Collections/SkipListTests.cs +++ b/SystemExtensions.Tests/Collections/SkipListTests.cs @@ -12,13 +12,13 @@ namespace System.Collections.Tests [TestMethod()] public void SkipListTest() { - var skipList = new SkipList(); + _ = new SkipList(); } [TestMethod()] public void SkipListTest2() { - var skipList = new SkipList(30); + _ = new SkipList(30); } [TestMethod()] @@ -132,7 +132,6 @@ namespace System.Collections.Tests skipList.Add(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, skipList); diff --git a/SystemExtensions.Tests/Collections/TreapTests.cs b/SystemExtensions.Tests/Collections/TreapTests.cs index 1dd46de..53f6de5 100644 --- a/SystemExtensions.Tests/Collections/TreapTests.cs +++ b/SystemExtensions.Tests/Collections/TreapTests.cs @@ -118,7 +118,6 @@ namespace System.Collections.Tests treap.Add(i); } var serializer = new BinaryFormatter(); - var s = string.Empty; using (var stream = new MemoryStream()) { serializer.Serialize(stream, treap); diff --git a/SystemExtensions.Tests/Http/HttpClientTests.cs b/SystemExtensions.Tests/Http/HttpClientTests.cs index 986e19f..ba25653 100644 --- a/SystemExtensions.Tests/Http/HttpClientTests.cs +++ b/SystemExtensions.Tests/Http/HttpClientTests.cs @@ -1,13 +1,11 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; -using System.Net; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using SystemExtensionsTests.Utils; -namespace System.Http.Tests +namespace System.Net.Http.Tests { [TestClass] public class HttpClientTests diff --git a/SystemExtensions.Tests/Structures/Int64BitStructTests.cs b/SystemExtensions.Tests/Structures/Int64BitStructTests.cs index bf349bc..9837459 100644 --- a/SystemExtensions.Tests/Structures/Int64BitStructTests.cs +++ b/SystemExtensions.Tests/Structures/Int64BitStructTests.cs @@ -16,7 +16,7 @@ namespace System.Structures.BitStructures.Tests [DataTestMethod] [DataRow(1UL)] - public void TestSetValueUint(long value) + public void TestSetValueUint(ulong value) { Int64BitStruct int64 = value; Assert.IsTrue(int64 == value); diff --git a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj index f5cccc6..47d3e69 100644 --- a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj +++ b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj @@ -7,11 +7,11 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/SystemExtensions.Tests/Threading/AsyncLazyTests.cs b/SystemExtensions.Tests/Threading/AsyncLazyTests.cs new file mode 100644 index 0000000..dc6a0a4 --- /dev/null +++ b/SystemExtensions.Tests/Threading/AsyncLazyTests.cs @@ -0,0 +1,47 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; + +namespace System.Tests; + +[TestClass] +public class AsyncLazyTests +{ + private const string Value = "Value"; + + [TestMethod] + public async Task ValueFactoryConstructor_AwaitsAndReturnsValue() + { + var asyncLazy = new AsyncLazy(() => Value); + + var value = await asyncLazy; + + value.Should().Be(Value); + } + + [TestMethod] + public async Task TaskFactoryConstructor_AwaitsAndReturnsValue() + { + var asyncLazy = new AsyncLazy(GetValueTask); + + var value = await asyncLazy; + + value.Should().Be(Value); + } + + [TestMethod] + public async Task Value_ReturnsValue() + { + var asyncLazy = new AsyncLazy(GetValueTask); + + var value = await asyncLazy.Value; + + value.Should().Be(Value); + } + + private static async Task GetValueTask() + { + await Task.Delay(10); + return Value; + } +} diff --git a/SystemExtensions.Tests/Threading/PriorityThreadPoolTests.cs b/SystemExtensions.Tests/Threading/PriorityThreadPoolTests.cs index 7d03f7f..1950986 100644 --- a/SystemExtensions.Tests/Threading/PriorityThreadPoolTests.cs +++ b/SystemExtensions.Tests/Threading/PriorityThreadPoolTests.cs @@ -52,7 +52,7 @@ namespace System.Threading.Tests var x = threadPool.NumberOfThreads; Assert.Fail(); } - catch(Exception e) + catch (Exception) { }