From 8ed38f5dcf4ed461d5066cf6e43088a94dab4275 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 22 Aug 2017 15:01:11 -0700 Subject: [PATCH] Upgrade to xunit 2.3.0-beta4 --- build/dependencies.props | 4 ++-- ...PT_AUTHENTICATED_CIPHER_MODE_INFO_Tests.cs | 5 +---- .../WeakReferenceHelpersTests.cs | 9 +++------ .../DataProtectionCommonExtensionsTests.cs | 4 ++-- .../DataProtectionAdvancedExtensionsTests.cs | 3 +-- .../DataProtectionProviderTests.cs | 6 +++--- .../TimeLimitedDataProtectorTests.cs | 20 +++++++++---------- .../KeyRingBasedDataProtectorTests.cs | 17 +++++++--------- .../KeyManagement/KeyRingTests.cs | 6 ++---- .../KeyManagement/XmlKeyManagerTests.cs | 4 ++-- .../RegistryPolicyResolverTests.cs | 4 ++-- 11 files changed, 35 insertions(+), 47 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 4502c0eba6..a3bda1eab5 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -8,8 +8,8 @@ 2.0.0-* 1.2.4 2.0.0-* - 15.3.0-* - 2.3.0-beta2-* + 15.3.0 + 2.3.0-beta4-build3742 8.1.4 diff --git a/test/Microsoft.AspNetCore.Cryptography.Internal.Test/Cng/BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_Tests.cs b/test/Microsoft.AspNetCore.Cryptography.Internal.Test/Cng/BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_Tests.cs index a455fd571f..69dfcdfe03 100644 --- a/test/Microsoft.AspNetCore.Cryptography.Internal.Test/Cng/BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_Tests.cs +++ b/test/Microsoft.AspNetCore.Cryptography.Internal.Test/Cng/BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO_Tests.cs @@ -11,11 +11,8 @@ namespace Microsoft.AspNetCore.Cryptography.Cng [Fact] public void Init_SetsProperties() { - // Arrange - BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO cipherModeInfo; - // Act - BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Init(out cipherModeInfo); + BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Init(out var cipherModeInfo); // Assert Assert.Equal((uint)sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO), cipherModeInfo.cbSize); diff --git a/test/Microsoft.AspNetCore.Cryptography.Internal.Test/WeakReferenceHelpersTests.cs b/test/Microsoft.AspNetCore.Cryptography.Internal.Test/WeakReferenceHelpersTests.cs index 8bdfddc030..da66146b07 100644 --- a/test/Microsoft.AspNetCore.Cryptography.Internal.Test/WeakReferenceHelpersTests.cs +++ b/test/Microsoft.AspNetCore.Cryptography.Internal.Test/WeakReferenceHelpersTests.cs @@ -20,10 +20,9 @@ namespace Microsoft.AspNetCore.Cryptography var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance); // Assert - MyDisposable target; Assert.NotNull(wr); Assert.NotSame(wrOriginal, wr); - Assert.True(wr.TryGetTarget(out target)); + Assert.True(wr.TryGetTarget(out var target)); Assert.Same(newInstance, target); Assert.Same(newInstance, retVal); Assert.False(newInstance.HasBeenDisposed); @@ -40,9 +39,8 @@ namespace Microsoft.AspNetCore.Cryptography var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance); // Assert - MyDisposable target; Assert.NotNull(wr); - Assert.True(wr.TryGetTarget(out target)); + Assert.True(wr.TryGetTarget(out var target)); Assert.Same(newInstance, target); Assert.Same(newInstance, retVal); Assert.False(newInstance.HasBeenDisposed); @@ -65,9 +63,8 @@ namespace Microsoft.AspNetCore.Cryptography }); // Assert - MyDisposable target; Assert.NotNull(wr); - Assert.True(wr.TryGetTarget(out target)); + Assert.True(wr.TryGetTarget(out var target)); Assert.Same(instanceThatWillBeCreatedFirst, target); Assert.Same(instanceThatWillBeCreatedFirst, retVal); Assert.False(instanceThatWillBeCreatedFirst.HasBeenDisposed); diff --git a/test/Microsoft.AspNetCore.DataProtection.Abstractions.Test/DataProtectionCommonExtensionsTests.cs b/test/Microsoft.AspNetCore.DataProtection.Abstractions.Test/DataProtectionCommonExtensionsTests.cs index c6eee2eddc..cfd4f3b41f 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Abstractions.Test/DataProtectionCommonExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Abstractions.Test/DataProtectionCommonExtensionsTests.cs @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.DataProtection { mockProtector.Object.Protect("Hello\ud800"); }); - Assert.IsAssignableFrom(typeof(EncoderFallbackException), ex.InnerException); + Assert.IsAssignableFrom(ex.InnerException); } [Fact] @@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.DataProtection { mockProtector.Object.Unprotect("AQIDBAU"); }); - Assert.IsAssignableFrom(typeof(DecoderFallbackException), ex.InnerException); + Assert.IsAssignableFrom(ex.InnerException); } [Fact] diff --git a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionAdvancedExtensionsTests.cs b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionAdvancedExtensionsTests.cs index 11fa056a4b..c98aff6c8f 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionAdvancedExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionAdvancedExtensionsTests.cs @@ -86,8 +86,7 @@ namespace Microsoft.AspNetCore.DataProtection mockDataProtector.Setup(o => o.Unprotect(new byte[] { 0x01, 0x02 }, out controlExpiration)).Returns(Encoding.UTF8.GetBytes("this is plaintext")); // Act - DateTimeOffset testExpiration; - string unprotectedPayload = mockDataProtector.Object.Unprotect(SampleEncodedString, out testExpiration); + string unprotectedPayload = mockDataProtector.Object.Unprotect(SampleEncodedString, out var testExpiration); // Assert Assert.Equal("this is plaintext", unprotectedPayload); diff --git a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionProviderTests.cs b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionProviderTests.cs index dee13c5ca1..fc73e1397d 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionProviderTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/DataProtectionProviderTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.DataProtection // Step 3: validate that there's now a single key in the directory and that it's not protected var allFiles = directory.GetFiles(); - Assert.Equal(1, allFiles.Length); + Assert.Single(allFiles); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); string fileText = File.ReadAllText(allFiles[0].FullName); Assert.Contains("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.DataProtection // Step 3: validate that there's now a single key in the directory and that it's protected with DPAPI var allFiles = directory.GetFiles(); - Assert.Equal(1, allFiles.Length); + Assert.Single(allFiles); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); string fileText = File.ReadAllText(allFiles[0].FullName); Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.DataProtection // Step 3: validate that there's now a single key in the directory and that it's is protected using the certificate var allFiles = directory.GetFiles(); - Assert.Equal(1, allFiles.Length); + Assert.Single(allFiles); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); string fileText = File.ReadAllText(allFiles[0].FullName); Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); diff --git a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/TimeLimitedDataProtectorTests.cs b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/TimeLimitedDataProtectorTests.cs index 45f8175615..6f71977154 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/TimeLimitedDataProtectorTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Extensions.Test/TimeLimitedDataProtectorTests.cs @@ -78,8 +78,7 @@ namespace Microsoft.AspNetCore.DataProtection var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act - DateTimeOffset actualExpiration; - var retVal = timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out actualExpiration); + var retVal = timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out var actualExpiration); // Assert Assert.Equal(expectedExpiration, actualExpiration); @@ -103,8 +102,8 @@ namespace Microsoft.AspNetCore.DataProtection var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act & assert - DateTimeOffset unused; - var ex = Assert.Throws(() => timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out unused)); + var ex = Assert.Throws(() + => timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out var _)); // Assert Assert.Equal(Resources.FormatTimeLimitedDataProtector_PayloadExpired(expectedExpiration), ex.Message); @@ -124,8 +123,8 @@ namespace Microsoft.AspNetCore.DataProtection var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act & assert - DateTimeOffset unused; - var ex = Assert.Throws(() => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out unused)); + var ex = Assert.Throws(() + => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out var _)); // Assert Assert.Equal(Resources.TimeLimitedDataProtector_PayloadInvalid, ex.Message); @@ -141,8 +140,8 @@ namespace Microsoft.AspNetCore.DataProtection var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); // Act & assert - DateTimeOffset unused; - var ex = Assert.Throws(() => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out unused)); + var ex = Assert.Throws(() + => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out var _)); // Assert Assert.Equal(Resources.CryptCommon_GenericError, ex.Message); @@ -162,8 +161,9 @@ namespace Microsoft.AspNetCore.DataProtection byte[] timeLimitedProtectedPayload = timeLimitedProtector.Protect(new byte[] { 0x11, 0x22, 0x33, 0x44 }, expectedExpiration); // Assert - DateTimeOffset actualExpiration; - Assert.Equal(new byte[] { 0x11, 0x22, 0x33, 0x44 }, timeLimitedProtector.UnprotectCore(timeLimitedProtectedPayload, StringToDateTime("2010-01-01 00:00:00Z"), out actualExpiration)); + Assert.Equal( + new byte[] { 0x11, 0x22, 0x33, 0x44 }, + timeLimitedProtector.UnprotectCore(timeLimitedProtectedPayload, StringToDateTime("2010-01-01 00:00:00Z"), out var actualExpiration)); Assert.Equal(expectedExpiration, actualExpiration); // the two providers shouldn't be able to talk to one another (due to the purpose chaining) diff --git a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingBasedDataProtectorTests.cs b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingBasedDataProtectorTests.cs index eb8d35fef0..d28ea7ff84 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingBasedDataProtectorTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingBasedDataProtectorTests.cs @@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement // Act & assert var ex = ExceptionAssert2.ThrowsCryptographicException(() => protector.Protect(new byte[0])); - Assert.IsAssignableFrom(typeof(MockException), ex.InnerException); + Assert.IsAssignableFrom(ex.InnerException); } [Fact] @@ -291,11 +291,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement newPurpose: "purpose"); // Act - bool requiresMigration, wasRevoked; byte[] retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, ignoreRevocationErrors: true, - requiresMigration: out requiresMigration, - wasRevoked: out wasRevoked); + requiresMigration: out var requiresMigration, + wasRevoked: out var wasRevoked); // Assert Assert.Equal(expectedPlaintext, retVal); @@ -342,11 +341,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement Assert.Equal(expectedPlaintext, retVal); // Act & assert - IPersistedDataProtector - bool requiresMigration, wasRevoked; retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, ignoreRevocationErrors: false, - requiresMigration: out requiresMigration, - wasRevoked: out wasRevoked); + requiresMigration: out var requiresMigration, + wasRevoked: out var wasRevoked); Assert.Equal(expectedPlaintext, retVal); Assert.False(requiresMigration); Assert.False(wasRevoked); @@ -393,11 +391,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement Assert.Equal(expectedPlaintext, retVal); // Act & assert - IPersistedDataProtector - bool requiresMigration, wasRevoked; retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, ignoreRevocationErrors: false, - requiresMigration: out requiresMigration, - wasRevoked: out wasRevoked); + requiresMigration: out var requiresMigration, + wasRevoked: out var wasRevoked); Assert.Equal(expectedPlaintext, retVal); Assert.True(requiresMigration); Assert.False(wasRevoked); diff --git a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingTests.cs b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingTests.cs index 4d137986fa..177c7c5d63 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/KeyRingTests.cs @@ -57,9 +57,8 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement var keyRing = new KeyRing(key3, new[] { key1, key2 }); // Assert - bool unused; Assert.Equal(key3.KeyId, keyRing.DefaultKeyId); - Assert.Equal(key3.CreateEncryptor(), keyRing.GetAuthenticatedEncryptorByKeyId(key3.KeyId, out unused)); + Assert.Equal(key3.CreateEncryptor(), keyRing.GetAuthenticatedEncryptorByKeyId(key3.KeyId, out var _)); } [Fact] @@ -77,9 +76,8 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement var keyRing = new KeyRing(key2, new[] { key1, key2 }); // Assert - bool isRevoked; Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); - Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); + Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out var isRevoked)); Assert.True(isRevoked); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); diff --git a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/XmlKeyManagerTests.cs b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/XmlKeyManagerTests.cs index 231e0c7b15..ba9f21be61 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/XmlKeyManagerTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Test/KeyManagement/XmlKeyManagerTests.cs @@ -476,7 +476,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray(); // Assert - Assert.Equal(1, keys.Length); + Assert.Single(keys); Assert.Equal(new Guid("09712588-ba68-438a-a5ee-fe842b3453b2"), keys[0].KeyId); Assert.Same(expectedDescriptor, keys[0].Descriptor); } @@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray(); // Assert - Assert.Equal(1, keys.Length); + Assert.Single(keys); Assert.Equal(new Guid("49c0cda9-0232-4d8c-a541-de20cc5a73d6"), keys[0].KeyId); Assert.Same(expectedDescriptor, keys[0].Descriptor); } diff --git a/test/Microsoft.AspNetCore.DataProtection.Test/RegistryPolicyResolverTests.cs b/test/Microsoft.AspNetCore.DataProtection.Test/RegistryPolicyResolverTests.cs index d2de2cde39..d10fd872cd 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Test/RegistryPolicyResolverTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Test/RegistryPolicyResolverTests.cs @@ -55,8 +55,8 @@ namespace Microsoft.AspNetCore.DataProtection // Assert var actualKeyEscrowSinks = context.KeyEscrowSinks.ToArray(); Assert.Equal(2, actualKeyEscrowSinks.Length); - Assert.IsType(typeof(MyKeyEscrowSink1), actualKeyEscrowSinks[0]); - Assert.IsType(typeof(MyKeyEscrowSink2), actualKeyEscrowSinks[1]); + Assert.IsType(actualKeyEscrowSinks[0]); + Assert.IsType(actualKeyEscrowSinks[1]); } [ConditionalFact]