From 0a308727816c21b26ae3c74059e7ec6caa180703 Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Sun, 2 Jan 2022 00:10:49 +0200 Subject: [PATCH] Introduce .netcore extensions (#11) * Introduce .netcore extensions Implement ArgumentNullException for .net6 and c#10 * Update pipelines to install .netcore 6 * Update test projects to .net 6.0 --- .github/workflows/cd.yaml | 12 +++++- .github/workflows/ci.yaml | 2 +- ...tStandard.DependencyInjection.Tests.csproj | 2 +- .../Extensions/ObjectExtensions.cs | 22 ++++++++++ .../SystemExtensions.NetCore.csproj | 23 ++++++++++ ...tensions.NetStandard.Security.Tests.csproj | 2 +- .../SystemExtensions.NetStandard.csproj | 1 + .../Extensions/ObjectExtensionsTests.cs | 42 +++++++++++++++++++ .../Http/HttpClientTests.cs | 4 +- .../SystemExtensions.NetStandard.Tests.csproj | 3 +- SystemExtensions.sln | 25 +++++++++-- 11 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 SystemExtensions.NetCore/Extensions/ObjectExtensions.cs create mode 100644 SystemExtensions.NetCore/SystemExtensions.NetCore.csproj create mode 100644 SystemExtensions.Tests/Extensions/ObjectExtensionsTests.cs diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 52692e3..9271a70 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -21,6 +21,7 @@ jobs: Test_Project_Path: SystemExtensions.Tests\SystemExtensions.NetStandard.Tests.csproj DI_Test_Project_Path: SystemExtensions.DependencyInjection.Tests\SystemExtensions.NetStandard.DependencyInjection.Tests.csproj Source_Project_Path: SystemExtensions.NetStandard\SystemExtensions.NetStandard.csproj + Core_Project_Path: SystemExtensions.NetCore\SystemExtensions.NetCore.csproj Actions_Allow_Unsecure_Commands: true steps: @@ -32,7 +33,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: '5.0.202' + dotnet-version: '6.0.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.0.1 @@ -45,6 +46,9 @@ jobs: - name: Build SystemExtensions.NetStandard project run: dotnet build SystemExtensions.NetStandard -c $env:Configuration + - name: Build SystemExtensions.NetCore project + run: dotnet build SystemExtensions.NetCore -c $env:Configuration + - name: Build SystemExtensions.NetStandard.DependencyInjection project run: dotnet build SystemExtensions.NetStandard.DependencyInjection -c $env:Configuration @@ -57,6 +61,12 @@ jobs: PROJECT_FILE_PATH: SystemExtensions.NetStandard\SystemExtensions.NetStandard.csproj NUGET_KEY: ${{secrets.NUGET_API_KEY}} + - 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: Push SystemExtensions.NetStandard.DependencyInjection nuget package uses: brandedoutcast/publish-nuget@v2.5.5 with: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index db55318..d047d34 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,7 +35,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: '5.0.202' + dotnet-version: '6.0.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.0.1 diff --git a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj index 2b581e8..4e77438 100644 --- a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj +++ b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/SystemExtensions.NetCore/Extensions/ObjectExtensions.cs b/SystemExtensions.NetCore/Extensions/ObjectExtensions.cs new file mode 100644 index 0000000..ddc67d6 --- /dev/null +++ b/SystemExtensions.NetCore/Extensions/ObjectExtensions.cs @@ -0,0 +1,22 @@ +using System.Runtime.CompilerServices; + +namespace System.Core.Extensions; + +public static class ObjectExtensions +{ + public static T ThrowIfNull([ValidatedNotNull] this T obj, [CallerArgumentExpression("obj")] string? paramName = null) + where T : class + { + if (obj is null) + { + throw new ArgumentNullException(paramName); + } + + return obj; + } + + [AttributeUsage(AttributeTargets.Parameter)] + sealed class ValidatedNotNullAttribute : Attribute + { + } +} diff --git a/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj b/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj new file mode 100644 index 0000000..9fcd27b --- /dev/null +++ b/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + true + enable + System + LICENSE + true + 1.0.0 + Alexandru Macocian + https://github.com/AlexMacocian/SystemExtensions + + + + + True + + + + + diff --git a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj index a9150ac..60ecee8 100644 --- a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj +++ b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj index 7e73c9b..2010800 100644 --- a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj +++ b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj @@ -2,6 +2,7 @@ netstandard2.0 + latest true LICENSE true diff --git a/SystemExtensions.Tests/Extensions/ObjectExtensionsTests.cs b/SystemExtensions.Tests/Extensions/ObjectExtensionsTests.cs new file mode 100644 index 0000000..5ce18d5 --- /dev/null +++ b/SystemExtensions.Tests/Extensions/ObjectExtensionsTests.cs @@ -0,0 +1,42 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace System.Extensions.Tests; + +[TestClass] +public class ObjectExtensionsTests +{ + [TestMethod] + public void ThrowIfNull_NetCore_ThrowsWithCorrectName() + { + object obj = null; + try + { + System.Core.Extensions.ObjectExtensions.ThrowIfNull(obj); + } + catch (ArgumentNullException ex) + { + ex.ParamName.Should().Be("obj"); + return; + } + + Assert.Fail("Null object should throw"); + } + + [TestMethod] + public void ThrowIfNull_NetStandard_ThrowsWithCorrectName() + { + object obj = null; + try + { + ObjectExtensions.ThrowIfNull(obj, nameof(obj)); + } + catch (ArgumentNullException ex) + { + ex.ParamName.Should().Be("obj"); + return; + } + + Assert.Fail("Null object should throw"); + } +} diff --git a/SystemExtensions.Tests/Http/HttpClientTests.cs b/SystemExtensions.Tests/Http/HttpClientTests.cs index a2ebc92..986e19f 100644 --- a/SystemExtensions.Tests/Http/HttpClientTests.cs +++ b/SystemExtensions.Tests/Http/HttpClientTests.cs @@ -1,7 +1,5 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Http; using System.IO; using System.Net; using System.Net.Http; @@ -9,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; using SystemExtensionsTests.Utils; -namespace SystemExtensionsTests.Http +namespace System.Http.Tests { [TestClass] public class HttpClientTests diff --git a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj index a47f5ba..f5cccc6 100644 --- a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj +++ b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false @@ -18,6 +18,7 @@ + diff --git a/SystemExtensions.sln b/SystemExtensions.sln index 27d2ea5..cdddf4d 100644 --- a/SystemExtensions.sln +++ b/SystemExtensions.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31005.135 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31815.197 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.NetStandard", "SystemExtensions.NetStandard\SystemExtensions.NetStandard.csproj", "{4CE9E55C-6016-4631-B8D4-4D763DD05F23}" EndProject @@ -14,9 +14,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.NetStandar EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.NetStandard.DependencyInjection.Tests", "SystemExtensions.DependencyInjection.Tests\SystemExtensions.NetStandard.DependencyInjection.Tests.csproj", "{1AFA1EEF-CEBA-4046-8466-C9B52979B7DA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemExtensions.NetStandard.Security", "SystemExtensions.NetStandard.Security\SystemExtensions.NetStandard.Security.csproj", "{BFC5BEE7-2569-45EA-9713-CDB32EED57AA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.NetStandard.Security", "SystemExtensions.NetStandard.Security\SystemExtensions.NetStandard.Security.csproj", "{BFC5BEE7-2569-45EA-9713-CDB32EED57AA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemExtensions.NetStandard.Security.Tests", "SystemExtensions.NetStandard.Security.Tests\SystemExtensions.NetStandard.Security.Tests.csproj", "{341ECE0F-A8DD-49A0-AE3D-B28D72E85130}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.NetStandard.Security.Tests", "SystemExtensions.NetStandard.Security.Tests\SystemExtensions.NetStandard.Security.Tests.csproj", "{341ECE0F-A8DD-49A0-AE3D-B28D72E85130}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemExtensions.NetCore", "SystemExtensions.NetCore\SystemExtensions.NetCore.csproj", "{9E6EBBF0-671B-4941-A72B-2CA60C882038}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{BBA334F6-779A-4A45-8BF3-EA321D0D12CF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{52962B0C-BB5F-4211-A70C-801D0A73CACC}" + ProjectSection(SolutionItems) = preProject + .github\workflows\cd.yaml = .github\workflows\cd.yaml + .github\workflows\ci.yaml = .github\workflows\ci.yaml + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -48,10 +58,17 @@ Global {341ECE0F-A8DD-49A0-AE3D-B28D72E85130}.Debug|Any CPU.Build.0 = Debug|Any CPU {341ECE0F-A8DD-49A0-AE3D-B28D72E85130}.Release|Any CPU.ActiveCfg = Release|Any CPU {341ECE0F-A8DD-49A0-AE3D-B28D72E85130}.Release|Any CPU.Build.0 = Release|Any CPU + {9E6EBBF0-671B-4941-A72B-2CA60C882038}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E6EBBF0-671B-4941-A72B-2CA60C882038}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E6EBBF0-671B-4941-A72B-2CA60C882038}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E6EBBF0-671B-4941-A72B-2CA60C882038}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {52962B0C-BB5F-4211-A70C-801D0A73CACC} = {BBA334F6-779A-4A45-8BF3-EA321D0D12CF} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BFA90E90-BD97-40AD-B19E-C723E504369A} EndGlobalSection