Upgrade to xunit 2.3.0-beta4

This commit is contained in:
Nate McMaster 2017-08-22 15:01:11 -07:00
parent bd8207bf8f
commit 8ed38f5dcf
11 changed files with 35 additions and 47 deletions

View File

@ -8,8 +8,8 @@
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion> <NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<RedisVersion>1.2.4</RedisVersion> <RedisVersion>1.2.4</RedisVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion> <RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
<TestSdkVersion>15.3.0-*</TestSdkVersion> <TestSdkVersion>15.3.0</TestSdkVersion>
<XunitVersion>2.3.0-beta2-*</XunitVersion> <XunitVersion>2.3.0-beta4-build3742</XunitVersion>
<WindowsAzureStorageVersion>8.1.4</WindowsAzureStorageVersion> <WindowsAzureStorageVersion>8.1.4</WindowsAzureStorageVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -11,11 +11,8 @@ namespace Microsoft.AspNetCore.Cryptography.Cng
[Fact] [Fact]
public void Init_SetsProperties() public void Init_SetsProperties()
{ {
// Arrange
BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO cipherModeInfo;
// Act // Act
BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Init(out cipherModeInfo); BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Init(out var cipherModeInfo);
// Assert // Assert
Assert.Equal((uint)sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO), cipherModeInfo.cbSize); Assert.Equal((uint)sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO), cipherModeInfo.cbSize);

View File

@ -20,10 +20,9 @@ namespace Microsoft.AspNetCore.Cryptography
var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance); var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance);
// Assert // Assert
MyDisposable target;
Assert.NotNull(wr); Assert.NotNull(wr);
Assert.NotSame(wrOriginal, 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, target);
Assert.Same(newInstance, retVal); Assert.Same(newInstance, retVal);
Assert.False(newInstance.HasBeenDisposed); Assert.False(newInstance.HasBeenDisposed);
@ -40,9 +39,8 @@ namespace Microsoft.AspNetCore.Cryptography
var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance); var retVal = WeakReferenceHelpers.GetSharedInstance(ref wr, () => newInstance);
// Assert // Assert
MyDisposable target;
Assert.NotNull(wr); Assert.NotNull(wr);
Assert.True(wr.TryGetTarget(out target)); Assert.True(wr.TryGetTarget(out var target));
Assert.Same(newInstance, target); Assert.Same(newInstance, target);
Assert.Same(newInstance, retVal); Assert.Same(newInstance, retVal);
Assert.False(newInstance.HasBeenDisposed); Assert.False(newInstance.HasBeenDisposed);
@ -65,9 +63,8 @@ namespace Microsoft.AspNetCore.Cryptography
}); });
// Assert // Assert
MyDisposable target;
Assert.NotNull(wr); Assert.NotNull(wr);
Assert.True(wr.TryGetTarget(out target)); Assert.True(wr.TryGetTarget(out var target));
Assert.Same(instanceThatWillBeCreatedFirst, target); Assert.Same(instanceThatWillBeCreatedFirst, target);
Assert.Same(instanceThatWillBeCreatedFirst, retVal); Assert.Same(instanceThatWillBeCreatedFirst, retVal);
Assert.False(instanceThatWillBeCreatedFirst.HasBeenDisposed); Assert.False(instanceThatWillBeCreatedFirst.HasBeenDisposed);

View File

@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.DataProtection
{ {
mockProtector.Object.Protect("Hello\ud800"); mockProtector.Object.Protect("Hello\ud800");
}); });
Assert.IsAssignableFrom(typeof(EncoderFallbackException), ex.InnerException); Assert.IsAssignableFrom<EncoderFallbackException>(ex.InnerException);
} }
[Fact] [Fact]
@ -293,7 +293,7 @@ namespace Microsoft.AspNetCore.DataProtection
{ {
mockProtector.Object.Unprotect("AQIDBAU"); mockProtector.Object.Unprotect("AQIDBAU");
}); });
Assert.IsAssignableFrom(typeof(DecoderFallbackException), ex.InnerException); Assert.IsAssignableFrom<DecoderFallbackException>(ex.InnerException);
} }
[Fact] [Fact]

View File

@ -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")); mockDataProtector.Setup(o => o.Unprotect(new byte[] { 0x01, 0x02 }, out controlExpiration)).Returns(Encoding.UTF8.GetBytes("this is plaintext"));
// Act // Act
DateTimeOffset testExpiration; string unprotectedPayload = mockDataProtector.Object.Unprotect(SampleEncodedString, out var testExpiration);
string unprotectedPayload = mockDataProtector.Object.Unprotect(SampleEncodedString, out testExpiration);
// Assert // Assert
Assert.Equal("this is plaintext", unprotectedPayload); Assert.Equal("this is plaintext", unprotectedPayload);

View File

@ -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 // Step 3: validate that there's now a single key in the directory and that it's not protected
var allFiles = directory.GetFiles(); var allFiles = directory.GetFiles();
Assert.Equal(1, allFiles.Length); Assert.Single(allFiles);
Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase);
string fileText = File.ReadAllText(allFiles[0].FullName); string fileText = File.ReadAllText(allFiles[0].FullName);
Assert.Contains("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); 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 // Step 3: validate that there's now a single key in the directory and that it's protected with DPAPI
var allFiles = directory.GetFiles(); var allFiles = directory.GetFiles();
Assert.Equal(1, allFiles.Length); Assert.Single(allFiles);
Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase);
string fileText = File.ReadAllText(allFiles[0].FullName); string fileText = File.ReadAllText(allFiles[0].FullName);
Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); 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 // 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(); var allFiles = directory.GetFiles();
Assert.Equal(1, allFiles.Length); Assert.Single(allFiles);
Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase); Assert.StartsWith("key-", allFiles[0].Name, StringComparison.OrdinalIgnoreCase);
string fileText = File.ReadAllText(allFiles[0].FullName); string fileText = File.ReadAllText(allFiles[0].FullName);
Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal); Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal);

View File

@ -78,8 +78,7 @@ namespace Microsoft.AspNetCore.DataProtection
var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object);
// Act // Act
DateTimeOffset actualExpiration; var retVal = timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out var actualExpiration);
var retVal = timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out actualExpiration);
// Assert // Assert
Assert.Equal(expectedExpiration, actualExpiration); Assert.Equal(expectedExpiration, actualExpiration);
@ -103,8 +102,8 @@ namespace Microsoft.AspNetCore.DataProtection
var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object);
// Act & assert // Act & assert
DateTimeOffset unused; var ex = Assert.Throws<CryptographicException>(()
var ex = Assert.Throws<CryptographicException>(() => timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out unused)); => timeLimitedProtector.UnprotectCore(new byte[] { 0x10, 0x11 }, now, out var _));
// Assert // Assert
Assert.Equal(Resources.FormatTimeLimitedDataProtector_PayloadExpired(expectedExpiration), ex.Message); Assert.Equal(Resources.FormatTimeLimitedDataProtector_PayloadExpired(expectedExpiration), ex.Message);
@ -124,8 +123,8 @@ namespace Microsoft.AspNetCore.DataProtection
var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object);
// Act & assert // Act & assert
DateTimeOffset unused; var ex = Assert.Throws<CryptographicException>(()
var ex = Assert.Throws<CryptographicException>(() => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out unused)); => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out var _));
// Assert // Assert
Assert.Equal(Resources.TimeLimitedDataProtector_PayloadInvalid, ex.Message); Assert.Equal(Resources.TimeLimitedDataProtector_PayloadInvalid, ex.Message);
@ -141,8 +140,8 @@ namespace Microsoft.AspNetCore.DataProtection
var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object); var timeLimitedProtector = new TimeLimitedDataProtector(mockInnerProtector.Object);
// Act & assert // Act & assert
DateTimeOffset unused; var ex = Assert.Throws<CryptographicException>(()
var ex = Assert.Throws<CryptographicException>(() => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out unused)); => timeLimitedProtector.Unprotect(new byte[] { 0x10, 0x11 }, out var _));
// Assert // Assert
Assert.Equal(Resources.CryptCommon_GenericError, ex.Message); 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); byte[] timeLimitedProtectedPayload = timeLimitedProtector.Protect(new byte[] { 0x11, 0x22, 0x33, 0x44 }, expectedExpiration);
// Assert // Assert
DateTimeOffset actualExpiration; Assert.Equal(
Assert.Equal(new byte[] { 0x11, 0x22, 0x33, 0x44 }, timeLimitedProtector.UnprotectCore(timeLimitedProtectedPayload, StringToDateTime("2010-01-01 00:00:00Z"), out actualExpiration)); new byte[] { 0x11, 0x22, 0x33, 0x44 },
timeLimitedProtector.UnprotectCore(timeLimitedProtectedPayload, StringToDateTime("2010-01-01 00:00:00Z"), out var actualExpiration));
Assert.Equal(expectedExpiration, actualExpiration); Assert.Equal(expectedExpiration, actualExpiration);
// the two providers shouldn't be able to talk to one another (due to the purpose chaining) // the two providers shouldn't be able to talk to one another (due to the purpose chaining)

View File

@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
// Act & assert // Act & assert
var ex = ExceptionAssert2.ThrowsCryptographicException(() => protector.Protect(new byte[0])); var ex = ExceptionAssert2.ThrowsCryptographicException(() => protector.Protect(new byte[0]));
Assert.IsAssignableFrom(typeof(MockException), ex.InnerException); Assert.IsAssignableFrom<MockException>(ex.InnerException);
} }
[Fact] [Fact]
@ -291,11 +291,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
newPurpose: "purpose"); newPurpose: "purpose");
// Act // Act
bool requiresMigration, wasRevoked;
byte[] retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, byte[] retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData,
ignoreRevocationErrors: true, ignoreRevocationErrors: true,
requiresMigration: out requiresMigration, requiresMigration: out var requiresMigration,
wasRevoked: out wasRevoked); wasRevoked: out var wasRevoked);
// Assert // Assert
Assert.Equal(expectedPlaintext, retVal); Assert.Equal(expectedPlaintext, retVal);
@ -342,11 +341,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
Assert.Equal(expectedPlaintext, retVal); Assert.Equal(expectedPlaintext, retVal);
// Act & assert - IPersistedDataProtector // Act & assert - IPersistedDataProtector
bool requiresMigration, wasRevoked;
retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData,
ignoreRevocationErrors: false, ignoreRevocationErrors: false,
requiresMigration: out requiresMigration, requiresMigration: out var requiresMigration,
wasRevoked: out wasRevoked); wasRevoked: out var wasRevoked);
Assert.Equal(expectedPlaintext, retVal); Assert.Equal(expectedPlaintext, retVal);
Assert.False(requiresMigration); Assert.False(requiresMigration);
Assert.False(wasRevoked); Assert.False(wasRevoked);
@ -393,11 +391,10 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
Assert.Equal(expectedPlaintext, retVal); Assert.Equal(expectedPlaintext, retVal);
// Act & assert - IPersistedDataProtector // Act & assert - IPersistedDataProtector
bool requiresMigration, wasRevoked;
retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData, retVal = ((IPersistedDataProtector)protector).DangerousUnprotect(protectedData,
ignoreRevocationErrors: false, ignoreRevocationErrors: false,
requiresMigration: out requiresMigration, requiresMigration: out var requiresMigration,
wasRevoked: out wasRevoked); wasRevoked: out var wasRevoked);
Assert.Equal(expectedPlaintext, retVal); Assert.Equal(expectedPlaintext, retVal);
Assert.True(requiresMigration); Assert.True(requiresMigration);
Assert.False(wasRevoked); Assert.False(wasRevoked);

View File

@ -57,9 +57,8 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
var keyRing = new KeyRing(key3, new[] { key1, key2 }); var keyRing = new KeyRing(key3, new[] { key1, key2 });
// Assert // Assert
bool unused;
Assert.Equal(key3.KeyId, keyRing.DefaultKeyId); 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] [Fact]
@ -77,9 +76,8 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
var keyRing = new KeyRing(key2, new[] { key1, key2 }); var keyRing = new KeyRing(key2, new[] { key1, key2 });
// Assert // Assert
bool isRevoked;
Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); 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.True(isRevoked);
Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled);
Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked));

View File

@ -476,7 +476,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray(); var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray();
// Assert // Assert
Assert.Equal(1, keys.Length); Assert.Single(keys);
Assert.Equal(new Guid("09712588-ba68-438a-a5ee-fe842b3453b2"), keys[0].KeyId); Assert.Equal(new Guid("09712588-ba68-438a-a5ee-fe842b3453b2"), keys[0].KeyId);
Assert.Same(expectedDescriptor, keys[0].Descriptor); Assert.Same(expectedDescriptor, keys[0].Descriptor);
} }
@ -515,7 +515,7 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement
var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray(); var keys = RunGetAllKeysCore(xml, mockActivator.Object).ToArray();
// Assert // Assert
Assert.Equal(1, keys.Length); Assert.Single(keys);
Assert.Equal(new Guid("49c0cda9-0232-4d8c-a541-de20cc5a73d6"), keys[0].KeyId); Assert.Equal(new Guid("49c0cda9-0232-4d8c-a541-de20cc5a73d6"), keys[0].KeyId);
Assert.Same(expectedDescriptor, keys[0].Descriptor); Assert.Same(expectedDescriptor, keys[0].Descriptor);
} }

View File

@ -55,8 +55,8 @@ namespace Microsoft.AspNetCore.DataProtection
// Assert // Assert
var actualKeyEscrowSinks = context.KeyEscrowSinks.ToArray(); var actualKeyEscrowSinks = context.KeyEscrowSinks.ToArray();
Assert.Equal(2, actualKeyEscrowSinks.Length); Assert.Equal(2, actualKeyEscrowSinks.Length);
Assert.IsType(typeof(MyKeyEscrowSink1), actualKeyEscrowSinks[0]); Assert.IsType<MyKeyEscrowSink1>(actualKeyEscrowSinks[0]);
Assert.IsType(typeof(MyKeyEscrowSink2), actualKeyEscrowSinks[1]); Assert.IsType<MyKeyEscrowSink2>(actualKeyEscrowSinks[1]);
} }
[ConditionalFact] [ConditionalFact]