diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs index 37b122ca4..ff74ca401 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs @@ -1,5 +1,8 @@ using System.Security.Cryptography; +#if NET6_0 +#else using AutoFixture; +#endif using FluentAssertions; using JWT.Algorithms; using JWT.Builder; @@ -10,12 +13,23 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmFactoryTests { - private static readonly Fixture _fixture = new Fixture(); + private static RSACryptoServiceProvider RSACryptoServiceProvider + { + get + { +#if NET6_0 + return new RSACryptoServiceProvider(); +#else + var fixture = new Fixture(); + return fixture.Create(); +#endif + } + } [TestMethod] public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS256() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -33,7 +47,7 @@ public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS384() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -51,7 +65,7 @@ public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS512() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -69,7 +83,8 @@ public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS1024() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; + var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -87,7 +102,7 @@ public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS2048() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -105,7 +120,7 @@ public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS4096Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS4096() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs index 10fce85ec..5d95469fd 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs @@ -2,7 +2,10 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +#if NET6_0 +#else using AutoFixture; +#endif using FluentAssertions; using JWT.Algorithms; using JWT.Tests.Models; @@ -13,13 +16,24 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmTests { - private static readonly Fixture _fixture = new Fixture(); + private static RSACryptoServiceProvider RSACryptoServiceProvider + { + get + { +#if NET6_0 + return new RSACryptoServiceProvider(); +#else + var fixture = new Fixture(); + return fixture.Create(); +#endif + } + } [DynamicData(nameof(GetFactoryWithPublicPrivateKey), DynamicDataSourceType.Method)] [DataTestMethod] public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var privateKey = _fixture.Create(); + var privateKey = RSACryptoServiceProvider; Action action = () => algFactory(null, privateKey); @@ -31,7 +45,7 @@ public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; Action action = () => algFactory(publicKey, null); @@ -43,7 +57,7 @@ public void Ctor_Should_Throw_Exception_When_PrivateKey_Is_Null(Func algFactory) { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var alg = algFactory(publicKey); var bytesToSign = Array.Empty();