diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignatureUtilityTests.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignatureUtilityTests.cs index f4b766c9eef..93b0c6e2966 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignatureUtilityTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignatureUtilityTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Collections.Generic; diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignedPackageArchiveTests.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignedPackageArchiveTests.cs index d3c269140f0..d53820d567b 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignedPackageArchiveTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SignedPackageArchiveTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.IO; using System.Security.Cryptography.X509Certificates; diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningUtilityTests.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningUtilityTests.cs index f01d2671592..d9f884a1b78 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningUtilityTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningUtilityTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Diagnostics; diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampProviderTests.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampProviderTests.cs index e7fc94c91b9..e7d8e6a49ed 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampProviderTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampProviderTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Collections.Generic; @@ -24,7 +24,6 @@ namespace NuGet.Packaging.FuncTest [Collection(SigningTestCollection.Name)] public class TimestampProviderTests { - private const string ArgumentNullExceptionMessage = "Value cannot be null.\r\nParameter name: {0}"; private const string OperationCancelledExceptionMessage = "The operation was canceled."; private SigningTestFixture _testFixture; @@ -70,7 +69,7 @@ public async Task GetTimestampAsync_WithValidInput_ReturnsTimestampAsync() } [CIOnlyFact] - public async Task GetTimestamp_AssertCompleteChain_SuccessAsync() + public async Task GetTimestampAsync_AssertCompleteChain_SuccessAsync() { var timestampService = await _testFixture.GetDefaultTrustedTimestampServiceAsync(); var timestampProvider = new Rfc3161TimestampProvider(timestampService.Url); @@ -157,12 +156,12 @@ public async Task GetTimestampAsync_WhenRequestNull_ThrowsAsync() target: SignaturePlacement.PrimarySignature ); - // Act - Action timestampAction = async () => await timestampProvider.GetTimestampAsync(null, logger, CancellationToken.None); - // Assert - timestampAction.ShouldThrow() - .WithMessage(string.Format(ArgumentNullExceptionMessage, nameof(request))); + var exception = await Assert.ThrowsAsync( + () => timestampProvider.GetTimestampAsync(request: null, logger, CancellationToken.None)); + + Assert.Equal("request", exception.ParamName); + Assert.StartsWith("Value cannot be null.", exception.Message); } } @@ -188,12 +187,12 @@ public async Task GetTimestampAsync_WhenLoggerNull_ThrowsAsync() target: SignaturePlacement.PrimarySignature ); - // Act - Action timestampAction = async () => await timestampProvider.GetTimestampAsync(request, null, CancellationToken.None); - // Assert - timestampAction.ShouldThrow() - .WithMessage(string.Format(ArgumentNullExceptionMessage, "logger")); + var exception = await Assert.ThrowsAsync( + () => timestampProvider.GetTimestampAsync(request, logger: null, CancellationToken.None)); + + Assert.Equal("logger", exception.ParamName); + Assert.StartsWith("Value cannot be null.", exception.Message); } } @@ -220,12 +219,11 @@ public async Task GetTimestampAsync_WhenCancelled_ThrowsAsync() target: SignaturePlacement.PrimarySignature ); - // Act - Action timestampAction = async () => await timestampProvider.GetTimestampAsync(request, logger, new CancellationToken(canceled: true)); - // Assert - timestampAction.ShouldThrow() - .WithMessage(OperationCancelledExceptionMessage); + var exception = await Assert.ThrowsAsync( + () => timestampProvider.GetTimestampAsync(request, logger, new CancellationToken(canceled: true))); + + Assert.Equal(OperationCancelledExceptionMessage, exception.Message); } } diff --git a/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests.cs b/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests.cs index 814cb2da9ad..4171be37257 100644 --- a/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests.cs @@ -969,7 +969,7 @@ public async Task RestoreCommand_ImportsNoMatchAsync() } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public async Task RestoreCommand_InvalidSignedPackageAsync() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/PackageArchiveReaderTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/PackageArchiveReaderTests.cs index 1c369ffca76..f379f70d151 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/PackageArchiveReaderTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/PackageArchiveReaderTests.cs @@ -1597,7 +1597,7 @@ await Assert.ThrowsAsync( } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public async Task ValidateIntegrityAsync_WhenSignatureContentNull_Throws() { @@ -1835,7 +1835,7 @@ public void GetContentHash_UnsignedPackage_WhenGivingAFallbackFunctionThatReturn } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [CIOnlyFact] public async Task GetContentHash_IsSameForUnsignedAndSignedPackageAsync() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/AttributeUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/AttributeUtilityTests.cs index 382231920b7..c4eb8b83871 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/AttributeUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/AttributeUtilityTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Linq; using System.Security.Cryptography; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdTests.cs index c63c07cb875..25e39bf9cb7 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdTests.cs @@ -36,7 +36,7 @@ public void Read_WithInvalidAsn1_Throws() () => EssCertId.Read(new byte[] { 0x30, 0x0b })); } -#if !IS_CORECLR +#if IS_SIGNING_SUPPORTED [Fact] public void Read_WithValidInput_ReturnsEssCertId() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdV2Tests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdV2Tests.cs index 7969df8bfd9..9d005a41aac 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdV2Tests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/EssCertIdV2Tests.cs @@ -168,7 +168,7 @@ public void Read_WithNonDefaultAlgorithmIdentifier_ReturnsEssCertIdV2() SigningTestUtility.VerifyByteArrays(bcIssuerSerial.Serial.Value.ToByteArray(), essCertIdV2.IssuerSerial.SerialNumber); } -#if !IS_CORECLR +#if IS_SIGNING_SUPPORTED [Fact] public void Read_WithValidInput_ReturnsEssCertId() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/PrimarySignatureTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/PrimarySignatureTests.cs index 39199bc84e9..6a16317678a 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/PrimarySignatureTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/PrimarySignatureTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Security.Cryptography.Pkcs; using System.Security.Cryptography.X509Certificates; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/ReadOnlyBufferedStreamTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/ReadOnlyBufferedStreamTests.cs index e693f00c2d1..020abfd9bdf 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/ReadOnlyBufferedStreamTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/ReadOnlyBufferedStreamTests.cs @@ -249,7 +249,7 @@ public void WriteTimeout_Setter_SetsValueOnUnderlyingStream() } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public void Close_WhenLeaveOpenFalse_DisposesUnderlyingStream() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/RepositoryCountersignatureTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/RepositoryCountersignatureTests.cs index 20a18861eb0..8c34ef7f080 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/RepositoryCountersignatureTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/RepositoryCountersignatureTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.Collections.Generic; using System.Linq; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureTrustAndValidityVerificationProviderTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureTrustAndValidityVerificationProviderTests.cs index 5e6fd38a398..ad86d149397 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureTrustAndValidityVerificationProviderTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureTrustAndValidityVerificationProviderTests.cs @@ -14,7 +14,7 @@ namespace NuGet.Packaging.Test { public class SignatureTrustAndValidityVerificationProviderTests { -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED private static readonly Lazy _signature = new Lazy( () => PrimarySignature.Load(SigningTestUtility.GetResourceBytes(".signature.p7s"))); #endif @@ -25,7 +25,7 @@ public SignatureTrustAndValidityVerificationProviderTests() _provider = new SignatureTrustAndValidityVerificationProvider(); } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public async Task GetTrustResultAsync_WhenPackageIsNull_Throws() { @@ -53,7 +53,7 @@ public async Task GetTrustResultAsync_WhenSignatureIsNull_Throws() Assert.Equal("signature", exception.ParamName); } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public async Task GetTrustResultAsync_WhenSettingsIsNull_Throws() { diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureUtilityTests.cs index 1607159a045..3a0c06797e6 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignatureUtilityTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.IO; using System.Threading; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveIOUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveIOUtilityTests.cs index c911cd72d24..8f9e003d53b 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveIOUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveIOUtilityTests.cs @@ -165,7 +165,7 @@ public void ReadAndHashUntilPosition_WhenPositionBeforeCurrentReadPosition_Throw } } -#if !IS_CORECLR +#if IS_SIGNING_SUPPORTED [Fact] public void ReadAndHashUntilPosition_WhenPositionAtStart_ReadsAndHashes() { @@ -248,7 +248,7 @@ public void HashBytes_WhenBytesNullOrEmpty_Throws(byte[] bytes) } } -#if !IS_CORECLR +#if IS_SIGNING_SUPPORTED [Fact] public void HashBytes_WithInputBytes_Hashes() { @@ -486,7 +486,7 @@ protected override void Dispose(bool disposing) internal string GetHash() { -#if !IS_CORECLR +#if IS_SIGNING_SUPPORTED HashAlgorithm.TransformFinalBlock(new byte[0], inputOffset: 0, inputCount: 0); return Convert.ToBase64String(HashAlgorithm.Hash); diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveTests.cs index f8fa6c9aaac..40969f77eaf 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveUtilityTests.cs index ff6ab82aedb..a3644f6353f 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SignedPackageArchiveUtilityTests.cs @@ -257,7 +257,7 @@ public void GetPackageContentHash_WithCompressedSignatureFileEntry_NotThrows() } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public async Task RemoveRepositorySignaturesAsync_WithNullInput_Throws() { @@ -542,7 +542,7 @@ public void Dispose() } } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED private sealed class RemoveTest : IDisposable { private bool _isDisposed; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningOptionsTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningOptionsTests.cs index a032b558bba..4902b2eb6f0 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningOptionsTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningOptionsTests.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System; using System.IO; using Moq; diff --git a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningUtilityTests.cs index 16edf8e21cb..f86e807678c 100644 --- a/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/SigningUtilityTests.cs @@ -6,7 +6,7 @@ using System.IO; using System.IO.Compression; using System.Linq; -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED using System.Security.Cryptography.Pkcs; #endif using System.Security.Cryptography.X509Certificates; @@ -159,7 +159,7 @@ public void Verify_WithUntrustedSelfSignedCertificate_Succeeds() } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED [Fact] public void CreateSignedAttributes_SignPackageRequest_WhenRequestNull_Throws() { diff --git a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs index 04110c535fb..06320b13b2f 100644 --- a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs +++ b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs @@ -496,7 +496,7 @@ public static SignedCms GenerateSignedCms(X509Certificate2 cert, byte[] content) return cms; } -#if IS_DESKTOP +#if IS_SIGNING_SUPPORTED /// /// Generates a SignedCMS object for some content. ///