From 27bccbdda5fc583818ad373b333d7d34b141912b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 4 Nov 2024 12:12:47 +0000 Subject: [PATCH 01/18] Update .NET SDK Update .NET SDK to version 10.0.100-alpha.1.24553.6. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: github-actions[bot] --- global.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global.json b/global.json index ef86f96c32d9..375258806973 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "10.0.100-alpha.1.24510.13" + "version": "10.0.100-alpha.1.24553.6" }, "tools": { - "dotnet": "10.0.100-alpha.1.24510.13", + "dotnet": "10.0.100-alpha.1.24553.6", "runtimes": { "dotnet/x86": [ "$(MicrosoftInternalRuntimeAspNetCoreTransportVersion)" From 395373d5307c5cbd1d82ac9e5f5a5969b8643182 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 09:48:22 -0800 Subject: [PATCH 02/18] Fix build errors --- .../Cng/CbcAuthenticatedEncryptorTests.cs | 2 +- .../Cng/GcmAuthenticatedEncryptorTests.cs | 4 +- .../KeyRingBasedDataProtectorTests.cs | 24 ++--- .../ManagedAuthenticatedEncryptorTests.cs | 2 +- .../test/CacheControlHeaderValueTest.cs | 4 +- .../test/ContentDispositionHeaderValueTest.cs | 102 +++++++++--------- .../test/ContentRangeHeaderValueTest.cs | 12 +-- .../Headers/test/CookieHeaderValueTest.cs | 12 +-- .../Headers/test/EntityTagHeaderValueTest.cs | 4 +- src/Http/Headers/test/HeaderUtilitiesTest.cs | 6 +- .../Headers/test/MediaTypeHeaderValueTest.cs | 28 ++--- .../Headers/test/NameValueHeaderValueTest.cs | 26 ++--- src/Http/Headers/test/RangeHeaderValueTest.cs | 2 +- .../Headers/test/SetCookieHeaderValueTest.cs | 12 +-- .../test/StringWithQualityHeaderValueTest.cs | 4 +- .../test/CookieBuilderTests.cs | 4 +- .../WebUtilities/test/QueryHelpersTests.cs | 6 +- .../test/CookieTempDataProviderTest.cs | 4 +- .../TempDataInCookiesTest.cs | 14 +-- .../OpenIdConnectChallengeTests.cs | 8 +- .../CookiePolicy/test/CookieConsentTests.cs | 46 ++++---- .../CookiePolicy/test/CookiePolicyTests.cs | 26 ++--- .../Core/test/Http2/Http2HPackEncoderTests.cs | 2 +- 23 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs index 549fdc217463..9285ba471d78 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs @@ -29,7 +29,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [ConditionalFact] diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs index 6c3cb9f51d12..90091ac3c3cc 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs @@ -26,7 +26,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [ConditionalFact] @@ -100,6 +100,6 @@ public void Encrypt_KnownKey() // | 00 00 00 00 (postBuffer) string retValAsString = Convert.ToBase64String(retVal); - Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA", retValAsString); + Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA".AsSpan(), retValAsString); } } diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs index f955c9e27f41..a1716d03a773 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs @@ -45,8 +45,8 @@ public void Protect_EncryptsToDefaultProtector_MultiplePurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -83,8 +83,8 @@ public void Protect_EncryptsToDefaultProtector_SinglePurpose() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -423,8 +423,8 @@ public void Unprotect_KeyRevoked_RevocationAllowed_ReturnsOriginalData_SetsRevok .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -470,8 +470,8 @@ public void Unprotect_IsAlsoDefaultKey_Success_NoMigrationRequired() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -519,8 +519,8 @@ public void Unprotect_IsNotDefaultKey_Success_RequiresMigration() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -594,8 +594,8 @@ public void CreateProtector_ChainsPurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs index b74f7102b731..ffb742e4ca5a 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs @@ -25,7 +25,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [Fact] diff --git a/src/Http/Headers/test/CacheControlHeaderValueTest.cs b/src/Http/Headers/test/CacheControlHeaderValueTest.cs index a081d5b6a2c6..8887a0ed1324 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter() Assert.Throws(() => cacheControl.NoCacheHeaders.Add("invalid PLACEHOLDER")); cacheControl.NoCacheHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.NoCacheHeaders); - Assert.Equal("PLACEHOLDER", cacheControl.NoCacheHeaders.First()); + Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.NoCacheHeaders.First()); Assert.NotNull(cacheControl.PrivateHeaders); Assert.Throws(() => cacheControl.PrivateHeaders.Add(null)); Assert.Throws(() => cacheControl.PrivateHeaders.Add("invalid PLACEHOLDER")); cacheControl.PrivateHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.PrivateHeaders); - Assert.Equal("PLACEHOLDER", cacheControl.PrivateHeaders.First()); + Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.PrivateHeaders.First()); // NameValueHeaderValue collection property Assert.NotNull(cacheControl.Extensions); diff --git a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs index 405d693f9cc0..ea56680307c4 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -42,7 +42,7 @@ public void Ctor_ContentDispositionInvalidFormat_ThrowFormatException() public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline", contentDisposition.DispositionType); + Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); Assert.Empty(contentDisposition.Parameters); Assert.Null(contentDisposition.Name.Value); Assert.Null(contentDisposition.FileName.Value); @@ -63,10 +63,10 @@ public void Parameters_AddNull_Throw() public void ContentDisposition_SetAndGetContentDisposition_MatchExpectations() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline", contentDisposition.DispositionType); + Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); contentDisposition.DispositionType = "attachment"; - Assert.Equal("attachment", contentDisposition.DispositionType); + Assert.Equal("attachment".AsSpan(), contentDisposition.DispositionType); } [Fact] @@ -74,9 +74,9 @@ public void Name_SetNameAndValidateObject_ParametersEntryForNameAdded() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.Name = "myname"; - Assert.Equal("myname", contentDisposition.Name); + Assert.Equal("myname".AsSpan(), contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("name", contentDisposition.Parameters.First().Name); + Assert.Equal("name".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Name = null; Assert.Null(contentDisposition.Name.Value); @@ -93,12 +93,12 @@ public void Name_AddNameParameterThenUseProperty_ParametersEntryIsOverwritten() NameValueHeaderValue name = new NameValueHeaderValue("NAME", "old_name"); contentDisposition.Parameters.Add(name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME", contentDisposition.Parameters.First().Name); + Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Name = "new_name"; - Assert.Equal("new_name", contentDisposition.Name); + Assert.Equal("new_name".AsSpan(), contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME", contentDisposition.Parameters.First().Name); + Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(name); Assert.Null(contentDisposition.Name.Value); @@ -113,12 +113,12 @@ public void FileName_AddNameParameterThenUseProperty_ParametersEntryIsOverwritte var fileName = new NameValueHeaderValue("FILENAME", "old_name"); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name", contentDisposition.FileName); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -130,10 +130,10 @@ public void FileName_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "FileÃName.bat"; - Assert.Equal("FileÃName.bat", contentDisposition.FileName); + Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); + Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -145,10 +145,10 @@ public void FileName_NeedsEncodingBecauseOfNewLine_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "File\nName.bat"; - Assert.Equal("File\nName.bat", contentDisposition.FileName); + Assert.Equal("File\nName.bat".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"", contentDisposition.Parameters.First().Value); + Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -163,14 +163,14 @@ public void FileName_UnknownOrBadEncoding_PropertyFails() var fileName = new NameValueHeaderValue("FILENAME", "\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\""); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); - Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=", contentDisposition.FileName); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=".AsSpan(), contentDisposition.FileName); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name", contentDisposition.FileName); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -185,14 +185,14 @@ public void FileNameStar_AddNameParameterThenUseProperty_ParametersEntryIsOverwr var fileNameStar = new NameValueHeaderValue("FILENAME*", "old_name"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name", contentDisposition.FileNameStar); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'new_name", contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'new_name".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -204,10 +204,10 @@ public void FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "FileÃName.bat"; - Assert.Equal("FileÃName.bat", contentDisposition.FileNameStar); + Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename*", contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'File%C3%83Name.bat", contentDisposition.Parameters.First().Value); + Assert.Equal("filename*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'File%C3%83Name.bat".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileNameStar.Value); @@ -218,7 +218,7 @@ public void NonValidAscii_WhenNeedsEncoding_UsesHex() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "a\u0080b"; - Assert.Equal($"UTF-8\'\'a%C2%80b", contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. + Assert.Equal($"UTF-8\'\'a%C2%80b".AsSpan(), contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. } [Fact] @@ -226,7 +226,7 @@ public void LongValidAscii_FullyProcessedWithout() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = new string('a', 400); // 400 is larger to the max stackallow size - Assert.Equal($"UTF-8\'\'{new string('a', 400)}", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'{new string('a', 400)}".AsSpan(), contentDisposition.Parameters.First().Value); } [Fact] @@ -250,11 +250,11 @@ public void FileNameStar_WhenNeedsEncoding_UsesHex() || b >= 0x7F) { var hexC = Convert.ToHexString([b]); - Assert.Equal($"UTF-8\'\'a%{hexC}b", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a%{hexC}b".AsSpan(), contentDisposition.Parameters.First().Value); } else { - Assert.Equal($"UTF-8\'\'a{(char)b}b", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a{(char)b}b".AsSpan(), contentDisposition.Parameters.First().Value); } contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); } @@ -269,14 +269,14 @@ public void FileNameStar_UnknownOrBadEncoding_PropertyFails() var fileNameStar = new NameValueHeaderValue("FILENAME*", "utf-99'lang'File%CZName.bat"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); - Assert.Equal("utf-99'lang'File%CZName.bat", contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("utf-99'lang'File%CZName.bat".AsSpan(), contentDisposition.Parameters.First().Value); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name", contentDisposition.FileNameStar); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -294,8 +294,8 @@ public void SetHttpFileName_ShouldSanitizeFileNameWhereNeeded(string httpFileNam { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.SetHttpFileName(httpFileName); - Assert.Equal(expectedFileName, contentDisposition.FileName); - Assert.Equal(httpFileName, contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding + Assert.Equal(expectedFileName.AsSpan(), contentDisposition.FileName); + Assert.Equal(httpFileName.AsSpan(), contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding } [Fact] @@ -310,7 +310,7 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() var dateParameter = new NameValueHeaderValue("Creation-DATE", validDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); + Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Equal(validDate, contentDisposition.CreationDate); @@ -318,8 +318,8 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() contentDisposition.CreationDate = newDate; Assert.Equal(newDate, contentDisposition.CreationDate); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); - Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"", contentDisposition.Parameters.First().Value); + Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(dateParameter); Assert.Null(contentDisposition.CreationDate); @@ -336,7 +336,7 @@ public void Dates_InvalidDates_PropertyFails() var dateParameter = new NameValueHeaderValue("read-DATE", invalidDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("read-DATE", contentDisposition.Parameters.First().Name); + Assert.Equal("read-DATE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.ReadDate); @@ -354,13 +354,13 @@ public void Size_AddSizeParameterThenUseProperty_ParametersEntryIsOverwritten() var sizeParameter = new NameValueHeaderValue("SIZE", "279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Equal(279172874239, contentDisposition.Size); contentDisposition.Size = 279172874240; Assert.Equal(279172874240, contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -375,14 +375,14 @@ public void Size_InvalidSizes_PropertyFails() var sizeParameter = new NameValueHeaderValue("SIZE", "-279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.Size); // Negatives not allowed Assert.Throws(() => contentDisposition.Size = -279172874240); Assert.Null(contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -645,8 +645,8 @@ public void HeaderNamesWithQuotes_ExpectNamesToNotHaveQuotes() var result = ContentDispositionHeaderValue.Parse(contentDispositionLine); - Assert.Equal(expectedName, result.Name); - Assert.Equal(expectedFileName, result.FileName); + Assert.Equal(expectedName.AsSpan(), result.Name); + Assert.Equal(expectedFileName.AsSpan(), result.FileName); } [Fact] @@ -655,9 +655,9 @@ public void FileNameWithSurrogatePairs_EncodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName("File 🤩 name.txt"); - Assert.Equal("File __ name.txt", contentDisposition.FileName); + Assert.Equal("File __ name.txt".AsSpan(), contentDisposition.FileName); Assert.Equal(2, contentDisposition.Parameters.Count); - Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt", contentDisposition.Parameters[1].Value); + Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt".AsSpan(), contentDisposition.Parameters[1].Value); } public class ContentDispositionValue diff --git a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs index af2a5fa8bbad..9036835059fd 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -18,7 +18,7 @@ public void Ctor_LengthOnlyOverloadValidValues_ValuesCorrectlySet() Assert.False(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Null(range.From); Assert.Null(range.To); Assert.Equal(5, range.Length); @@ -39,7 +39,7 @@ public void Ctor_FromAndToOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.False(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Null(range.Length); @@ -63,7 +63,7 @@ public void Ctor_FromToAndLengthOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Equal(2, range.Length); @@ -74,7 +74,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new ContentRangeHeaderValue(0); range.Unit = "myunit"; - Assert.Equal("myunit", range.Unit); + Assert.Equal("myunit".AsSpan(), range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); @@ -156,7 +156,7 @@ public void Parse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. var result = ContentRangeHeaderValue.Parse("bytes */*"); - Assert.Equal("bytes", result.Unit); + Assert.Equal("bytes".AsSpan(), result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); @@ -187,7 +187,7 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result)); - Assert.Equal("bytes", result.Unit); + Assert.Equal("bytes".AsSpan(), result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); diff --git a/src/Http/Headers/test/CookieHeaderValueTest.cs b/src/Http/Headers/test/CookieHeaderValueTest.cs index 02e00068f878..b212aae88e00 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -172,8 +172,8 @@ public void CookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void CookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new CookieHeaderValue("cookie"); - Assert.Equal("cookie", header.Name); - Assert.Equal(string.Empty, header.Value); + Assert.Equal("cookie".AsSpan(), header.Name); + Assert.Equal(string.Empty.AsSpan(), header.Value); } [Theory] @@ -183,18 +183,18 @@ public void CookieHeaderValue_Ctor1_InitializesCorrectly() public void CookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new CookieHeaderValue(name, value); - Assert.Equal(name, header.Name); - Assert.Equal(value, header.Value); + Assert.Equal(name.AsSpan(), header.Name); + Assert.Equal(value.AsSpan(), header.Value); } [Fact] public void CookieHeaderValue_Value() { var cookie = new CookieHeaderValue("name"); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1", cookie.Value); + Assert.Equal("value1".AsSpan(), cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/EntityTagHeaderValueTest.cs b/src/Http/Headers/test/EntityTagHeaderValueTest.cs index 48086ab29613..69f4e1bcac6e 100644 --- a/src/Http/Headers/test/EntityTagHeaderValueTest.cs +++ b/src/Http/Headers/test/EntityTagHeaderValueTest.cs @@ -32,7 +32,7 @@ public void Ctor_ETagInvalidFormat_ThrowFormatException() public void Ctor_ETagValidFormat_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"tag\""); - Assert.Equal("\"tag\"", etag.Tag); + Assert.Equal("\"tag\"", etag.Tag.ToString()); Assert.False(etag.IsWeak, "IsWeak"); } @@ -40,7 +40,7 @@ public void Ctor_ETagValidFormat_SuccessfullyCreated() public void Ctor_ETagValidFormatAndIsWeak_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"e tag\"", true); - Assert.Equal("\"e tag\"", etag.Tag); + Assert.Equal("\"e tag\"", etag.Tag.ToString()); Assert.True(etag.IsWeak, "IsWeak"); } diff --git a/src/Http/Headers/test/HeaderUtilitiesTest.cs b/src/Http/Headers/test/HeaderUtilitiesTest.cs index 9ce61faec7f9..33dfe95fb3f1 100644 --- a/src/Http/Headers/test/HeaderUtilitiesTest.cs +++ b/src/Http/Headers/test/HeaderUtilitiesTest.cs @@ -231,7 +231,7 @@ public void RemoveQuotes_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.RemoveQuotes(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] [InlineData("\"hello\"", true)] @@ -258,7 +258,7 @@ public void UnescapeAsQuotedString_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.UnescapeAsQuotedString(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -275,7 +275,7 @@ public void SetAndEscapeValue_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.EscapeAsQuotedString(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] diff --git a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs index 5af91d202643..67191c746936 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -102,7 +102,7 @@ public void MatchesAllSubTypesWithoutSuffix_ReturnsExpectedResult(string value, public void Ctor_MediaTypeValidFormat_SuccessfullyCreated() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain", mediaType.MediaType); + Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); Assert.Empty(mediaType.Parameters); Assert.Null(mediaType.Charset.Value); } @@ -112,7 +112,7 @@ public void Ctor_AddNameAndQuality_QualityParameterAdded() { var mediaType = new MediaTypeHeaderValue("application/xml", 0.08); Assert.Equal(0.08, mediaType.Quality); - Assert.Equal("application/xml", mediaType.MediaType); + Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); Assert.Single(mediaType.Parameters); } @@ -221,10 +221,10 @@ public void CopyFromReadOnly_WithParameters_CopiedAsNonReadOnly() public void MediaType_SetAndGetMediaType_MatchExpectations() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain", mediaType.MediaType); + Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); mediaType.MediaType = "application/xml"; - Assert.Equal("application/xml", mediaType.MediaType); + Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); } [Fact] @@ -232,9 +232,9 @@ public void Charset_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() { var mediaType = new MediaTypeHeaderValue("text/plain"); mediaType.Charset = "mycharset"; - Assert.Equal("mycharset", mediaType.Charset); + Assert.Equal("mycharset".AsSpan(), mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("charset", mediaType.Parameters.First().Name); + Assert.Equal("charset".AsSpan(), mediaType.Parameters.First().Name); mediaType.Charset = null; Assert.Null(mediaType.Charset.Value); @@ -251,12 +251,12 @@ public void Charset_AddCharsetParameterThenUseProperty_ParametersEntryIsOverwrit var charset = new NameValueHeaderValue("CHARSET", "old_charset"); mediaType.Parameters.Add(charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET", mediaType.Parameters.First().Name); + Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); mediaType.Charset = "new_charset"; - Assert.Equal("new_charset", mediaType.Charset); + Assert.Equal("new_charset".AsSpan(), mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET", mediaType.Parameters.First().Name); + Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); mediaType.Parameters.Remove(charset); Assert.Null(mediaType.Charset.Value); @@ -269,8 +269,8 @@ public void Quality_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() mediaType.Quality = 0.563156454; Assert.Equal(0.563, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); - Assert.Equal("0.563", mediaType.Parameters.First().Value); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("0.563".AsSpan(), mediaType.Parameters.First().Value); mediaType.Quality = null; Assert.Null(mediaType.Quality); @@ -286,13 +286,13 @@ public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwrit var quality = new NameValueHeaderValue("q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); mediaType.Quality = 0.9; Assert.Equal(0.9, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); mediaType.Parameters.Remove(quality); Assert.Null(mediaType.Quality); @@ -306,7 +306,7 @@ public void Quality_AddQualityParameterUpperCase_CaseInsensitiveComparison() var quality = new NameValueHeaderValue("Q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("Q", mediaType.Parameters.First().Name); + Assert.Equal("Q".AsSpan(), mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); } diff --git a/src/Http/Headers/test/NameValueHeaderValueTest.cs b/src/Http/Headers/test/NameValueHeaderValueTest.cs index 003ee695c7f6..2031b6a77391 100644 --- a/src/Http/Headers/test/NameValueHeaderValueTest.cs +++ b/src/Http/Headers/test/NameValueHeaderValueTest.cs @@ -29,7 +29,7 @@ public void Ctor_NameInvalidFormat_ThrowFormatException() public void Ctor_NameValidFormat_SuccessfullyCreated() { var nameValue = new NameValueHeaderValue("text", null); - Assert.Equal("text", nameValue.Name); + Assert.Equal("text".AsSpan(), nameValue.Name); } [Fact] @@ -66,7 +66,7 @@ public void Copy_NameOnly_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); Assert.Null(pair1.Value.Value); } @@ -84,7 +84,7 @@ public void CopyAsReadOnly_NameOnly_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); Assert.Null(pair1.Value.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -100,8 +100,8 @@ public void Copy_NameAndValue_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("value".AsSpan(), pair1.Value); } [Fact] @@ -117,8 +117,8 @@ public void CopyAsReadOnly_NameAndValue_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("value".AsSpan(), pair1.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -134,8 +134,8 @@ public void CopyFromReadOnly_NameAndValue_CopiedAsNonReadOnly() // Change one value and verify the other is unchanged. pair2.Value = "othervalue"; - Assert.Equal("othervalue", pair2.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair2.Value); + Assert.Equal("value".AsSpan(), pair1.Value); } [Fact] @@ -581,7 +581,7 @@ public void GetUnescapedValue_ReturnsExpectedValue(string input, string expected var actual = header.GetUnescapedValue(); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -602,7 +602,7 @@ public void SetAndEscapeValue_ReturnsExpectedValue(string input, string expected var actual = header.Value; - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -628,7 +628,7 @@ public void GetAndSetEncodeValueRoundTrip_ReturnsExpectedValue(string input) var actual = header.Value; - Assert.Equal(input, actual); + Assert.Equal(input.AsSpan(), actual); } [Theory] @@ -673,7 +673,7 @@ private void CheckInvalidTryParse(string? input) private static void CheckValue(string? value) { var nameValue = new NameValueHeaderValue("text", value); - Assert.Equal(value, nameValue.Value); + Assert.Equal(value.AsSpan(), nameValue.Value); } private static void AssertFormatException(string name, string? value) diff --git a/src/Http/Headers/test/RangeHeaderValueTest.cs b/src/Http/Headers/test/RangeHeaderValueTest.cs index 624c07dafbd1..101759609c02 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -16,7 +16,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new RangeHeaderValue(); range.Unit = "myunit"; - Assert.Equal("myunit", range.Unit); + Assert.Equal("myunit".AsSpan(), range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); diff --git a/src/Http/Headers/test/SetCookieHeaderValueTest.cs b/src/Http/Headers/test/SetCookieHeaderValueTest.cs index 05c6684feef9..7e53fad5e75c 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -318,8 +318,8 @@ public void SetCookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new SetCookieHeaderValue("cookie"); - Assert.Equal("cookie", header.Name); - Assert.Equal(string.Empty, header.Value); + Assert.Equal("cookie".AsSpan(), header.Name); + Assert.Equal(string.Empty.AsSpan(), header.Value); } [Theory] @@ -329,18 +329,18 @@ public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() public void SetCookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new SetCookieHeaderValue(name, value); - Assert.Equal(name, header.Name); - Assert.Equal(value, header.Value); + Assert.Equal(name.AsSpan(), header.Name); + Assert.Equal(value.AsSpan(), header.Value); } [Fact] public void SetCookieHeaderValue_Value() { var cookie = new SetCookieHeaderValue("name"); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1", cookie.Value); + Assert.Equal("value1".AsSpan(), cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs index 661114afbcfa..5a786b6b70a8 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -9,7 +9,7 @@ public class StringWithQualityHeaderValueTest public void Ctor_StringOnlyOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token"); - Assert.Equal("token", value.Value); + Assert.Equal("token".AsSpan(), value.Value); Assert.Null(value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null)); @@ -21,7 +21,7 @@ public void Ctor_StringOnlyOverload_MatchExpectation() public void Ctor_StringWithQualityOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token", 0.5); - Assert.Equal("token", value.Value); + Assert.Equal("token".AsSpan(), value.Value); Assert.Equal(0.5, value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null, 0.1)); diff --git a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs index ce171a6ec527..ebdb2fe0ad7d 100644 --- a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs +++ b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs @@ -64,8 +64,8 @@ public void CookieBuilder_Extensions_Added() Assert.Contains("key=value", options.Extensions); var cookie = options.CreateCookieHeader("name", "value"); - Assert.Equal("name", cookie.Name); - Assert.Equal("value", cookie.Value); + Assert.Equal("name".AsSpan(), cookie.Name); + Assert.Equal("value".AsSpan(), cookie.Value); Assert.Equal(2, cookie.Extensions.Count); Assert.Contains("simple", cookie.Extensions); Assert.Contains("key=value", cookie.Extensions); diff --git a/src/Http/WebUtilities/test/QueryHelpersTests.cs b/src/Http/WebUtilities/test/QueryHelpersTests.cs index 8707fe2411be..6f040e4146e4 100644 --- a/src/Http/WebUtilities/test/QueryHelpersTests.cs +++ b/src/Http/WebUtilities/test/QueryHelpersTests.cs @@ -30,7 +30,7 @@ public void ParseQueryWithDuplicateKeysGroups() { var collection = QueryHelpers.ParseQuery("?key1=valueA&key2=valueB&key1=valueC"); Assert.Equal(2, collection.Count); - Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"]); + Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"].ToArray()); Assert.Equal("valueB", collection["key2"].FirstOrDefault()); } @@ -48,7 +48,7 @@ public void ParseQueryWithEmptyKeyWorks() { var collection = QueryHelpers.ParseQuery("?=value1&="); Assert.Single(collection); - Assert.Equal(new[] { "value1", "" }, collection[""]); + Assert.Equal(new[] { "value1", "" }, collection[""].ToArray()); } [Fact] @@ -88,7 +88,7 @@ public void ParseQueryWithEncodedKeyEncodedValuesWorks() { var collection = QueryHelpers.ParseQuery("?fields+%5BtodoItems%5D=%5B+1+%5D&fields+%5BtodoItems%5D=%5B+2+%5D"); Assert.Single(collection); - Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"]); + Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"].ToArray()); } [Theory] diff --git a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs index b7b3e8d95612..d4861a9a527b 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs @@ -284,8 +284,8 @@ public void SaveTempData_RemovesCookie_WhenNoDataToSave() Assert.Single(responseCookies); var cookie = responseCookies.Single(); Assert.NotNull(cookie); - Assert.Equal(CookieTempDataProvider.CookieName, cookie.Name); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(CookieTempDataProvider.CookieName.AsSpan(), cookie.Name); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); Assert.NotNull(cookie.Expires); Assert.True(cookie.Expires.Value < DateTimeOffset.Now); // expired cookie } diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs index f25096cc9acc..debdf250c46e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs @@ -80,7 +80,7 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) foreach (var cookieTempDataProviderCookie in cookieTempDataProviderCookies) { Assert.NotNull(cookieTempDataProviderCookie.Value.Value); - Assert.Equal("/", cookieTempDataProviderCookie.Path); + Assert.Equal("/".AsSpan(), cookieTempDataProviderCookie.Path); Assert.Null(cookieTempDataProviderCookie.Domain.Value); Assert.False(cookieTempDataProviderCookie.Secure); } @@ -97,8 +97,8 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeader => setCookieHeader.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeaderValue); - Assert.Equal(string.Empty, setCookieHeaderValue.Value); - Assert.Equal("/", setCookieHeaderValue.Path); + Assert.Equal(string.Empty.AsSpan(), setCookieHeaderValue.Value); + Assert.Equal("/".AsSpan(), setCookieHeaderValue.Path); Assert.Null(setCookieHeaderValue.Domain.Value); Assert.NotNull(setCookieHeaderValue.Expires); Assert.True(setCookieHeaderValue.Expires < DateTimeOffset.Now); // expired cookie @@ -130,7 +130,7 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); @@ -153,8 +153,8 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal(string.Empty, setCookieHeader.Value); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal(string.Empty.AsSpan(), setCookieHeader.Value); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.NotNull(setCookieHeader.Expires); Assert.True(setCookieHeader.Expires < DateTimeOffset.Now); // expired cookie @@ -183,7 +183,7 @@ public async Task CookieTempDataProviderCookie_DoesNotSetsSecureAttributeOnCooki .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); diff --git a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs index abc76954193c..68d6e98ce124 100644 --- a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs +++ b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs @@ -441,15 +441,15 @@ public async Task ChallengeSetsNonceAndStateCookies(OpenIdConnectRedirectBehavio Assert.True(nonceCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(nonceCookie.HttpOnly); - Assert.Equal("/signin-oidc", nonceCookie.Path); - Assert.Equal("N", nonceCookie.Value); + Assert.Equal("/signin-oidc".AsSpan(), nonceCookie.Path); + Assert.Equal("N".AsSpan(), nonceCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.None, nonceCookie.SameSite); var correlationCookie = challengeCookies.Where(cookie => cookie.Name.StartsWith(".AspNetCore.Correlation.", StringComparison.Ordinal)).Single(); Assert.True(correlationCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(correlationCookie.HttpOnly); - Assert.Equal("/signin-oidc", correlationCookie.Path); + Assert.Equal("/signin-oidc".AsSpan(), correlationCookie.Path); Assert.False(StringSegment.IsNullOrEmpty(correlationCookie.Value)); Assert.Equal(Net.Http.Headers.SameSiteMode.None, correlationCookie.SameSite); @@ -847,7 +847,7 @@ public async Task Challenge_WithPushedAuthorization_Handled() var res = transaction.Response; Assert.Equal(HttpStatusCode.Redirect, res.StatusCode); - + Assert.Contains("request_uri=request_uri_from_event", res.Headers.Location.Query); Assert.Empty(mockBackchannel.PushedParameters); } diff --git a/src/Security/CookiePolicy/test/CookieConsentTests.cs b/src/Security/CookiePolicy/test/CookieConsentTests.cs index f5234ca0af2d..79905c22c9c6 100644 --- a/src/Security/CookiePolicy/test/CookieConsentTests.cs +++ b/src/Security/CookiePolicy/test/CookieConsentTests.cs @@ -217,15 +217,15 @@ public async Task GrantConsentSetsCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("yes", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("yes".AsSpan(), consentCookie.Value); Assert.True(consentCookie.Expires.HasValue); Assert.True(consentCookie.Expires.Value > DateTimeOffset.Now + TimeSpan.FromDays(364)); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); var testCookie = cookies[1]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("Value", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("Value".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); } @@ -239,8 +239,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnAppendCookie = context => { - Assert.Equal(".AspNet.Consent", context.CookieName); - Assert.Equal("yes", context.CookieValue); + Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); + Assert.Equal("yes".AsSpan(), context.CookieValue); Assert.Equal(Http.SameSiteMode.Strict, context.CookieOptions.SameSite); context.CookieName += "1"; context.CookieValue += "1"; @@ -267,8 +267,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("yes1", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("yes1".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); Assert.Contains("extension", consentCookie.Extensions); @@ -398,13 +398,13 @@ public async Task WithdrawConsentDeletesCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var testCookie = cookies[0]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("Value1", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("Value1".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); var consentCookie = cookies[1]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -418,7 +418,7 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnDeleteCookie = context => { - Assert.Equal(".AspNet.Consent", context.CookieName); + Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); context.CookieName += "1"; }; }, @@ -445,8 +445,8 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -510,8 +510,8 @@ public async Task DeleteCookieDoesNotRequireConsent() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var testCookie = cookies[0]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.NotNull(testCookie.Expires); } @@ -574,8 +574,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("yes", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("yes".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -627,8 +627,8 @@ public async Task CreateConsentCookieAppliesPolicy() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("yes1", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("yes1".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -672,8 +672,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookieWhenCookieValueIsC var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("true", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("true".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); diff --git a/src/Security/CookiePolicy/test/CookiePolicyTests.cs b/src/Security/CookiePolicy/test/CookiePolicyTests.cs index d17decb80a64..30a55a961d55 100644 --- a/src/Security/CookiePolicy/test/CookiePolicyTests.cs +++ b/src/Security/CookiePolicy/test/CookiePolicyTests.cs @@ -58,10 +58,10 @@ await RunTest("/secureAlways", transaction => { Assert.NotNull(transaction.SetCookie); - Assert.Equal("A=A; path=/; secure", transaction.SetCookie[0]); - Assert.Equal("B=B; path=/; secure", transaction.SetCookie[1]); - Assert.Equal("C=C; path=/; secure", transaction.SetCookie[2]); - Assert.Equal("D=D; path=/; secure", transaction.SetCookie[3]); + Assert.Equal("A=A; path=/; secure".AsSpan(), transaction.SetCookie[0]); + Assert.Equal("B=B; path=/; secure".AsSpan(), transaction.SetCookie[1]); + Assert.Equal("C=C; path=/; secure".AsSpan(), transaction.SetCookie[2]); + Assert.Equal("D=D; path=/; secure".AsSpan(), transaction.SetCookie[3]); })); } @@ -398,10 +398,10 @@ public async Task CookiePolicyAppliesToCookieAuth() Assert.NotNull(transaction.SetCookie); Assert.Single(transaction.SetCookie); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie", cookie.Name); + Assert.Equal("TestCookie".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("extension", cookie.Extensions); } @@ -450,25 +450,25 @@ public async Task CookiePolicyAppliesToCookieAuthChunks() Assert.Equal(3, transaction.SetCookie.Count); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie", cookie.Name); - Assert.Equal("chunks-2", cookie.Value); + Assert.Equal("TestCookie".AsSpan(), cookie.Name); + Assert.Equal("chunks-2".AsSpan(), cookie.Value); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[1]); - Assert.Equal("TestCookieC1", cookie.Name); + Assert.Equal("TestCookieC1".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[2]); - Assert.Equal("TestCookieC2", cookie.Name); + Assert.Equal("TestCookieC2".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); } diff --git a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs index 2edf4628129e..23a4ca0e3fd3 100644 --- a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs +++ b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs @@ -486,7 +486,7 @@ public void EncodesHeadersInSinglePayloadWhenSpaceAvailable(KeyValuePair(payload, 0, length)); + Assert.Equal(expectedPayload, new ArraySegment(payload, 0, length).ToArray()); } [Theory] From a488cac1efb5aa1c1e179bf8718d385b35f3d440 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 11:07:55 -0800 Subject: [PATCH 03/18] Revert changes --- .../Cng/CbcAuthenticatedEncryptorTests.cs | 2 +- .../Cng/GcmAuthenticatedEncryptorTests.cs | 4 +- .../KeyRingBasedDataProtectorTests.cs | 24 ++--- .../ManagedAuthenticatedEncryptorTests.cs | 2 +- .../test/CacheControlHeaderValueTest.cs | 4 +- .../test/ContentDispositionHeaderValueTest.cs | 102 +++++++++--------- .../test/ContentRangeHeaderValueTest.cs | 12 +-- .../Headers/test/CookieHeaderValueTest.cs | 12 +-- .../Headers/test/EntityTagHeaderValueTest.cs | 4 +- src/Http/Headers/test/HeaderUtilitiesTest.cs | 6 +- .../Headers/test/MediaTypeHeaderValueTest.cs | 28 ++--- .../Headers/test/NameValueHeaderValueTest.cs | 26 ++--- src/Http/Headers/test/RangeHeaderValueTest.cs | 2 +- .../Headers/test/SetCookieHeaderValueTest.cs | 12 +-- .../test/StringWithQualityHeaderValueTest.cs | 4 +- .../test/CookieBuilderTests.cs | 4 +- .../WebUtilities/test/QueryHelpersTests.cs | 6 +- .../test/CookieTempDataProviderTest.cs | 4 +- .../TempDataInCookiesTest.cs | 14 +-- .../OpenIdConnectChallengeTests.cs | 8 +- .../CookiePolicy/test/CookieConsentTests.cs | 46 ++++---- .../CookiePolicy/test/CookiePolicyTests.cs | 26 ++--- .../Core/test/Http2/Http2HPackEncoderTests.cs | 2 +- 23 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs index 9285ba471d78..549fdc217463 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs @@ -29,7 +29,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext, decipheredtext); } [ConditionalFact] diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs index 90091ac3c3cc..6c3cb9f51d12 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs @@ -26,7 +26,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext, decipheredtext); } [ConditionalFact] @@ -100,6 +100,6 @@ public void Encrypt_KnownKey() // | 00 00 00 00 (postBuffer) string retValAsString = Convert.ToBase64String(retVal); - Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA".AsSpan(), retValAsString); + Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA", retValAsString); } } diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs index a1716d03a773..f955c9e27f41 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs @@ -45,8 +45,8 @@ public void Protect_EncryptsToDefaultProtector_MultiplePurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext); + Assert.Equal(expectedAad, actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -83,8 +83,8 @@ public void Protect_EncryptsToDefaultProtector_SinglePurpose() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext); + Assert.Equal(expectedAad, actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -423,8 +423,8 @@ public void Unprotect_KeyRevoked_RevocationAllowed_ReturnsOriginalData_SetsRevok .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext); + Assert.Equal(expectedAad, actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -470,8 +470,8 @@ public void Unprotect_IsAlsoDefaultKey_Success_NoMigrationRequired() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext); + Assert.Equal(expectedAad, actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -519,8 +519,8 @@ public void Unprotect_IsNotDefaultKey_Success_RequiresMigration() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext); + Assert.Equal(expectedAad, actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -594,8 +594,8 @@ public void CreateProtector_ChainsPurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext); + Assert.Equal(expectedAad, actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs index ffb742e4ca5a..b74f7102b731 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs @@ -25,7 +25,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext, decipheredtext); } [Fact] diff --git a/src/Http/Headers/test/CacheControlHeaderValueTest.cs b/src/Http/Headers/test/CacheControlHeaderValueTest.cs index 8887a0ed1324..a081d5b6a2c6 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter() Assert.Throws(() => cacheControl.NoCacheHeaders.Add("invalid PLACEHOLDER")); cacheControl.NoCacheHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.NoCacheHeaders); - Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.NoCacheHeaders.First()); + Assert.Equal("PLACEHOLDER", cacheControl.NoCacheHeaders.First()); Assert.NotNull(cacheControl.PrivateHeaders); Assert.Throws(() => cacheControl.PrivateHeaders.Add(null)); Assert.Throws(() => cacheControl.PrivateHeaders.Add("invalid PLACEHOLDER")); cacheControl.PrivateHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.PrivateHeaders); - Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.PrivateHeaders.First()); + Assert.Equal("PLACEHOLDER", cacheControl.PrivateHeaders.First()); // NameValueHeaderValue collection property Assert.NotNull(cacheControl.Extensions); diff --git a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs index ea56680307c4..405d693f9cc0 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -42,7 +42,7 @@ public void Ctor_ContentDispositionInvalidFormat_ThrowFormatException() public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("inline", contentDisposition.DispositionType); Assert.Empty(contentDisposition.Parameters); Assert.Null(contentDisposition.Name.Value); Assert.Null(contentDisposition.FileName.Value); @@ -63,10 +63,10 @@ public void Parameters_AddNull_Throw() public void ContentDisposition_SetAndGetContentDisposition_MatchExpectations() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("inline", contentDisposition.DispositionType); contentDisposition.DispositionType = "attachment"; - Assert.Equal("attachment".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("attachment", contentDisposition.DispositionType); } [Fact] @@ -74,9 +74,9 @@ public void Name_SetNameAndValidateObject_ParametersEntryForNameAdded() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.Name = "myname"; - Assert.Equal("myname".AsSpan(), contentDisposition.Name); + Assert.Equal("myname", contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("name".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("name", contentDisposition.Parameters.First().Name); contentDisposition.Name = null; Assert.Null(contentDisposition.Name.Value); @@ -93,12 +93,12 @@ public void Name_AddNameParameterThenUseProperty_ParametersEntryIsOverwritten() NameValueHeaderValue name = new NameValueHeaderValue("NAME", "old_name"); contentDisposition.Parameters.Add(name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("NAME", contentDisposition.Parameters.First().Name); contentDisposition.Name = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.Name); + Assert.Equal("new_name", contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("NAME", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(name); Assert.Null(contentDisposition.Name.Value); @@ -113,12 +113,12 @@ public void FileName_AddNameParameterThenUseProperty_ParametersEntryIsOverwritte var fileName = new NameValueHeaderValue("FILENAME", "old_name"); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); + Assert.Equal("new_name", contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -130,10 +130,10 @@ public void FileName_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "FileÃName.bat"; - Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileName); + Assert.Equal("FileÃName.bat", contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename", contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -145,10 +145,10 @@ public void FileName_NeedsEncodingBecauseOfNewLine_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "File\nName.bat"; - Assert.Equal("File\nName.bat".AsSpan(), contentDisposition.FileName); + Assert.Equal("File\nName.bat", contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename", contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"", contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -163,14 +163,14 @@ public void FileName_UnknownOrBadEncoding_PropertyFails() var fileName = new NameValueHeaderValue("FILENAME", "\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\""); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); - Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=".AsSpan(), contentDisposition.FileName); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); + Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=", contentDisposition.FileName); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); + Assert.Equal("new_name", contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -185,14 +185,14 @@ public void FileNameStar_AddNameParameterThenUseProperty_ParametersEntryIsOverwr var fileNameStar = new NameValueHeaderValue("FILENAME*", "old_name"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("new_name", contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'new_name".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'new_name", contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -204,10 +204,10 @@ public void FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "FileÃName.bat"; - Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("FileÃName.bat", contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'File%C3%83Name.bat".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename*", contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'File%C3%83Name.bat", contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileNameStar.Value); @@ -218,7 +218,7 @@ public void NonValidAscii_WhenNeedsEncoding_UsesHex() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "a\u0080b"; - Assert.Equal($"UTF-8\'\'a%C2%80b".AsSpan(), contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. + Assert.Equal($"UTF-8\'\'a%C2%80b", contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. } [Fact] @@ -226,7 +226,7 @@ public void LongValidAscii_FullyProcessedWithout() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = new string('a', 400); // 400 is larger to the max stackallow size - Assert.Equal($"UTF-8\'\'{new string('a', 400)}".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'{new string('a', 400)}", contentDisposition.Parameters.First().Value); } [Fact] @@ -250,11 +250,11 @@ public void FileNameStar_WhenNeedsEncoding_UsesHex() || b >= 0x7F) { var hexC = Convert.ToHexString([b]); - Assert.Equal($"UTF-8\'\'a%{hexC}b".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a%{hexC}b", contentDisposition.Parameters.First().Value); } else { - Assert.Equal($"UTF-8\'\'a{(char)b}b".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a{(char)b}b", contentDisposition.Parameters.First().Value); } contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); } @@ -269,14 +269,14 @@ public void FileNameStar_UnknownOrBadEncoding_PropertyFails() var fileNameStar = new NameValueHeaderValue("FILENAME*", "utf-99'lang'File%CZName.bat"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("utf-99'lang'File%CZName.bat".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("utf-99'lang'File%CZName.bat", contentDisposition.Parameters.First().Value); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("new_name", contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -294,8 +294,8 @@ public void SetHttpFileName_ShouldSanitizeFileNameWhereNeeded(string httpFileNam { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.SetHttpFileName(httpFileName); - Assert.Equal(expectedFileName.AsSpan(), contentDisposition.FileName); - Assert.Equal(httpFileName.AsSpan(), contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding + Assert.Equal(expectedFileName, contentDisposition.FileName); + Assert.Equal(httpFileName, contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding } [Fact] @@ -310,7 +310,7 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() var dateParameter = new NameValueHeaderValue("Creation-DATE", validDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); Assert.Equal(validDate, contentDisposition.CreationDate); @@ -318,8 +318,8 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() contentDisposition.CreationDate = newDate; Assert.Equal(newDate, contentDisposition.CreationDate); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); + Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"", contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(dateParameter); Assert.Null(contentDisposition.CreationDate); @@ -336,7 +336,7 @@ public void Dates_InvalidDates_PropertyFails() var dateParameter = new NameValueHeaderValue("read-DATE", invalidDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("read-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("read-DATE", contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.ReadDate); @@ -354,13 +354,13 @@ public void Size_AddSizeParameterThenUseProperty_ParametersEntryIsOverwritten() var sizeParameter = new NameValueHeaderValue("SIZE", "279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); Assert.Equal(279172874239, contentDisposition.Size); contentDisposition.Size = 279172874240; Assert.Equal(279172874240, contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -375,14 +375,14 @@ public void Size_InvalidSizes_PropertyFails() var sizeParameter = new NameValueHeaderValue("SIZE", "-279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.Size); // Negatives not allowed Assert.Throws(() => contentDisposition.Size = -279172874240); Assert.Null(contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -645,8 +645,8 @@ public void HeaderNamesWithQuotes_ExpectNamesToNotHaveQuotes() var result = ContentDispositionHeaderValue.Parse(contentDispositionLine); - Assert.Equal(expectedName.AsSpan(), result.Name); - Assert.Equal(expectedFileName.AsSpan(), result.FileName); + Assert.Equal(expectedName, result.Name); + Assert.Equal(expectedFileName, result.FileName); } [Fact] @@ -655,9 +655,9 @@ public void FileNameWithSurrogatePairs_EncodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName("File 🤩 name.txt"); - Assert.Equal("File __ name.txt".AsSpan(), contentDisposition.FileName); + Assert.Equal("File __ name.txt", contentDisposition.FileName); Assert.Equal(2, contentDisposition.Parameters.Count); - Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt".AsSpan(), contentDisposition.Parameters[1].Value); + Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt", contentDisposition.Parameters[1].Value); } public class ContentDispositionValue diff --git a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs index 9036835059fd..af2a5fa8bbad 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -18,7 +18,7 @@ public void Ctor_LengthOnlyOverloadValidValues_ValuesCorrectlySet() Assert.False(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit); Assert.Null(range.From); Assert.Null(range.To); Assert.Equal(5, range.Length); @@ -39,7 +39,7 @@ public void Ctor_FromAndToOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.False(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Null(range.Length); @@ -63,7 +63,7 @@ public void Ctor_FromToAndLengthOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Equal(2, range.Length); @@ -74,7 +74,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new ContentRangeHeaderValue(0); range.Unit = "myunit"; - Assert.Equal("myunit".AsSpan(), range.Unit); + Assert.Equal("myunit", range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); @@ -156,7 +156,7 @@ public void Parse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. var result = ContentRangeHeaderValue.Parse("bytes */*"); - Assert.Equal("bytes".AsSpan(), result.Unit); + Assert.Equal("bytes", result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); @@ -187,7 +187,7 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result)); - Assert.Equal("bytes".AsSpan(), result.Unit); + Assert.Equal("bytes", result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); diff --git a/src/Http/Headers/test/CookieHeaderValueTest.cs b/src/Http/Headers/test/CookieHeaderValueTest.cs index b212aae88e00..02e00068f878 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -172,8 +172,8 @@ public void CookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void CookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new CookieHeaderValue("cookie"); - Assert.Equal("cookie".AsSpan(), header.Name); - Assert.Equal(string.Empty.AsSpan(), header.Value); + Assert.Equal("cookie", header.Name); + Assert.Equal(string.Empty, header.Value); } [Theory] @@ -183,18 +183,18 @@ public void CookieHeaderValue_Ctor1_InitializesCorrectly() public void CookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new CookieHeaderValue(name, value); - Assert.Equal(name.AsSpan(), header.Name); - Assert.Equal(value.AsSpan(), header.Value); + Assert.Equal(name, header.Name); + Assert.Equal(value, header.Value); } [Fact] public void CookieHeaderValue_Value() { var cookie = new CookieHeaderValue("name"); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(string.Empty, cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1".AsSpan(), cookie.Value); + Assert.Equal("value1", cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/EntityTagHeaderValueTest.cs b/src/Http/Headers/test/EntityTagHeaderValueTest.cs index 69f4e1bcac6e..48086ab29613 100644 --- a/src/Http/Headers/test/EntityTagHeaderValueTest.cs +++ b/src/Http/Headers/test/EntityTagHeaderValueTest.cs @@ -32,7 +32,7 @@ public void Ctor_ETagInvalidFormat_ThrowFormatException() public void Ctor_ETagValidFormat_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"tag\""); - Assert.Equal("\"tag\"", etag.Tag.ToString()); + Assert.Equal("\"tag\"", etag.Tag); Assert.False(etag.IsWeak, "IsWeak"); } @@ -40,7 +40,7 @@ public void Ctor_ETagValidFormat_SuccessfullyCreated() public void Ctor_ETagValidFormatAndIsWeak_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"e tag\"", true); - Assert.Equal("\"e tag\"", etag.Tag.ToString()); + Assert.Equal("\"e tag\"", etag.Tag); Assert.True(etag.IsWeak, "IsWeak"); } diff --git a/src/Http/Headers/test/HeaderUtilitiesTest.cs b/src/Http/Headers/test/HeaderUtilitiesTest.cs index 33dfe95fb3f1..9ce61faec7f9 100644 --- a/src/Http/Headers/test/HeaderUtilitiesTest.cs +++ b/src/Http/Headers/test/HeaderUtilitiesTest.cs @@ -231,7 +231,7 @@ public void RemoveQuotes_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.RemoveQuotes(input); - Assert.Equal(expected.AsSpan(), actual); + Assert.Equal(expected, actual); } [Theory] [InlineData("\"hello\"", true)] @@ -258,7 +258,7 @@ public void UnescapeAsQuotedString_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.UnescapeAsQuotedString(input); - Assert.Equal(expected.AsSpan(), actual); + Assert.Equal(expected, actual); } [Theory] @@ -275,7 +275,7 @@ public void SetAndEscapeValue_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.EscapeAsQuotedString(input); - Assert.Equal(expected.AsSpan(), actual); + Assert.Equal(expected, actual); } [Theory] diff --git a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs index 67191c746936..5af91d202643 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -102,7 +102,7 @@ public void MatchesAllSubTypesWithoutSuffix_ReturnsExpectedResult(string value, public void Ctor_MediaTypeValidFormat_SuccessfullyCreated() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); + Assert.Equal("text/plain", mediaType.MediaType); Assert.Empty(mediaType.Parameters); Assert.Null(mediaType.Charset.Value); } @@ -112,7 +112,7 @@ public void Ctor_AddNameAndQuality_QualityParameterAdded() { var mediaType = new MediaTypeHeaderValue("application/xml", 0.08); Assert.Equal(0.08, mediaType.Quality); - Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); + Assert.Equal("application/xml", mediaType.MediaType); Assert.Single(mediaType.Parameters); } @@ -221,10 +221,10 @@ public void CopyFromReadOnly_WithParameters_CopiedAsNonReadOnly() public void MediaType_SetAndGetMediaType_MatchExpectations() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); + Assert.Equal("text/plain", mediaType.MediaType); mediaType.MediaType = "application/xml"; - Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); + Assert.Equal("application/xml", mediaType.MediaType); } [Fact] @@ -232,9 +232,9 @@ public void Charset_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() { var mediaType = new MediaTypeHeaderValue("text/plain"); mediaType.Charset = "mycharset"; - Assert.Equal("mycharset".AsSpan(), mediaType.Charset); + Assert.Equal("mycharset", mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("charset".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("charset", mediaType.Parameters.First().Name); mediaType.Charset = null; Assert.Null(mediaType.Charset.Value); @@ -251,12 +251,12 @@ public void Charset_AddCharsetParameterThenUseProperty_ParametersEntryIsOverwrit var charset = new NameValueHeaderValue("CHARSET", "old_charset"); mediaType.Parameters.Add(charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("CHARSET", mediaType.Parameters.First().Name); mediaType.Charset = "new_charset"; - Assert.Equal("new_charset".AsSpan(), mediaType.Charset); + Assert.Equal("new_charset", mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("CHARSET", mediaType.Parameters.First().Name); mediaType.Parameters.Remove(charset); Assert.Null(mediaType.Charset.Value); @@ -269,8 +269,8 @@ public void Quality_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() mediaType.Quality = 0.563156454; Assert.Equal(0.563, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); - Assert.Equal("0.563".AsSpan(), mediaType.Parameters.First().Value); + Assert.Equal("q", mediaType.Parameters.First().Name); + Assert.Equal("0.563", mediaType.Parameters.First().Value); mediaType.Quality = null; Assert.Null(mediaType.Quality); @@ -286,13 +286,13 @@ public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwrit var quality = new NameValueHeaderValue("q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("q", mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); mediaType.Quality = 0.9; Assert.Equal(0.9, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("q", mediaType.Parameters.First().Name); mediaType.Parameters.Remove(quality); Assert.Null(mediaType.Quality); @@ -306,7 +306,7 @@ public void Quality_AddQualityParameterUpperCase_CaseInsensitiveComparison() var quality = new NameValueHeaderValue("Q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("Q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("Q", mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); } diff --git a/src/Http/Headers/test/NameValueHeaderValueTest.cs b/src/Http/Headers/test/NameValueHeaderValueTest.cs index 2031b6a77391..003ee695c7f6 100644 --- a/src/Http/Headers/test/NameValueHeaderValueTest.cs +++ b/src/Http/Headers/test/NameValueHeaderValueTest.cs @@ -29,7 +29,7 @@ public void Ctor_NameInvalidFormat_ThrowFormatException() public void Ctor_NameValidFormat_SuccessfullyCreated() { var nameValue = new NameValueHeaderValue("text", null); - Assert.Equal("text".AsSpan(), nameValue.Name); + Assert.Equal("text", nameValue.Name); } [Fact] @@ -66,7 +66,7 @@ public void Copy_NameOnly_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("othervalue", pair0.Value); Assert.Null(pair1.Value.Value); } @@ -84,7 +84,7 @@ public void CopyAsReadOnly_NameOnly_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("othervalue", pair0.Value); Assert.Null(pair1.Value.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -100,8 +100,8 @@ public void Copy_NameAndValue_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair0.Value); + Assert.Equal("value", pair1.Value); } [Fact] @@ -117,8 +117,8 @@ public void CopyAsReadOnly_NameAndValue_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair0.Value); + Assert.Equal("value", pair1.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -134,8 +134,8 @@ public void CopyFromReadOnly_NameAndValue_CopiedAsNonReadOnly() // Change one value and verify the other is unchanged. pair2.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair2.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair2.Value); + Assert.Equal("value", pair1.Value); } [Fact] @@ -581,7 +581,7 @@ public void GetUnescapedValue_ReturnsExpectedValue(string input, string expected var actual = header.GetUnescapedValue(); - Assert.Equal(expected.AsSpan(), actual); + Assert.Equal(expected, actual); } [Theory] @@ -602,7 +602,7 @@ public void SetAndEscapeValue_ReturnsExpectedValue(string input, string expected var actual = header.Value; - Assert.Equal(expected.AsSpan(), actual); + Assert.Equal(expected, actual); } [Theory] @@ -628,7 +628,7 @@ public void GetAndSetEncodeValueRoundTrip_ReturnsExpectedValue(string input) var actual = header.Value; - Assert.Equal(input.AsSpan(), actual); + Assert.Equal(input, actual); } [Theory] @@ -673,7 +673,7 @@ private void CheckInvalidTryParse(string? input) private static void CheckValue(string? value) { var nameValue = new NameValueHeaderValue("text", value); - Assert.Equal(value.AsSpan(), nameValue.Value); + Assert.Equal(value, nameValue.Value); } private static void AssertFormatException(string name, string? value) diff --git a/src/Http/Headers/test/RangeHeaderValueTest.cs b/src/Http/Headers/test/RangeHeaderValueTest.cs index 101759609c02..624c07dafbd1 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -16,7 +16,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new RangeHeaderValue(); range.Unit = "myunit"; - Assert.Equal("myunit".AsSpan(), range.Unit); + Assert.Equal("myunit", range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); diff --git a/src/Http/Headers/test/SetCookieHeaderValueTest.cs b/src/Http/Headers/test/SetCookieHeaderValueTest.cs index 7e53fad5e75c..05c6684feef9 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -318,8 +318,8 @@ public void SetCookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new SetCookieHeaderValue("cookie"); - Assert.Equal("cookie".AsSpan(), header.Name); - Assert.Equal(string.Empty.AsSpan(), header.Value); + Assert.Equal("cookie", header.Name); + Assert.Equal(string.Empty, header.Value); } [Theory] @@ -329,18 +329,18 @@ public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() public void SetCookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new SetCookieHeaderValue(name, value); - Assert.Equal(name.AsSpan(), header.Name); - Assert.Equal(value.AsSpan(), header.Value); + Assert.Equal(name, header.Name); + Assert.Equal(value, header.Value); } [Fact] public void SetCookieHeaderValue_Value() { var cookie = new SetCookieHeaderValue("name"); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(string.Empty, cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1".AsSpan(), cookie.Value); + Assert.Equal("value1", cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs index 5a786b6b70a8..661114afbcfa 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -9,7 +9,7 @@ public class StringWithQualityHeaderValueTest public void Ctor_StringOnlyOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token"); - Assert.Equal("token".AsSpan(), value.Value); + Assert.Equal("token", value.Value); Assert.Null(value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null)); @@ -21,7 +21,7 @@ public void Ctor_StringOnlyOverload_MatchExpectation() public void Ctor_StringWithQualityOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token", 0.5); - Assert.Equal("token".AsSpan(), value.Value); + Assert.Equal("token", value.Value); Assert.Equal(0.5, value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null, 0.1)); diff --git a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs index ebdb2fe0ad7d..ce171a6ec527 100644 --- a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs +++ b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs @@ -64,8 +64,8 @@ public void CookieBuilder_Extensions_Added() Assert.Contains("key=value", options.Extensions); var cookie = options.CreateCookieHeader("name", "value"); - Assert.Equal("name".AsSpan(), cookie.Name); - Assert.Equal("value".AsSpan(), cookie.Value); + Assert.Equal("name", cookie.Name); + Assert.Equal("value", cookie.Value); Assert.Equal(2, cookie.Extensions.Count); Assert.Contains("simple", cookie.Extensions); Assert.Contains("key=value", cookie.Extensions); diff --git a/src/Http/WebUtilities/test/QueryHelpersTests.cs b/src/Http/WebUtilities/test/QueryHelpersTests.cs index 6f040e4146e4..8707fe2411be 100644 --- a/src/Http/WebUtilities/test/QueryHelpersTests.cs +++ b/src/Http/WebUtilities/test/QueryHelpersTests.cs @@ -30,7 +30,7 @@ public void ParseQueryWithDuplicateKeysGroups() { var collection = QueryHelpers.ParseQuery("?key1=valueA&key2=valueB&key1=valueC"); Assert.Equal(2, collection.Count); - Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"].ToArray()); + Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"]); Assert.Equal("valueB", collection["key2"].FirstOrDefault()); } @@ -48,7 +48,7 @@ public void ParseQueryWithEmptyKeyWorks() { var collection = QueryHelpers.ParseQuery("?=value1&="); Assert.Single(collection); - Assert.Equal(new[] { "value1", "" }, collection[""].ToArray()); + Assert.Equal(new[] { "value1", "" }, collection[""]); } [Fact] @@ -88,7 +88,7 @@ public void ParseQueryWithEncodedKeyEncodedValuesWorks() { var collection = QueryHelpers.ParseQuery("?fields+%5BtodoItems%5D=%5B+1+%5D&fields+%5BtodoItems%5D=%5B+2+%5D"); Assert.Single(collection); - Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"].ToArray()); + Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"]); } [Theory] diff --git a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs index d4861a9a527b..b7b3e8d95612 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs @@ -284,8 +284,8 @@ public void SaveTempData_RemovesCookie_WhenNoDataToSave() Assert.Single(responseCookies); var cookie = responseCookies.Single(); Assert.NotNull(cookie); - Assert.Equal(CookieTempDataProvider.CookieName.AsSpan(), cookie.Name); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(CookieTempDataProvider.CookieName, cookie.Name); + Assert.Equal(string.Empty, cookie.Value); Assert.NotNull(cookie.Expires); Assert.True(cookie.Expires.Value < DateTimeOffset.Now); // expired cookie } diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs index debdf250c46e..f25096cc9acc 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs @@ -80,7 +80,7 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) foreach (var cookieTempDataProviderCookie in cookieTempDataProviderCookies) { Assert.NotNull(cookieTempDataProviderCookie.Value.Value); - Assert.Equal("/".AsSpan(), cookieTempDataProviderCookie.Path); + Assert.Equal("/", cookieTempDataProviderCookie.Path); Assert.Null(cookieTempDataProviderCookie.Domain.Value); Assert.False(cookieTempDataProviderCookie.Secure); } @@ -97,8 +97,8 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeader => setCookieHeader.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeaderValue); - Assert.Equal(string.Empty.AsSpan(), setCookieHeaderValue.Value); - Assert.Equal("/".AsSpan(), setCookieHeaderValue.Path); + Assert.Equal(string.Empty, setCookieHeaderValue.Value); + Assert.Equal("/", setCookieHeaderValue.Path); Assert.Null(setCookieHeaderValue.Domain.Value); Assert.NotNull(setCookieHeaderValue.Expires); Assert.True(setCookieHeaderValue.Expires < DateTimeOffset.Now); // expired cookie @@ -130,7 +130,7 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal("/", setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); @@ -153,8 +153,8 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal(string.Empty.AsSpan(), setCookieHeader.Value); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal(string.Empty, setCookieHeader.Value); + Assert.Equal("/", setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.NotNull(setCookieHeader.Expires); Assert.True(setCookieHeader.Expires < DateTimeOffset.Now); // expired cookie @@ -183,7 +183,7 @@ public async Task CookieTempDataProviderCookie_DoesNotSetsSecureAttributeOnCooki .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal("/", setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); diff --git a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs index 68d6e98ce124..abc76954193c 100644 --- a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs +++ b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs @@ -441,15 +441,15 @@ public async Task ChallengeSetsNonceAndStateCookies(OpenIdConnectRedirectBehavio Assert.True(nonceCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(nonceCookie.HttpOnly); - Assert.Equal("/signin-oidc".AsSpan(), nonceCookie.Path); - Assert.Equal("N".AsSpan(), nonceCookie.Value); + Assert.Equal("/signin-oidc", nonceCookie.Path); + Assert.Equal("N", nonceCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.None, nonceCookie.SameSite); var correlationCookie = challengeCookies.Where(cookie => cookie.Name.StartsWith(".AspNetCore.Correlation.", StringComparison.Ordinal)).Single(); Assert.True(correlationCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(correlationCookie.HttpOnly); - Assert.Equal("/signin-oidc".AsSpan(), correlationCookie.Path); + Assert.Equal("/signin-oidc", correlationCookie.Path); Assert.False(StringSegment.IsNullOrEmpty(correlationCookie.Value)); Assert.Equal(Net.Http.Headers.SameSiteMode.None, correlationCookie.SameSite); @@ -847,7 +847,7 @@ public async Task Challenge_WithPushedAuthorization_Handled() var res = transaction.Response; Assert.Equal(HttpStatusCode.Redirect, res.StatusCode); - + Assert.Contains("request_uri=request_uri_from_event", res.Headers.Location.Query); Assert.Empty(mockBackchannel.PushedParameters); } diff --git a/src/Security/CookiePolicy/test/CookieConsentTests.cs b/src/Security/CookiePolicy/test/CookieConsentTests.cs index 79905c22c9c6..f5234ca0af2d 100644 --- a/src/Security/CookiePolicy/test/CookieConsentTests.cs +++ b/src/Security/CookiePolicy/test/CookieConsentTests.cs @@ -217,15 +217,15 @@ public async Task GrantConsentSetsCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("yes".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name); + Assert.Equal("yes", consentCookie.Value); Assert.True(consentCookie.Expires.HasValue); Assert.True(consentCookie.Expires.Value > DateTimeOffset.Now + TimeSpan.FromDays(364)); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); var testCookie = cookies[1]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("Value".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name); + Assert.Equal("Value", testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); } @@ -239,8 +239,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnAppendCookie = context => { - Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); - Assert.Equal("yes".AsSpan(), context.CookieValue); + Assert.Equal(".AspNet.Consent", context.CookieName); + Assert.Equal("yes", context.CookieValue); Assert.Equal(Http.SameSiteMode.Strict, context.CookieOptions.SameSite); context.CookieName += "1"; context.CookieValue += "1"; @@ -267,8 +267,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("yes1".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name); + Assert.Equal("yes1", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); Assert.Contains("extension", consentCookie.Extensions); @@ -398,13 +398,13 @@ public async Task WithdrawConsentDeletesCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var testCookie = cookies[0]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("Value1".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name); + Assert.Equal("Value1", testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); var consentCookie = cookies[1]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name); + Assert.Equal("", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -418,7 +418,7 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnDeleteCookie = context => { - Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); + Assert.Equal(".AspNet.Consent", context.CookieName); context.CookieName += "1"; }; }, @@ -445,8 +445,8 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name); + Assert.Equal("", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -510,8 +510,8 @@ public async Task DeleteCookieDoesNotRequireConsent() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var testCookie = cookies[0]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name); + Assert.Equal("", testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.NotNull(testCookie.Expires); } @@ -574,8 +574,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("yes".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name); + Assert.Equal("yes", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -627,8 +627,8 @@ public async Task CreateConsentCookieAppliesPolicy() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("yes1".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name); + Assert.Equal("yes1", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -672,8 +672,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookieWhenCookieValueIsC var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("true".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name); + Assert.Equal("true", consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); diff --git a/src/Security/CookiePolicy/test/CookiePolicyTests.cs b/src/Security/CookiePolicy/test/CookiePolicyTests.cs index 30a55a961d55..d17decb80a64 100644 --- a/src/Security/CookiePolicy/test/CookiePolicyTests.cs +++ b/src/Security/CookiePolicy/test/CookiePolicyTests.cs @@ -58,10 +58,10 @@ await RunTest("/secureAlways", transaction => { Assert.NotNull(transaction.SetCookie); - Assert.Equal("A=A; path=/; secure".AsSpan(), transaction.SetCookie[0]); - Assert.Equal("B=B; path=/; secure".AsSpan(), transaction.SetCookie[1]); - Assert.Equal("C=C; path=/; secure".AsSpan(), transaction.SetCookie[2]); - Assert.Equal("D=D; path=/; secure".AsSpan(), transaction.SetCookie[3]); + Assert.Equal("A=A; path=/; secure", transaction.SetCookie[0]); + Assert.Equal("B=B; path=/; secure", transaction.SetCookie[1]); + Assert.Equal("C=C; path=/; secure", transaction.SetCookie[2]); + Assert.Equal("D=D; path=/; secure", transaction.SetCookie[3]); })); } @@ -398,10 +398,10 @@ public async Task CookiePolicyAppliesToCookieAuth() Assert.NotNull(transaction.SetCookie); Assert.Single(transaction.SetCookie); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie".AsSpan(), cookie.Name); + Assert.Equal("TestCookie", cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path); Assert.Contains("extension", cookie.Extensions); } @@ -450,25 +450,25 @@ public async Task CookiePolicyAppliesToCookieAuthChunks() Assert.Equal(3, transaction.SetCookie.Count); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie".AsSpan(), cookie.Name); - Assert.Equal("chunks-2".AsSpan(), cookie.Value); + Assert.Equal("TestCookie", cookie.Name); + Assert.Equal("chunks-2", cookie.Value); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[1]); - Assert.Equal("TestCookieC1".AsSpan(), cookie.Name); + Assert.Equal("TestCookieC1", cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[2]); - Assert.Equal("TestCookieC2".AsSpan(), cookie.Name); + Assert.Equal("TestCookieC2", cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path); Assert.Contains("ext", cookie.Extensions); } diff --git a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs index 23a4ca0e3fd3..2edf4628129e 100644 --- a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs +++ b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs @@ -486,7 +486,7 @@ public void EncodesHeadersInSinglePayloadWhenSpaceAvailable(KeyValuePair(payload, 0, length).ToArray()); + Assert.Equal(expectedPayload, new ArraySegment(payload, 0, length)); } [Theory] From 78ab6e35a7f0b52996e3ecf920666848cb91ab49 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 11:08:47 -0800 Subject: [PATCH 04/18] Update XUnit package --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 566f7e66cc19..732b293be2c5 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -322,7 +322,7 @@ 19.14.0 2.0.3 1.15.0 - 2.9.0 + 2.9.2 $(XunitVersion) $(XunitVersion) $(XunitVersion) From 0a3b290b2d109e0b99a9d27037afa6d9142a69f4 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 09:48:22 -0800 Subject: [PATCH 05/18] Fix build errors --- .../Cng/CbcAuthenticatedEncryptorTests.cs | 2 +- .../Cng/GcmAuthenticatedEncryptorTests.cs | 4 +- .../KeyRingBasedDataProtectorTests.cs | 24 ++--- .../ManagedAuthenticatedEncryptorTests.cs | 2 +- .../test/CacheControlHeaderValueTest.cs | 4 +- .../test/ContentDispositionHeaderValueTest.cs | 102 +++++++++--------- .../test/ContentRangeHeaderValueTest.cs | 12 +-- .../Headers/test/CookieHeaderValueTest.cs | 12 +-- .../Headers/test/EntityTagHeaderValueTest.cs | 4 +- src/Http/Headers/test/HeaderUtilitiesTest.cs | 6 +- .../Headers/test/MediaTypeHeaderValueTest.cs | 28 ++--- .../Headers/test/NameValueHeaderValueTest.cs | 26 ++--- src/Http/Headers/test/RangeHeaderValueTest.cs | 2 +- .../Headers/test/SetCookieHeaderValueTest.cs | 12 +-- .../test/StringWithQualityHeaderValueTest.cs | 4 +- .../test/CookieBuilderTests.cs | 4 +- .../WebUtilities/test/QueryHelpersTests.cs | 6 +- .../test/CookieTempDataProviderTest.cs | 4 +- .../TempDataInCookiesTest.cs | 14 +-- .../OpenIdConnectChallengeTests.cs | 8 +- .../CookiePolicy/test/CookieConsentTests.cs | 46 ++++---- .../CookiePolicy/test/CookiePolicyTests.cs | 26 ++--- .../Core/test/Http2/Http2HPackEncoderTests.cs | 2 +- 23 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs index 549fdc217463..9285ba471d78 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs @@ -29,7 +29,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [ConditionalFact] diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs index 6c3cb9f51d12..90091ac3c3cc 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs @@ -26,7 +26,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [ConditionalFact] @@ -100,6 +100,6 @@ public void Encrypt_KnownKey() // | 00 00 00 00 (postBuffer) string retValAsString = Convert.ToBase64String(retVal); - Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA", retValAsString); + Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA".AsSpan(), retValAsString); } } diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs index f955c9e27f41..a1716d03a773 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs @@ -45,8 +45,8 @@ public void Protect_EncryptsToDefaultProtector_MultiplePurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -83,8 +83,8 @@ public void Protect_EncryptsToDefaultProtector_SinglePurpose() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -423,8 +423,8 @@ public void Unprotect_KeyRevoked_RevocationAllowed_ReturnsOriginalData_SetsRevok .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -470,8 +470,8 @@ public void Unprotect_IsAlsoDefaultKey_Success_NoMigrationRequired() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -519,8 +519,8 @@ public void Unprotect_IsNotDefaultKey_Success_RequiresMigration() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext, actualCiphertext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -594,8 +594,8 @@ public void CreateProtector_ChainsPurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext, actualPlaintext); - Assert.Equal(expectedAad, actualAad); + Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); + Assert.Equal(expectedAad.AsSpan(), actualAad); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs index b74f7102b731..ffb742e4ca5a 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs @@ -25,7 +25,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext, decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext); } [Fact] diff --git a/src/Http/Headers/test/CacheControlHeaderValueTest.cs b/src/Http/Headers/test/CacheControlHeaderValueTest.cs index a081d5b6a2c6..8887a0ed1324 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter() Assert.Throws(() => cacheControl.NoCacheHeaders.Add("invalid PLACEHOLDER")); cacheControl.NoCacheHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.NoCacheHeaders); - Assert.Equal("PLACEHOLDER", cacheControl.NoCacheHeaders.First()); + Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.NoCacheHeaders.First()); Assert.NotNull(cacheControl.PrivateHeaders); Assert.Throws(() => cacheControl.PrivateHeaders.Add(null)); Assert.Throws(() => cacheControl.PrivateHeaders.Add("invalid PLACEHOLDER")); cacheControl.PrivateHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.PrivateHeaders); - Assert.Equal("PLACEHOLDER", cacheControl.PrivateHeaders.First()); + Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.PrivateHeaders.First()); // NameValueHeaderValue collection property Assert.NotNull(cacheControl.Extensions); diff --git a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs index 405d693f9cc0..ea56680307c4 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -42,7 +42,7 @@ public void Ctor_ContentDispositionInvalidFormat_ThrowFormatException() public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline", contentDisposition.DispositionType); + Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); Assert.Empty(contentDisposition.Parameters); Assert.Null(contentDisposition.Name.Value); Assert.Null(contentDisposition.FileName.Value); @@ -63,10 +63,10 @@ public void Parameters_AddNull_Throw() public void ContentDisposition_SetAndGetContentDisposition_MatchExpectations() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline", contentDisposition.DispositionType); + Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); contentDisposition.DispositionType = "attachment"; - Assert.Equal("attachment", contentDisposition.DispositionType); + Assert.Equal("attachment".AsSpan(), contentDisposition.DispositionType); } [Fact] @@ -74,9 +74,9 @@ public void Name_SetNameAndValidateObject_ParametersEntryForNameAdded() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.Name = "myname"; - Assert.Equal("myname", contentDisposition.Name); + Assert.Equal("myname".AsSpan(), contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("name", contentDisposition.Parameters.First().Name); + Assert.Equal("name".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Name = null; Assert.Null(contentDisposition.Name.Value); @@ -93,12 +93,12 @@ public void Name_AddNameParameterThenUseProperty_ParametersEntryIsOverwritten() NameValueHeaderValue name = new NameValueHeaderValue("NAME", "old_name"); contentDisposition.Parameters.Add(name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME", contentDisposition.Parameters.First().Name); + Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Name = "new_name"; - Assert.Equal("new_name", contentDisposition.Name); + Assert.Equal("new_name".AsSpan(), contentDisposition.Name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME", contentDisposition.Parameters.First().Name); + Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(name); Assert.Null(contentDisposition.Name.Value); @@ -113,12 +113,12 @@ public void FileName_AddNameParameterThenUseProperty_ParametersEntryIsOverwritte var fileName = new NameValueHeaderValue("FILENAME", "old_name"); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name", contentDisposition.FileName); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -130,10 +130,10 @@ public void FileName_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "FileÃName.bat"; - Assert.Equal("FileÃName.bat", contentDisposition.FileName); + Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); + Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -145,10 +145,10 @@ public void FileName_NeedsEncodingBecauseOfNewLine_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "File\nName.bat"; - Assert.Equal("File\nName.bat", contentDisposition.FileName); + Assert.Equal("File\nName.bat".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"", contentDisposition.Parameters.First().Value); + Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -163,14 +163,14 @@ public void FileName_UnknownOrBadEncoding_PropertyFails() var fileName = new NameValueHeaderValue("FILENAME", "\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\""); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value); - Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=", contentDisposition.FileName); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=".AsSpan(), contentDisposition.FileName); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name", contentDisposition.FileName); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -185,14 +185,14 @@ public void FileNameStar_AddNameParameterThenUseProperty_ParametersEntryIsOverwr var fileNameStar = new NameValueHeaderValue("FILENAME*", "old_name"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name", contentDisposition.FileNameStar); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'new_name", contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'new_name".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -204,10 +204,10 @@ public void FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "FileÃName.bat"; - Assert.Equal("FileÃName.bat", contentDisposition.FileNameStar); + Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename*", contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'File%C3%83Name.bat", contentDisposition.Parameters.First().Value); + Assert.Equal("filename*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("UTF-8\'\'File%C3%83Name.bat".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileNameStar.Value); @@ -218,7 +218,7 @@ public void NonValidAscii_WhenNeedsEncoding_UsesHex() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "a\u0080b"; - Assert.Equal($"UTF-8\'\'a%C2%80b", contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. + Assert.Equal($"UTF-8\'\'a%C2%80b".AsSpan(), contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. } [Fact] @@ -226,7 +226,7 @@ public void LongValidAscii_FullyProcessedWithout() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = new string('a', 400); // 400 is larger to the max stackallow size - Assert.Equal($"UTF-8\'\'{new string('a', 400)}", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'{new string('a', 400)}".AsSpan(), contentDisposition.Parameters.First().Value); } [Fact] @@ -250,11 +250,11 @@ public void FileNameStar_WhenNeedsEncoding_UsesHex() || b >= 0x7F) { var hexC = Convert.ToHexString([b]); - Assert.Equal($"UTF-8\'\'a%{hexC}b", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a%{hexC}b".AsSpan(), contentDisposition.Parameters.First().Value); } else { - Assert.Equal($"UTF-8\'\'a{(char)b}b", contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a{(char)b}b".AsSpan(), contentDisposition.Parameters.First().Value); } contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); } @@ -269,14 +269,14 @@ public void FileNameStar_UnknownOrBadEncoding_PropertyFails() var fileNameStar = new NameValueHeaderValue("FILENAME*", "utf-99'lang'File%CZName.bat"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); - Assert.Equal("utf-99'lang'File%CZName.bat", contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("utf-99'lang'File%CZName.bat".AsSpan(), contentDisposition.Parameters.First().Value); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name", contentDisposition.FileNameStar); + Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -294,8 +294,8 @@ public void SetHttpFileName_ShouldSanitizeFileNameWhereNeeded(string httpFileNam { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.SetHttpFileName(httpFileName); - Assert.Equal(expectedFileName, contentDisposition.FileName); - Assert.Equal(httpFileName, contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding + Assert.Equal(expectedFileName.AsSpan(), contentDisposition.FileName); + Assert.Equal(httpFileName.AsSpan(), contentDisposition.FileNameStar); // Should roundtrip through FileNameStar encoding } [Fact] @@ -310,7 +310,7 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() var dateParameter = new NameValueHeaderValue("Creation-DATE", validDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); + Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Equal(validDate, contentDisposition.CreationDate); @@ -318,8 +318,8 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() contentDisposition.CreationDate = newDate; Assert.Equal(newDate, contentDisposition.CreationDate); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name); - Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"", contentDisposition.Parameters.First().Value); + Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"".AsSpan(), contentDisposition.Parameters.First().Value); contentDisposition.Parameters.Remove(dateParameter); Assert.Null(contentDisposition.CreationDate); @@ -336,7 +336,7 @@ public void Dates_InvalidDates_PropertyFails() var dateParameter = new NameValueHeaderValue("read-DATE", invalidDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("read-DATE", contentDisposition.Parameters.First().Name); + Assert.Equal("read-DATE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.ReadDate); @@ -354,13 +354,13 @@ public void Size_AddSizeParameterThenUseProperty_ParametersEntryIsOverwritten() var sizeParameter = new NameValueHeaderValue("SIZE", "279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Equal(279172874239, contentDisposition.Size); contentDisposition.Size = 279172874240; Assert.Equal(279172874240, contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -375,14 +375,14 @@ public void Size_InvalidSizes_PropertyFails() var sizeParameter = new NameValueHeaderValue("SIZE", "-279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); Assert.Null(contentDisposition.Size); // Negatives not allowed Assert.Throws(() => contentDisposition.Size = -279172874240); Assert.Null(contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE", contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -645,8 +645,8 @@ public void HeaderNamesWithQuotes_ExpectNamesToNotHaveQuotes() var result = ContentDispositionHeaderValue.Parse(contentDispositionLine); - Assert.Equal(expectedName, result.Name); - Assert.Equal(expectedFileName, result.FileName); + Assert.Equal(expectedName.AsSpan(), result.Name); + Assert.Equal(expectedFileName.AsSpan(), result.FileName); } [Fact] @@ -655,9 +655,9 @@ public void FileNameWithSurrogatePairs_EncodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName("File 🤩 name.txt"); - Assert.Equal("File __ name.txt", contentDisposition.FileName); + Assert.Equal("File __ name.txt".AsSpan(), contentDisposition.FileName); Assert.Equal(2, contentDisposition.Parameters.Count); - Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt", contentDisposition.Parameters[1].Value); + Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt".AsSpan(), contentDisposition.Parameters[1].Value); } public class ContentDispositionValue diff --git a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs index af2a5fa8bbad..9036835059fd 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -18,7 +18,7 @@ public void Ctor_LengthOnlyOverloadValidValues_ValuesCorrectlySet() Assert.False(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Null(range.From); Assert.Null(range.To); Assert.Equal(5, range.Length); @@ -39,7 +39,7 @@ public void Ctor_FromAndToOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.False(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Null(range.Length); @@ -63,7 +63,7 @@ public void Ctor_FromToAndLengthOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes", range.Unit); + Assert.Equal("bytes".AsSpan(), range.Unit); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Equal(2, range.Length); @@ -74,7 +74,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new ContentRangeHeaderValue(0); range.Unit = "myunit"; - Assert.Equal("myunit", range.Unit); + Assert.Equal("myunit".AsSpan(), range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); @@ -156,7 +156,7 @@ public void Parse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. var result = ContentRangeHeaderValue.Parse("bytes */*"); - Assert.Equal("bytes", result.Unit); + Assert.Equal("bytes".AsSpan(), result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); @@ -187,7 +187,7 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result)); - Assert.Equal("bytes", result.Unit); + Assert.Equal("bytes".AsSpan(), result.Unit); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); diff --git a/src/Http/Headers/test/CookieHeaderValueTest.cs b/src/Http/Headers/test/CookieHeaderValueTest.cs index 02e00068f878..b212aae88e00 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -172,8 +172,8 @@ public void CookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void CookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new CookieHeaderValue("cookie"); - Assert.Equal("cookie", header.Name); - Assert.Equal(string.Empty, header.Value); + Assert.Equal("cookie".AsSpan(), header.Name); + Assert.Equal(string.Empty.AsSpan(), header.Value); } [Theory] @@ -183,18 +183,18 @@ public void CookieHeaderValue_Ctor1_InitializesCorrectly() public void CookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new CookieHeaderValue(name, value); - Assert.Equal(name, header.Name); - Assert.Equal(value, header.Value); + Assert.Equal(name.AsSpan(), header.Name); + Assert.Equal(value.AsSpan(), header.Value); } [Fact] public void CookieHeaderValue_Value() { var cookie = new CookieHeaderValue("name"); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1", cookie.Value); + Assert.Equal("value1".AsSpan(), cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/EntityTagHeaderValueTest.cs b/src/Http/Headers/test/EntityTagHeaderValueTest.cs index 48086ab29613..69f4e1bcac6e 100644 --- a/src/Http/Headers/test/EntityTagHeaderValueTest.cs +++ b/src/Http/Headers/test/EntityTagHeaderValueTest.cs @@ -32,7 +32,7 @@ public void Ctor_ETagInvalidFormat_ThrowFormatException() public void Ctor_ETagValidFormat_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"tag\""); - Assert.Equal("\"tag\"", etag.Tag); + Assert.Equal("\"tag\"", etag.Tag.ToString()); Assert.False(etag.IsWeak, "IsWeak"); } @@ -40,7 +40,7 @@ public void Ctor_ETagValidFormat_SuccessfullyCreated() public void Ctor_ETagValidFormatAndIsWeak_SuccessfullyCreated() { var etag = new EntityTagHeaderValue("\"e tag\"", true); - Assert.Equal("\"e tag\"", etag.Tag); + Assert.Equal("\"e tag\"", etag.Tag.ToString()); Assert.True(etag.IsWeak, "IsWeak"); } diff --git a/src/Http/Headers/test/HeaderUtilitiesTest.cs b/src/Http/Headers/test/HeaderUtilitiesTest.cs index 9ce61faec7f9..33dfe95fb3f1 100644 --- a/src/Http/Headers/test/HeaderUtilitiesTest.cs +++ b/src/Http/Headers/test/HeaderUtilitiesTest.cs @@ -231,7 +231,7 @@ public void RemoveQuotes_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.RemoveQuotes(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] [InlineData("\"hello\"", true)] @@ -258,7 +258,7 @@ public void UnescapeAsQuotedString_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.UnescapeAsQuotedString(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -275,7 +275,7 @@ public void SetAndEscapeValue_BehaviorCheck(string input, string expected) { var actual = HeaderUtilities.EscapeAsQuotedString(input); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] diff --git a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs index 5af91d202643..67191c746936 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -102,7 +102,7 @@ public void MatchesAllSubTypesWithoutSuffix_ReturnsExpectedResult(string value, public void Ctor_MediaTypeValidFormat_SuccessfullyCreated() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain", mediaType.MediaType); + Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); Assert.Empty(mediaType.Parameters); Assert.Null(mediaType.Charset.Value); } @@ -112,7 +112,7 @@ public void Ctor_AddNameAndQuality_QualityParameterAdded() { var mediaType = new MediaTypeHeaderValue("application/xml", 0.08); Assert.Equal(0.08, mediaType.Quality); - Assert.Equal("application/xml", mediaType.MediaType); + Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); Assert.Single(mediaType.Parameters); } @@ -221,10 +221,10 @@ public void CopyFromReadOnly_WithParameters_CopiedAsNonReadOnly() public void MediaType_SetAndGetMediaType_MatchExpectations() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain", mediaType.MediaType); + Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); mediaType.MediaType = "application/xml"; - Assert.Equal("application/xml", mediaType.MediaType); + Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); } [Fact] @@ -232,9 +232,9 @@ public void Charset_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() { var mediaType = new MediaTypeHeaderValue("text/plain"); mediaType.Charset = "mycharset"; - Assert.Equal("mycharset", mediaType.Charset); + Assert.Equal("mycharset".AsSpan(), mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("charset", mediaType.Parameters.First().Name); + Assert.Equal("charset".AsSpan(), mediaType.Parameters.First().Name); mediaType.Charset = null; Assert.Null(mediaType.Charset.Value); @@ -251,12 +251,12 @@ public void Charset_AddCharsetParameterThenUseProperty_ParametersEntryIsOverwrit var charset = new NameValueHeaderValue("CHARSET", "old_charset"); mediaType.Parameters.Add(charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET", mediaType.Parameters.First().Name); + Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); mediaType.Charset = "new_charset"; - Assert.Equal("new_charset", mediaType.Charset); + Assert.Equal("new_charset".AsSpan(), mediaType.Charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET", mediaType.Parameters.First().Name); + Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); mediaType.Parameters.Remove(charset); Assert.Null(mediaType.Charset.Value); @@ -269,8 +269,8 @@ public void Quality_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() mediaType.Quality = 0.563156454; Assert.Equal(0.563, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); - Assert.Equal("0.563", mediaType.Parameters.First().Value); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("0.563".AsSpan(), mediaType.Parameters.First().Value); mediaType.Quality = null; Assert.Null(mediaType.Quality); @@ -286,13 +286,13 @@ public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwrit var quality = new NameValueHeaderValue("q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); mediaType.Quality = 0.9; Assert.Equal(0.9, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q", mediaType.Parameters.First().Name); + Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); mediaType.Parameters.Remove(quality); Assert.Null(mediaType.Quality); @@ -306,7 +306,7 @@ public void Quality_AddQualityParameterUpperCase_CaseInsensitiveComparison() var quality = new NameValueHeaderValue("Q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("Q", mediaType.Parameters.First().Name); + Assert.Equal("Q".AsSpan(), mediaType.Parameters.First().Name); Assert.Equal(0.132, mediaType.Quality); } diff --git a/src/Http/Headers/test/NameValueHeaderValueTest.cs b/src/Http/Headers/test/NameValueHeaderValueTest.cs index 003ee695c7f6..2031b6a77391 100644 --- a/src/Http/Headers/test/NameValueHeaderValueTest.cs +++ b/src/Http/Headers/test/NameValueHeaderValueTest.cs @@ -29,7 +29,7 @@ public void Ctor_NameInvalidFormat_ThrowFormatException() public void Ctor_NameValidFormat_SuccessfullyCreated() { var nameValue = new NameValueHeaderValue("text", null); - Assert.Equal("text", nameValue.Name); + Assert.Equal("text".AsSpan(), nameValue.Name); } [Fact] @@ -66,7 +66,7 @@ public void Copy_NameOnly_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); Assert.Null(pair1.Value.Value); } @@ -84,7 +84,7 @@ public void CopyAsReadOnly_NameOnly_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); Assert.Null(pair1.Value.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -100,8 +100,8 @@ public void Copy_NameAndValue_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("value".AsSpan(), pair1.Value); } [Fact] @@ -117,8 +117,8 @@ public void CopyAsReadOnly_NameAndValue_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue", pair0.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("value".AsSpan(), pair1.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -134,8 +134,8 @@ public void CopyFromReadOnly_NameAndValue_CopiedAsNonReadOnly() // Change one value and verify the other is unchanged. pair2.Value = "othervalue"; - Assert.Equal("othervalue", pair2.Value); - Assert.Equal("value", pair1.Value); + Assert.Equal("othervalue".AsSpan(), pair2.Value); + Assert.Equal("value".AsSpan(), pair1.Value); } [Fact] @@ -581,7 +581,7 @@ public void GetUnescapedValue_ReturnsExpectedValue(string input, string expected var actual = header.GetUnescapedValue(); - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -602,7 +602,7 @@ public void SetAndEscapeValue_ReturnsExpectedValue(string input, string expected var actual = header.Value; - Assert.Equal(expected, actual); + Assert.Equal(expected.AsSpan(), actual); } [Theory] @@ -628,7 +628,7 @@ public void GetAndSetEncodeValueRoundTrip_ReturnsExpectedValue(string input) var actual = header.Value; - Assert.Equal(input, actual); + Assert.Equal(input.AsSpan(), actual); } [Theory] @@ -673,7 +673,7 @@ private void CheckInvalidTryParse(string? input) private static void CheckValue(string? value) { var nameValue = new NameValueHeaderValue("text", value); - Assert.Equal(value, nameValue.Value); + Assert.Equal(value.AsSpan(), nameValue.Value); } private static void AssertFormatException(string name, string? value) diff --git a/src/Http/Headers/test/RangeHeaderValueTest.cs b/src/Http/Headers/test/RangeHeaderValueTest.cs index 624c07dafbd1..101759609c02 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -16,7 +16,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new RangeHeaderValue(); range.Unit = "myunit"; - Assert.Equal("myunit", range.Unit); + Assert.Equal("myunit".AsSpan(), range.Unit); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); diff --git a/src/Http/Headers/test/SetCookieHeaderValueTest.cs b/src/Http/Headers/test/SetCookieHeaderValueTest.cs index 05c6684feef9..7e53fad5e75c 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -318,8 +318,8 @@ public void SetCookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new SetCookieHeaderValue("cookie"); - Assert.Equal("cookie", header.Name); - Assert.Equal(string.Empty, header.Value); + Assert.Equal("cookie".AsSpan(), header.Name); + Assert.Equal(string.Empty.AsSpan(), header.Value); } [Theory] @@ -329,18 +329,18 @@ public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() public void SetCookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new SetCookieHeaderValue(name, value); - Assert.Equal(name, header.Name); - Assert.Equal(value, header.Value); + Assert.Equal(name.AsSpan(), header.Name); + Assert.Equal(value.AsSpan(), header.Value); } [Fact] public void SetCookieHeaderValue_Value() { var cookie = new SetCookieHeaderValue("name"); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); cookie.Value = "value1"; - Assert.Equal("value1", cookie.Value); + Assert.Equal("value1".AsSpan(), cookie.Value); } [Theory] diff --git a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs index 661114afbcfa..5a786b6b70a8 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -9,7 +9,7 @@ public class StringWithQualityHeaderValueTest public void Ctor_StringOnlyOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token"); - Assert.Equal("token", value.Value); + Assert.Equal("token".AsSpan(), value.Value); Assert.Null(value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null)); @@ -21,7 +21,7 @@ public void Ctor_StringOnlyOverload_MatchExpectation() public void Ctor_StringWithQualityOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token", 0.5); - Assert.Equal("token", value.Value); + Assert.Equal("token".AsSpan(), value.Value); Assert.Equal(0.5, value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null, 0.1)); diff --git a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs index ce171a6ec527..ebdb2fe0ad7d 100644 --- a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs +++ b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs @@ -64,8 +64,8 @@ public void CookieBuilder_Extensions_Added() Assert.Contains("key=value", options.Extensions); var cookie = options.CreateCookieHeader("name", "value"); - Assert.Equal("name", cookie.Name); - Assert.Equal("value", cookie.Value); + Assert.Equal("name".AsSpan(), cookie.Name); + Assert.Equal("value".AsSpan(), cookie.Value); Assert.Equal(2, cookie.Extensions.Count); Assert.Contains("simple", cookie.Extensions); Assert.Contains("key=value", cookie.Extensions); diff --git a/src/Http/WebUtilities/test/QueryHelpersTests.cs b/src/Http/WebUtilities/test/QueryHelpersTests.cs index 8707fe2411be..6f040e4146e4 100644 --- a/src/Http/WebUtilities/test/QueryHelpersTests.cs +++ b/src/Http/WebUtilities/test/QueryHelpersTests.cs @@ -30,7 +30,7 @@ public void ParseQueryWithDuplicateKeysGroups() { var collection = QueryHelpers.ParseQuery("?key1=valueA&key2=valueB&key1=valueC"); Assert.Equal(2, collection.Count); - Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"]); + Assert.Equal(new[] { "valueA", "valueC" }, collection["key1"].ToArray()); Assert.Equal("valueB", collection["key2"].FirstOrDefault()); } @@ -48,7 +48,7 @@ public void ParseQueryWithEmptyKeyWorks() { var collection = QueryHelpers.ParseQuery("?=value1&="); Assert.Single(collection); - Assert.Equal(new[] { "value1", "" }, collection[""]); + Assert.Equal(new[] { "value1", "" }, collection[""].ToArray()); } [Fact] @@ -88,7 +88,7 @@ public void ParseQueryWithEncodedKeyEncodedValuesWorks() { var collection = QueryHelpers.ParseQuery("?fields+%5BtodoItems%5D=%5B+1+%5D&fields+%5BtodoItems%5D=%5B+2+%5D"); Assert.Single(collection); - Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"]); + Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, collection["fields [todoItems]"].ToArray()); } [Theory] diff --git a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs index b7b3e8d95612..d4861a9a527b 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs @@ -284,8 +284,8 @@ public void SaveTempData_RemovesCookie_WhenNoDataToSave() Assert.Single(responseCookies); var cookie = responseCookies.Single(); Assert.NotNull(cookie); - Assert.Equal(CookieTempDataProvider.CookieName, cookie.Name); - Assert.Equal(string.Empty, cookie.Value); + Assert.Equal(CookieTempDataProvider.CookieName.AsSpan(), cookie.Name); + Assert.Equal(string.Empty.AsSpan(), cookie.Value); Assert.NotNull(cookie.Expires); Assert.True(cookie.Expires.Value < DateTimeOffset.Now); // expired cookie } diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs index f25096cc9acc..debdf250c46e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs @@ -80,7 +80,7 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) foreach (var cookieTempDataProviderCookie in cookieTempDataProviderCookies) { Assert.NotNull(cookieTempDataProviderCookie.Value.Value); - Assert.Equal("/", cookieTempDataProviderCookie.Path); + Assert.Equal("/".AsSpan(), cookieTempDataProviderCookie.Path); Assert.Null(cookieTempDataProviderCookie.Domain.Value); Assert.False(cookieTempDataProviderCookie.Secure); } @@ -97,8 +97,8 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeader => setCookieHeader.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeaderValue); - Assert.Equal(string.Empty, setCookieHeaderValue.Value); - Assert.Equal("/", setCookieHeaderValue.Path); + Assert.Equal(string.Empty.AsSpan(), setCookieHeaderValue.Value); + Assert.Equal("/".AsSpan(), setCookieHeaderValue.Path); Assert.Null(setCookieHeaderValue.Domain.Value); Assert.NotNull(setCookieHeaderValue.Expires); Assert.True(setCookieHeaderValue.Expires < DateTimeOffset.Now); // expired cookie @@ -130,7 +130,7 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); @@ -153,8 +153,8 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal(string.Empty, setCookieHeader.Value); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal(string.Empty.AsSpan(), setCookieHeader.Value); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.NotNull(setCookieHeader.Expires); Assert.True(setCookieHeader.Expires < DateTimeOffset.Now); // expired cookie @@ -183,7 +183,7 @@ public async Task CookieTempDataProviderCookie_DoesNotSetsSecureAttributeOnCooki .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/", setCookieHeader.Path); + Assert.Equal("/".AsSpan(), setCookieHeader.Path); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); diff --git a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs index abc76954193c..68d6e98ce124 100644 --- a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs +++ b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs @@ -441,15 +441,15 @@ public async Task ChallengeSetsNonceAndStateCookies(OpenIdConnectRedirectBehavio Assert.True(nonceCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(nonceCookie.HttpOnly); - Assert.Equal("/signin-oidc", nonceCookie.Path); - Assert.Equal("N", nonceCookie.Value); + Assert.Equal("/signin-oidc".AsSpan(), nonceCookie.Path); + Assert.Equal("N".AsSpan(), nonceCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.None, nonceCookie.SameSite); var correlationCookie = challengeCookies.Where(cookie => cookie.Name.StartsWith(".AspNetCore.Correlation.", StringComparison.Ordinal)).Single(); Assert.True(correlationCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(correlationCookie.HttpOnly); - Assert.Equal("/signin-oidc", correlationCookie.Path); + Assert.Equal("/signin-oidc".AsSpan(), correlationCookie.Path); Assert.False(StringSegment.IsNullOrEmpty(correlationCookie.Value)); Assert.Equal(Net.Http.Headers.SameSiteMode.None, correlationCookie.SameSite); @@ -847,7 +847,7 @@ public async Task Challenge_WithPushedAuthorization_Handled() var res = transaction.Response; Assert.Equal(HttpStatusCode.Redirect, res.StatusCode); - + Assert.Contains("request_uri=request_uri_from_event", res.Headers.Location.Query); Assert.Empty(mockBackchannel.PushedParameters); } diff --git a/src/Security/CookiePolicy/test/CookieConsentTests.cs b/src/Security/CookiePolicy/test/CookieConsentTests.cs index f5234ca0af2d..79905c22c9c6 100644 --- a/src/Security/CookiePolicy/test/CookieConsentTests.cs +++ b/src/Security/CookiePolicy/test/CookieConsentTests.cs @@ -217,15 +217,15 @@ public async Task GrantConsentSetsCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("yes", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("yes".AsSpan(), consentCookie.Value); Assert.True(consentCookie.Expires.HasValue); Assert.True(consentCookie.Expires.Value > DateTimeOffset.Now + TimeSpan.FromDays(364)); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); var testCookie = cookies[1]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("Value", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("Value".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); } @@ -239,8 +239,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnAppendCookie = context => { - Assert.Equal(".AspNet.Consent", context.CookieName); - Assert.Equal("yes", context.CookieValue); + Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); + Assert.Equal("yes".AsSpan(), context.CookieValue); Assert.Equal(Http.SameSiteMode.Strict, context.CookieOptions.SameSite); context.CookieName += "1"; context.CookieValue += "1"; @@ -267,8 +267,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("yes1", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("yes1".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); Assert.Contains("extension", consentCookie.Extensions); @@ -398,13 +398,13 @@ public async Task WithdrawConsentDeletesCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var testCookie = cookies[0]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("Value1", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("Value1".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); var consentCookie = cookies[1]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -418,7 +418,7 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnDeleteCookie = context => { - Assert.Equal(".AspNet.Consent", context.CookieName); + Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); context.CookieName += "1"; }; }, @@ -445,8 +445,8 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -510,8 +510,8 @@ public async Task DeleteCookieDoesNotRequireConsent() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var testCookie = cookies[0]; - Assert.Equal("Test", testCookie.Name); - Assert.Equal("", testCookie.Value); + Assert.Equal("Test".AsSpan(), testCookie.Name); + Assert.Equal("".AsSpan(), testCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.NotNull(testCookie.Expires); } @@ -574,8 +574,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("yes", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("yes".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -627,8 +627,8 @@ public async Task CreateConsentCookieAppliesPolicy() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1", consentCookie.Name); - Assert.Equal("yes1", consentCookie.Value); + Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); + Assert.Equal("yes1".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -672,8 +672,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookieWhenCookieValueIsC var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent", consentCookie.Name); - Assert.Equal("true", consentCookie.Value); + Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); + Assert.Equal("true".AsSpan(), consentCookie.Value); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); diff --git a/src/Security/CookiePolicy/test/CookiePolicyTests.cs b/src/Security/CookiePolicy/test/CookiePolicyTests.cs index d17decb80a64..30a55a961d55 100644 --- a/src/Security/CookiePolicy/test/CookiePolicyTests.cs +++ b/src/Security/CookiePolicy/test/CookiePolicyTests.cs @@ -58,10 +58,10 @@ await RunTest("/secureAlways", transaction => { Assert.NotNull(transaction.SetCookie); - Assert.Equal("A=A; path=/; secure", transaction.SetCookie[0]); - Assert.Equal("B=B; path=/; secure", transaction.SetCookie[1]); - Assert.Equal("C=C; path=/; secure", transaction.SetCookie[2]); - Assert.Equal("D=D; path=/; secure", transaction.SetCookie[3]); + Assert.Equal("A=A; path=/; secure".AsSpan(), transaction.SetCookie[0]); + Assert.Equal("B=B; path=/; secure".AsSpan(), transaction.SetCookie[1]); + Assert.Equal("C=C; path=/; secure".AsSpan(), transaction.SetCookie[2]); + Assert.Equal("D=D; path=/; secure".AsSpan(), transaction.SetCookie[3]); })); } @@ -398,10 +398,10 @@ public async Task CookiePolicyAppliesToCookieAuth() Assert.NotNull(transaction.SetCookie); Assert.Single(transaction.SetCookie); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie", cookie.Name); + Assert.Equal("TestCookie".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("extension", cookie.Extensions); } @@ -450,25 +450,25 @@ public async Task CookiePolicyAppliesToCookieAuthChunks() Assert.Equal(3, transaction.SetCookie.Count); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie", cookie.Name); - Assert.Equal("chunks-2", cookie.Value); + Assert.Equal("TestCookie".AsSpan(), cookie.Name); + Assert.Equal("chunks-2".AsSpan(), cookie.Value); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[1]); - Assert.Equal("TestCookieC1", cookie.Name); + Assert.Equal("TestCookieC1".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[2]); - Assert.Equal("TestCookieC2", cookie.Name); + Assert.Equal("TestCookieC2".AsSpan(), cookie.Name); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/", cookie.Path); + Assert.Equal("/".AsSpan(), cookie.Path); Assert.Contains("ext", cookie.Extensions); } diff --git a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs index 2edf4628129e..23a4ca0e3fd3 100644 --- a/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs +++ b/src/Servers/Kestrel/Core/test/Http2/Http2HPackEncoderTests.cs @@ -486,7 +486,7 @@ public void EncodesHeadersInSinglePayloadWhenSpaceAvailable(KeyValuePair(payload, 0, length)); + Assert.Equal(expectedPayload, new ArraySegment(payload, 0, length).ToArray()); } [Theory] From d685379239c58f616efa71a8a1b96be5220a978a Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 13:56:42 -0800 Subject: [PATCH 06/18] Fix arrays --- src/Http/Http/test/Features/QueryFeatureTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Http/Http/test/Features/QueryFeatureTests.cs b/src/Http/Http/test/Features/QueryFeatureTests.cs index 9e19f7f9df27..2094eeadd8b0 100644 --- a/src/Http/Http/test/Features/QueryFeatureTests.cs +++ b/src/Http/Http/test/Features/QueryFeatureTests.cs @@ -84,7 +84,7 @@ public void ParseQueryWithEmptyKeyWorks() var queryCollection = provider.Query; Assert.Single(queryCollection); - Assert.Equal(new[] { "value1", "" }, queryCollection[""]); + Assert.Equal(new[] { "value1", "" }, queryCollection[""].ToArray()); } [Fact] @@ -98,7 +98,7 @@ public void ParseQueryWithDuplicateKeysGroups() var queryCollection = provider.Query; Assert.Equal(2, queryCollection.Count); - Assert.Equal(new[] { "valueA", "valueC" }, queryCollection["key1"]); + Assert.Equal(new[] { "valueA", "valueC" }, queryCollection["key1"].ToArray()); Assert.Equal("valueB", queryCollection["key2"].FirstOrDefault()); } @@ -113,7 +113,7 @@ public void ParseQueryWithThreefoldKeysGroups() var queryCollection = provider.Query; Assert.Equal(2, queryCollection.Count); - Assert.Equal(new[] { "valueA", "valueC", "valueD" }, queryCollection["key1"]); + Assert.Equal(new[] { "valueA", "valueC", "valueD" }, queryCollection["key1"].ToArray()); Assert.Equal("valueB", queryCollection["key2"].FirstOrDefault()); } From 286f5f6d1fa7653872374815e89c1c61fd3a5662 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 14:23:17 -0800 Subject: [PATCH 07/18] Fix Http tests --- src/Http/Http/test/Features/QueryFeatureTests.cs | 6 +++--- src/Http/Http/test/Internal/DefaultHttpRequestTests.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Http/Http/test/Features/QueryFeatureTests.cs b/src/Http/Http/test/Features/QueryFeatureTests.cs index 2094eeadd8b0..17479bd069c1 100644 --- a/src/Http/Http/test/Features/QueryFeatureTests.cs +++ b/src/Http/Http/test/Features/QueryFeatureTests.cs @@ -215,7 +215,7 @@ public void ParseQueryWithEncodedKeyEncodedValuesWorks() var queryCollection = provider.Query; Assert.Single(queryCollection); - Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, queryCollection["fields [todoItems]"]); + Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, queryCollection["fields [todoItems]"].ToArray()); } [Fact] @@ -234,7 +234,7 @@ public void CaseInsensitiveWithManyKeys() var queryCollection = provider.Query; Assert.Equal(12, queryCollection.Count); - Assert.Equal(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }, queryCollection["KEY"]); + Assert.Equal(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }, queryCollection["KEY"].ToArray()); } [Fact] @@ -249,6 +249,6 @@ public void CaseInsensitiveWithFewKeys() var queryCollection = provider.Query; Assert.Equal(1, queryCollection.Count); - Assert.Equal(new[] { "1", "2", "3", "4", "5" }, queryCollection["KEY"]); + Assert.Equal(new[] { "1", "2", "3", "4", "5" }, queryCollection["KEY"].ToArray()); } } diff --git a/src/Http/Http/test/Internal/DefaultHttpRequestTests.cs b/src/Http/Http/test/Internal/DefaultHttpRequestTests.cs index 7575b4136bc8..cb7d548d4507 100644 --- a/src/Http/Http/test/Internal/DefaultHttpRequestTests.cs +++ b/src/Http/Http/test/Internal/DefaultHttpRequestTests.cs @@ -180,7 +180,7 @@ public void Cookies_GetAndSet() Assert.Equal(2, cookies1.Count); Assert.Equal("value0,", cookies1["name0"]); Assert.Equal("value1", cookies1["name1"]); - Assert.Equal(newCookies, request.Headers["Cookie"]); + Assert.Equal(newCookies, request.Headers["Cookie"].ToArray()); var cookies2 = new RequestCookieCollection(new Dictionary() { @@ -190,7 +190,7 @@ public void Cookies_GetAndSet() Assert.Equal(cookies2, request.Cookies); Assert.Equal("value2", request.Cookies["name2"]); cookieHeaders = request.Headers["Cookie"]; - Assert.Equal(new[] { "name2=value2" }, cookieHeaders); + Assert.Equal(new[] { "name2=value2" }, cookieHeaders.ToArray()); } [Fact] From 218022af1f816a9a9293868365058ca31ba02f2c Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 15:33:51 -0800 Subject: [PATCH 08/18] Fix more errors --- .../Cng/CbcAuthenticatedEncryptorTests.cs | 2 +- .../Cng/GcmAuthenticatedEncryptorTests.cs | 2 +- .../Managed/ManagedAuthenticatedEncryptorTests.cs | 2 +- .../test/HeaderPropagationMiddlewareTest.cs | 8 ++++---- .../OutputCaching/test/OutputCachePoliciesTests.cs | 6 +++--- .../test/ModelBinding/ValueProviderResultTest.cs | 2 +- .../test/ModelBinding/EnumerableValueProviderTest.cs | 4 ++-- .../test/Rendering/HtmlHelperPasswordTest.cs | 4 ++-- .../Runtime/TagHelpers/TagHelperExecutionContextTest.cs | 3 +-- src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs | 3 +-- src/Security/CookiePolicy/test/CookieChunkingTests.cs | 8 ++++---- src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs | 6 +++--- 12 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs index 9285ba471d78..ef8a921f2bae 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/CbcAuthenticatedEncryptorTests.cs @@ -29,7 +29,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext.AsSpan()); } [ConditionalFact] diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs index 90091ac3c3cc..8d60ed6876c3 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs @@ -26,7 +26,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext.AsSpan()); } [ConditionalFact] diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs index ffb742e4ca5a..e49a4ef4cfa8 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Managed/ManagedAuthenticatedEncryptorTests.cs @@ -25,7 +25,7 @@ public void Encrypt_Decrypt_RoundTrips() byte[] decipheredtext = encryptor.Decrypt(new ArraySegment(ciphertext), aad); // Assert - Assert.Equal(plaintext.AsSpan(), decipheredtext); + Assert.Equal(plaintext.AsSpan(), decipheredtext.AsSpan()); } [Fact] diff --git a/src/Middleware/HeaderPropagation/test/HeaderPropagationMiddlewareTest.cs b/src/Middleware/HeaderPropagation/test/HeaderPropagationMiddlewareTest.cs index e42c2a1f276f..20706ec71fbe 100644 --- a/src/Middleware/HeaderPropagation/test/HeaderPropagationMiddlewareTest.cs +++ b/src/Middleware/HeaderPropagation/test/HeaderPropagationMiddlewareTest.cs @@ -44,7 +44,7 @@ public async Task HeaderInRequest_AddCorrectValue() // Assert Assert.Contains("in", CapturedHeaders.Keys); - Assert.Equal(new[] { "test" }, CapturedHeaders["in"]); + Assert.Equal(new[] { "test" }, CapturedHeaders["in"].ToArray()); } [Fact] @@ -87,9 +87,9 @@ public async Task MultipleHeadersInRequest_AddAllHeaders() // Assert Assert.Contains("in", CapturedHeaders.Keys); - Assert.Equal(new[] { "test" }, CapturedHeaders["in"]); + Assert.Equal(new[] { "test" }, CapturedHeaders["in"].ToArray()); Assert.Contains("another", CapturedHeaders.Keys); - Assert.Equal(new[] { "test2" }, CapturedHeaders["another"]); + Assert.Equal(new[] { "test2" }, CapturedHeaders["another"].ToArray()); } [Theory] @@ -132,7 +132,7 @@ public async Task UsesValueFilter(string[] filterValues, string[] expectedValues // Assert Assert.Contains("in", CapturedHeaders.Keys); - Assert.Equal(expectedValues, CapturedHeaders["in"]); + Assert.Equal(expectedValues, CapturedHeaders["in"].ToArray()); Assert.Equal("in", receivedName); Assert.Equal(new StringValues("value"), receivedValue); Assert.Same(Context, receivedContext); diff --git a/src/Middleware/OutputCaching/test/OutputCachePoliciesTests.cs b/src/Middleware/OutputCaching/test/OutputCachePoliciesTests.cs index 887455305f13..7279c07500ed 100644 --- a/src/Middleware/OutputCaching/test/OutputCachePoliciesTests.cs +++ b/src/Middleware/OutputCaching/test/OutputCachePoliciesTests.cs @@ -214,7 +214,7 @@ public async Task VaryByHeadersPolicy_AddsMultipleHeaders() await policy.CacheRequestAsync(context, default); - Assert.Equal(headers, context.CacheVaryByRules.HeaderNames); + Assert.Equal(headers, context.CacheVaryByRules.HeaderNames.ToArray()); } [Fact] @@ -252,7 +252,7 @@ public async Task VaryByQueryPolicy_AddsMultipleHeaders() await policy.CacheRequestAsync(context, default); - Assert.Equal(queries, context.CacheVaryByRules.QueryKeys); + Assert.Equal(queries, context.CacheVaryByRules.QueryKeys.ToArray()); } [Fact] @@ -265,7 +265,7 @@ public async Task VaryByQueryPolicy_AddsMultipleHeadersArray() await policy.CacheRequestAsync(context, default); - Assert.Equal(queries, context.CacheVaryByRules.QueryKeys); + Assert.Equal(queries, context.CacheVaryByRules.QueryKeys.ToArray()); } [Fact] diff --git a/src/Mvc/Mvc.Abstractions/test/ModelBinding/ValueProviderResultTest.cs b/src/Mvc/Mvc.Abstractions/test/ModelBinding/ValueProviderResultTest.cs index 4f11baf8f14e..544db549bfc3 100644 --- a/src/Mvc/Mvc.Abstractions/test/ModelBinding/ValueProviderResultTest.cs +++ b/src/Mvc/Mvc.Abstractions/test/ModelBinding/ValueProviderResultTest.cs @@ -76,7 +76,7 @@ public void Construct_With_Array() // Assert Assert.Equal(2, result.Length); - Assert.Equal(new string[] { "Hi", "There" }, result.Values); + Assert.Equal(new string[] { "Hi", "There" }, result.Values.ToArray()); Assert.Equal("Hi", result.FirstValue); Assert.NotEqual(ValueProviderResult.None, result); Assert.Equal("Hi,There", (string)result); diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/EnumerableValueProviderTest.cs b/src/Mvc/Mvc.Core/test/ModelBinding/EnumerableValueProviderTest.cs index c1c9aec765dd..b1c2613f4f7e 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/EnumerableValueProviderTest.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/EnumerableValueProviderTest.cs @@ -179,7 +179,7 @@ public void GetValue_MultiValue() var result = valueProvider.GetValue("some"); // Assert - Assert.Equal(new[] { "someValue1", "someValue2" }, result.Values); + Assert.Equal(new[] { "someValue1", "someValue2" }, result.Values.ToArray()); Assert.Equal("someValue1,someValue2", (string)result); Assert.Equal(culture, result.Culture); } @@ -215,7 +215,7 @@ public void GetValue_NullMultipleValue() var result = valueProvider.GetValue("key"); // Assert - Assert.Equal(new[] { null, null, "value" }, result.Values); + Assert.Equal(new[] { null, null, "value" }, result.Values.ToArray()); } [Fact] diff --git a/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs b/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs index 81ff8931a882..0ecbdd634746 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs @@ -44,8 +44,8 @@ public static TheoryData, object> PasswordWith var data = new TheoryData, object>(); foreach (var items in HtmlAttributeData) { - data.Add(viewData, items[0]); - data.Add(nullModelViewData, items[0]); + data.Add(viewData, items.ToArray()); + data.Add(nullModelViewData, items.ToArray()); } return data; diff --git a/src/Razor/Razor.Runtime/test/Runtime/TagHelpers/TagHelperExecutionContextTest.cs b/src/Razor/Razor.Runtime/test/Runtime/TagHelpers/TagHelperExecutionContextTest.cs index 64b14d365deb..1bc5f9967561 100644 --- a/src/Razor/Razor.Runtime/test/Runtime/TagHelpers/TagHelperExecutionContextTest.cs +++ b/src/Razor/Razor.Runtime/test/Runtime/TagHelpers/TagHelperExecutionContextTest.cs @@ -245,9 +245,8 @@ public static TheoryData HtmlEncoderDataLessNull get { var data = new TheoryData(); - foreach (var row in HtmlEncoderData) + foreach (var encoder in HtmlEncoderData) { - var encoder = (HtmlEncoder)(row[0]); if (encoder != null) { data.Add(encoder); diff --git a/src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs b/src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs index 10a023825330..f80efdf608f3 100644 --- a/src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs +++ b/src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs @@ -164,9 +164,8 @@ public static TheoryData UseCachedResultAndHtmlEncoderData var data = new TheoryData(); foreach (var useCachedResult in new[] { false, true }) { - foreach (var encoderEntry in HtmlEncoderData) + foreach (var encoder in HtmlEncoderData) { - var encoder = (HtmlEncoder)(encoderEntry[0]); data.Add(useCachedResult, encoder); } } diff --git a/src/Security/CookiePolicy/test/CookieChunkingTests.cs b/src/Security/CookiePolicy/test/CookieChunkingTests.cs index c0a841fe4f85..3b8cc719d6d5 100644 --- a/src/Security/CookiePolicy/test/CookieChunkingTests.cs +++ b/src/Security/CookiePolicy/test/CookieChunkingTests.cs @@ -223,7 +223,7 @@ public void DeleteChunkedCookieWithOptions_AllDeleted() "TestCookieC5=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension", "TestCookieC6=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension", "TestCookieC7=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension", - }, cookies); + }, cookies.ToArray()); } [Fact] @@ -240,7 +240,7 @@ public void DeleteChunkedCookieWithMissingRequestCookies_OnlyPresentCookiesDelet "TestCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", "TestCookieC1=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", "TestCookieC2=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", - }, cookies); + }, cookies.ToArray()); } [Fact] @@ -258,7 +258,7 @@ public void DeleteChunkedCookieWithMissingRequestCookies_StopsAtMissingChunk() "TestCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", "TestCookieC1=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", "TestCookieC2=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure", - }, cookies); + }, cookies.ToArray()); } [Fact] @@ -311,6 +311,6 @@ public void DeleteChunkedCookieWithOptionsAndResponseCookies_AllDeleted() "TestCookieC5=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension", "TestCookieC6=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension", "TestCookieC7=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=foo.com; path=/; secure; extension" - }, httpContext.Response.Headers[HeaderNames.SetCookie]); + }, httpContext.Response.Headers[HeaderNames.SetCookie].ToArray()); } } diff --git a/src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs b/src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs index 6e3d988617d4..7a9b6dea0f78 100644 --- a/src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs +++ b/src/Servers/Kestrel/Core/test/HttpRequestHeadersTests.cs @@ -379,13 +379,13 @@ public void CopyToMovesDataIntoArray() Assert.Equal(new StringValues(), entries[0].Value); Assert.Equal("Host", entries[1].Key); - Assert.Equal(new[] { "localhost" }, entries[1].Value); + Assert.Equal(new[] { "localhost" }, entries[1].Value.ToArray()); Assert.Equal("Content-Length", entries[2].Key); - Assert.Equal(new[] { "0" }, entries[2].Value); + Assert.Equal(new[] { "0" }, entries[2].Value.ToArray()); Assert.Equal("custom", entries[3].Key); - Assert.Equal(new[] { "value" }, entries[3].Value); + Assert.Equal(new[] { "value" }, entries[3].Value.ToArray()); Assert.Null(entries[4].Key); Assert.Equal(new StringValues(), entries[4].Value); From 2149d9c5d2cc9f38c79fa16f4eac6092e25b7b7e Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 4 Nov 2024 15:46:08 -0800 Subject: [PATCH 09/18] Fix MVC --- .../Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs b/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs index 0ecbdd634746..caa11d372f06 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/Rendering/HtmlHelperPasswordTest.cs @@ -44,8 +44,8 @@ public static TheoryData, object> PasswordWith var data = new TheoryData, object>(); foreach (var items in HtmlAttributeData) { - data.Add(viewData, items.ToArray()); - data.Add(nullModelViewData, items.ToArray()); + data.Add(viewData, items); + data.Add(nullModelViewData, items); } return data; From 57a5d9714974c57336621f6f9c930dd7eea57cdf Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 5 Nov 2024 18:48:31 -0600 Subject: [PATCH 10/18] Flip around where AsSpan is called with string comparisons in tests. --- .../Cng/GcmAuthenticatedEncryptorTests.cs | 2 +- .../KeyRingBasedDataProtectorTests.cs | 24 ++--- .../test/CacheControlHeaderValueTest.cs | 4 +- .../test/ContentDispositionHeaderValueTest.cs | 94 +++++++++---------- .../test/ContentRangeHeaderValueTest.cs | 12 +-- .../Headers/test/CookieHeaderValueTest.cs | 12 +-- .../Headers/test/MediaTypeHeaderValueTest.cs | 28 +++--- .../Headers/test/NameValueHeaderValueTest.cs | 18 ++-- src/Http/Headers/test/RangeHeaderValueTest.cs | 2 +- .../Headers/test/SetCookieHeaderValueTest.cs | 12 +-- .../test/StringWithQualityHeaderValueTest.cs | 4 +- .../test/CookieBuilderTests.cs | 4 +- .../test/CookieTempDataProviderTest.cs | 4 +- .../TempDataInCookiesTest.cs | 14 +-- .../OpenIdConnectChallengeTests.cs | 6 +- .../CookiePolicy/test/CookieConsentTests.cs | 46 ++++----- .../CookiePolicy/test/CookiePolicyTests.cs | 26 ++--- 17 files changed, 156 insertions(+), 156 deletions(-) diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs index 8d60ed6876c3..15b8a2fd1bb1 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Cng/GcmAuthenticatedEncryptorTests.cs @@ -100,6 +100,6 @@ public void Encrypt_KnownKey() // | 00 00 00 00 (postBuffer) string retValAsString = Convert.ToBase64String(retVal); - Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA".AsSpan(), retValAsString); + Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA", retValAsString); } } diff --git a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs index a1716d03a773..d63a5cdd3d12 100644 --- a/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs +++ b/src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingBasedDataProtectorTests.cs @@ -45,8 +45,8 @@ public void Protect_EncryptsToDefaultProtector_MultiplePurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -83,8 +83,8 @@ public void Protect_EncryptsToDefaultProtector_SinglePurpose() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); @@ -423,8 +423,8 @@ public void Unprotect_KeyRevoked_RevocationAllowed_ReturnsOriginalData_SetsRevok .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -470,8 +470,8 @@ public void Unprotect_IsAlsoDefaultKey_Success_NoMigrationRequired() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -519,8 +519,8 @@ public void Unprotect_IsNotDefaultKey_Success_RequiresMigration() .Setup(o => o.Decrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualCiphertext, actualAad) => { - Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return expectedPlaintext; }); var mockDescriptor = new Mock(); @@ -594,8 +594,8 @@ public void CreateProtector_ChainsPurposes() .Setup(o => o.Encrypt(It.IsAny>(), It.IsAny>())) .Returns, ArraySegment>((actualPlaintext, actualAad) => { - Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext); - Assert.Equal(expectedAad.AsSpan(), actualAad); + Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan()); + Assert.Equal(expectedAad, actualAad.AsSpan()); return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag }); diff --git a/src/Http/Headers/test/CacheControlHeaderValueTest.cs b/src/Http/Headers/test/CacheControlHeaderValueTest.cs index 8887a0ed1324..1f407cc2177d 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter() Assert.Throws(() => cacheControl.NoCacheHeaders.Add("invalid PLACEHOLDER")); cacheControl.NoCacheHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.NoCacheHeaders); - Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.NoCacheHeaders.First()); + Assert.Equal("PLACEHOLDER", cacheControl.NoCacheHeaders.First().AsSpan()); Assert.NotNull(cacheControl.PrivateHeaders); Assert.Throws(() => cacheControl.PrivateHeaders.Add(null)); Assert.Throws(() => cacheControl.PrivateHeaders.Add("invalid PLACEHOLDER")); cacheControl.PrivateHeaders.Add("PLACEHOLDER"); Assert.Single(cacheControl.PrivateHeaders); - Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.PrivateHeaders.First()); + Assert.Equal("PLACEHOLDER", cacheControl.PrivateHeaders.First().AsSpan()); // NameValueHeaderValue collection property Assert.NotNull(cacheControl.Extensions); diff --git a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs index ea56680307c4..f153018b0b0b 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -42,7 +42,7 @@ public void Ctor_ContentDispositionInvalidFormat_ThrowFormatException() public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("inline", contentDisposition.DispositionType.AsSpan()); Assert.Empty(contentDisposition.Parameters); Assert.Null(contentDisposition.Name.Value); Assert.Null(contentDisposition.FileName.Value); @@ -63,10 +63,10 @@ public void Parameters_AddNull_Throw() public void ContentDisposition_SetAndGetContentDisposition_MatchExpectations() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Equal("inline".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("inline", contentDisposition.DispositionType.AsSpan()); contentDisposition.DispositionType = "attachment"; - Assert.Equal("attachment".AsSpan(), contentDisposition.DispositionType); + Assert.Equal("attachment", contentDisposition.DispositionType.AsSpan()); } [Fact] @@ -74,9 +74,9 @@ public void Name_SetNameAndValidateObject_ParametersEntryForNameAdded() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.Name = "myname"; - Assert.Equal("myname".AsSpan(), contentDisposition.Name); + Assert.Equal("myname", contentDisposition.Name.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("name".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("name", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Name = null; Assert.Null(contentDisposition.Name.Value); @@ -93,12 +93,12 @@ public void Name_AddNameParameterThenUseProperty_ParametersEntryIsOverwritten() NameValueHeaderValue name = new NameValueHeaderValue("NAME", "old_name"); contentDisposition.Parameters.Add(name); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("NAME", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Name = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.Name); + Assert.Equal("new_name", contentDisposition.Name.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("NAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("NAME", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(name); Assert.Null(contentDisposition.Name.Value); @@ -113,12 +113,12 @@ public void FileName_AddNameParameterThenUseProperty_ParametersEntryIsOverwritte var fileName = new NameValueHeaderValue("FILENAME", "old_name"); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); + Assert.Equal("new_name", contentDisposition.FileName.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -130,10 +130,10 @@ public void FileName_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "FileÃName.bat"; - Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileName); + Assert.Equal("FileÃName.bat", contentDisposition.FileName.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("\"=?utf-8?B?RmlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value.AsSpan()); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -145,10 +145,10 @@ public void FileName_NeedsEncodingBecauseOfNewLine_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileName = "File\nName.bat"; - Assert.Equal("File\nName.bat".AsSpan(), contentDisposition.FileName); + Assert.Equal("File\nName.bat", contentDisposition.FileName.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("\"=?utf-8?B?RmlsZQpOYW1lLmJhdA==?=\"", contentDisposition.Parameters.First().Value.AsSpan()); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileName.Value); @@ -163,14 +163,14 @@ public void FileName_UnknownOrBadEncoding_PropertyFails() var fileName = new NameValueHeaderValue("FILENAME", "\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\""); contentDisposition.Parameters.Add(fileName); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"".AsSpan(), contentDisposition.Parameters.First().Value); - Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=".AsSpan(), contentDisposition.FileName); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("\"=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=\"", contentDisposition.Parameters.First().Value.AsSpan()); + Assert.Equal("=?utf-99?Q?R=mlsZcODTmFtZS5iYXQ=?=", contentDisposition.FileName.AsSpan()); contentDisposition.FileName = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileName); + Assert.Equal("new_name", contentDisposition.FileName.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(fileName); Assert.Null(contentDisposition.FileName.Value); @@ -185,14 +185,14 @@ public void FileNameStar_AddNameParameterThenUseProperty_ParametersEntryIsOverwr var fileNameStar = new NameValueHeaderValue("FILENAME*", "old_name"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name.AsSpan()); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("new_name", contentDisposition.FileNameStar.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'new_name".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("UTF-8\'\'new_name", contentDisposition.Parameters.First().Value.AsSpan()); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -204,10 +204,10 @@ public void FileNameStar_NeedsEncoding_EncodedAndDecodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "FileÃName.bat"; - Assert.Equal("FileÃName.bat".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("FileÃName.bat", contentDisposition.FileNameStar.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("filename*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("UTF-8\'\'File%C3%83Name.bat".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("filename*", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("UTF-8\'\'File%C3%83Name.bat", contentDisposition.Parameters.First().Value.AsSpan()); contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); Assert.Null(contentDisposition.FileNameStar.Value); @@ -218,7 +218,7 @@ public void NonValidAscii_WhenNeedsEncoding_UsesHex() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = "a\u0080b"; - Assert.Equal($"UTF-8\'\'a%C2%80b".AsSpan(), contentDisposition.Parameters.First().Value); //%C2 added because the value in UTF-8 is encoded on 2 bytes. + Assert.Equal($"UTF-8\'\'a%C2%80b", contentDisposition.Parameters.First().Value.AsSpan()); //%C2 added because the value in UTF-8 is encoded on 2 bytes. } [Fact] @@ -226,7 +226,7 @@ public void LongValidAscii_FullyProcessedWithout() { var contentDisposition = new ContentDispositionHeaderValue("inline"); contentDisposition.FileNameStar = new string('a', 400); // 400 is larger to the max stackallow size - Assert.Equal($"UTF-8\'\'{new string('a', 400)}".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'{new string('a', 400)}", contentDisposition.Parameters.First().Value.AsSpan()); } [Fact] @@ -250,11 +250,11 @@ public void FileNameStar_WhenNeedsEncoding_UsesHex() || b >= 0x7F) { var hexC = Convert.ToHexString([b]); - Assert.Equal($"UTF-8\'\'a%{hexC}b".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a%{hexC}b", contentDisposition.Parameters.First().Value.AsSpan()); } else { - Assert.Equal($"UTF-8\'\'a{(char)b}b".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal($"UTF-8\'\'a{(char)b}b", contentDisposition.Parameters.First().Value.AsSpan()); } contentDisposition.Parameters.Remove(contentDisposition.Parameters.First()); } @@ -269,14 +269,14 @@ public void FileNameStar_UnknownOrBadEncoding_PropertyFails() var fileNameStar = new NameValueHeaderValue("FILENAME*", "utf-99'lang'File%CZName.bat"); contentDisposition.Parameters.Add(fileNameStar); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("utf-99'lang'File%CZName.bat".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("utf-99'lang'File%CZName.bat", contentDisposition.Parameters.First().Value.AsSpan()); Assert.Null(contentDisposition.FileNameStar.Value); // Decode failure contentDisposition.FileNameStar = "new_name"; - Assert.Equal("new_name".AsSpan(), contentDisposition.FileNameStar); + Assert.Equal("new_name", contentDisposition.FileNameStar.AsSpan()); Assert.Single(contentDisposition.Parameters); - Assert.Equal("FILENAME*".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("FILENAME*", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(fileNameStar); Assert.Null(contentDisposition.FileNameStar.Value); @@ -310,7 +310,7 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() var dateParameter = new NameValueHeaderValue("Creation-DATE", validDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name.AsSpan()); Assert.Equal(validDate, contentDisposition.CreationDate); @@ -318,8 +318,8 @@ public void Dates_AddDateParameterThenUseProperty_ParametersEntryIsOverwritten() contentDisposition.CreationDate = newDate; Assert.Equal(newDate, contentDisposition.CreationDate); Assert.Single(contentDisposition.Parameters); - Assert.Equal("Creation-DATE".AsSpan(), contentDisposition.Parameters.First().Name); - Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"".AsSpan(), contentDisposition.Parameters.First().Value); + Assert.Equal("Creation-DATE", contentDisposition.Parameters.First().Name.AsSpan()); + Assert.Equal("\"Tue, 15 Nov 1994 08:12:32 GMT\"", contentDisposition.Parameters.First().Value.AsSpan()); contentDisposition.Parameters.Remove(dateParameter); Assert.Null(contentDisposition.CreationDate); @@ -336,7 +336,7 @@ public void Dates_InvalidDates_PropertyFails() var dateParameter = new NameValueHeaderValue("read-DATE", invalidDateString); contentDisposition.Parameters.Add(dateParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("read-DATE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("read-DATE", contentDisposition.Parameters.First().Name.AsSpan()); Assert.Null(contentDisposition.ReadDate); @@ -354,13 +354,13 @@ public void Size_AddSizeParameterThenUseProperty_ParametersEntryIsOverwritten() var sizeParameter = new NameValueHeaderValue("SIZE", "279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name.AsSpan()); Assert.Equal(279172874239, contentDisposition.Size); contentDisposition.Size = 279172874240; Assert.Equal(279172874240, contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -375,14 +375,14 @@ public void Size_InvalidSizes_PropertyFails() var sizeParameter = new NameValueHeaderValue("SIZE", "-279172874239"); contentDisposition.Parameters.Add(sizeParameter); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name.AsSpan()); Assert.Null(contentDisposition.Size); // Negatives not allowed Assert.Throws(() => contentDisposition.Size = -279172874240); Assert.Null(contentDisposition.Size); Assert.Single(contentDisposition.Parameters); - Assert.Equal("SIZE".AsSpan(), contentDisposition.Parameters.First().Name); + Assert.Equal("SIZE", contentDisposition.Parameters.First().Name.AsSpan()); contentDisposition.Parameters.Remove(sizeParameter); Assert.Null(contentDisposition.Size); @@ -655,9 +655,9 @@ public void FileNameWithSurrogatePairs_EncodedCorrectly() var contentDisposition = new ContentDispositionHeaderValue("attachment"); contentDisposition.SetHttpFileName("File 🤩 name.txt"); - Assert.Equal("File __ name.txt".AsSpan(), contentDisposition.FileName); + Assert.Equal("File __ name.txt", contentDisposition.FileName.AsSpan()); Assert.Equal(2, contentDisposition.Parameters.Count); - Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt".AsSpan(), contentDisposition.Parameters[1].Value); + Assert.Equal("UTF-8\'\'File%20%F0%9F%A4%A9%20name.txt", contentDisposition.Parameters[1].Value.AsSpan()); } public class ContentDispositionValue diff --git a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs index 9036835059fd..f07823971549 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -18,7 +18,7 @@ public void Ctor_LengthOnlyOverloadValidValues_ValuesCorrectlySet() Assert.False(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit.AsSpan()); Assert.Null(range.From); Assert.Null(range.To); Assert.Equal(5, range.Length); @@ -39,7 +39,7 @@ public void Ctor_FromAndToOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.False(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit.AsSpan()); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Null(range.Length); @@ -63,7 +63,7 @@ public void Ctor_FromToAndLengthOverloadValidValues_ValuesCorrectlySet() Assert.True(range.HasRange, "HasRange"); Assert.True(range.HasLength, "HasLength"); - Assert.Equal("bytes".AsSpan(), range.Unit); + Assert.Equal("bytes", range.Unit.AsSpan()); Assert.Equal(0, range.From); Assert.Equal(1, range.To); Assert.Equal(2, range.Length); @@ -74,7 +74,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new ContentRangeHeaderValue(0); range.Unit = "myunit"; - Assert.Equal("myunit".AsSpan(), range.Unit); + Assert.Equal("myunit", range.Unit.AsSpan()); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); @@ -156,7 +156,7 @@ public void Parse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. var result = ContentRangeHeaderValue.Parse("bytes */*"); - Assert.Equal("bytes".AsSpan(), result.Unit); + Assert.Equal("bytes", result.Unit.AsSpan()); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); @@ -187,7 +187,7 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result)); - Assert.Equal("bytes".AsSpan(), result.Unit); + Assert.Equal("bytes", result.Unit.AsSpan()); Assert.Null(result.From); Assert.Null(result.To); Assert.Null(result.Length); diff --git a/src/Http/Headers/test/CookieHeaderValueTest.cs b/src/Http/Headers/test/CookieHeaderValueTest.cs index b212aae88e00..aa64816f35dc 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -172,8 +172,8 @@ public void CookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void CookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new CookieHeaderValue("cookie"); - Assert.Equal("cookie".AsSpan(), header.Name); - Assert.Equal(string.Empty.AsSpan(), header.Value); + Assert.Equal("cookie", header.Name.AsSpan()); + Assert.Equal(string.Empty, header.Value.AsSpan()); } [Theory] @@ -183,18 +183,18 @@ public void CookieHeaderValue_Ctor1_InitializesCorrectly() public void CookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new CookieHeaderValue(name, value); - Assert.Equal(name.AsSpan(), header.Name); - Assert.Equal(value.AsSpan(), header.Value); + Assert.Equal(name, header.Name.AsSpan()); + Assert.Equal(value, header.Value.AsSpan()); } [Fact] public void CookieHeaderValue_Value() { var cookie = new CookieHeaderValue("name"); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(string.Empty, cookie.Value.AsSpan()); cookie.Value = "value1"; - Assert.Equal("value1".AsSpan(), cookie.Value); + Assert.Equal("value1", cookie.Value.AsSpan()); } [Theory] diff --git a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs index 67191c746936..77bcf89a4d8c 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -102,7 +102,7 @@ public void MatchesAllSubTypesWithoutSuffix_ReturnsExpectedResult(string value, public void Ctor_MediaTypeValidFormat_SuccessfullyCreated() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); + Assert.Equal("text/plain", mediaType.MediaType.AsSpan()); Assert.Empty(mediaType.Parameters); Assert.Null(mediaType.Charset.Value); } @@ -112,7 +112,7 @@ public void Ctor_AddNameAndQuality_QualityParameterAdded() { var mediaType = new MediaTypeHeaderValue("application/xml", 0.08); Assert.Equal(0.08, mediaType.Quality); - Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); + Assert.Equal("application/xml", mediaType.MediaType.AsSpan()); Assert.Single(mediaType.Parameters); } @@ -221,10 +221,10 @@ public void CopyFromReadOnly_WithParameters_CopiedAsNonReadOnly() public void MediaType_SetAndGetMediaType_MatchExpectations() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Equal("text/plain".AsSpan(), mediaType.MediaType); + Assert.Equal("text/plain", mediaType.MediaType.AsSpan()); mediaType.MediaType = "application/xml"; - Assert.Equal("application/xml".AsSpan(), mediaType.MediaType); + Assert.Equal("application/xml", mediaType.MediaType.AsSpan()); } [Fact] @@ -232,9 +232,9 @@ public void Charset_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() { var mediaType = new MediaTypeHeaderValue("text/plain"); mediaType.Charset = "mycharset"; - Assert.Equal("mycharset".AsSpan(), mediaType.Charset); + Assert.Equal("mycharset", mediaType.Charset.AsSpan()); Assert.Single(mediaType.Parameters); - Assert.Equal("charset".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("charset", mediaType.Parameters.First().Name.AsSpan()); mediaType.Charset = null; Assert.Null(mediaType.Charset.Value); @@ -251,12 +251,12 @@ public void Charset_AddCharsetParameterThenUseProperty_ParametersEntryIsOverwrit var charset = new NameValueHeaderValue("CHARSET", "old_charset"); mediaType.Parameters.Add(charset); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("CHARSET", mediaType.Parameters.First().Name.AsSpan()); mediaType.Charset = "new_charset"; - Assert.Equal("new_charset".AsSpan(), mediaType.Charset); + Assert.Equal("new_charset", mediaType.Charset.AsSpan()); Assert.Single(mediaType.Parameters); - Assert.Equal("CHARSET".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("CHARSET", mediaType.Parameters.First().Name.AsSpan()); mediaType.Parameters.Remove(charset); Assert.Null(mediaType.Charset.Value); @@ -269,8 +269,8 @@ public void Quality_SetCharsetAndValidateObject_ParametersEntryForCharsetAdded() mediaType.Quality = 0.563156454; Assert.Equal(0.563, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); - Assert.Equal("0.563".AsSpan(), mediaType.Parameters.First().Value); + Assert.Equal("q", mediaType.Parameters.First().Name.AsSpan()); + Assert.Equal("0.563", mediaType.Parameters.First().Value.AsSpan()); mediaType.Quality = null; Assert.Null(mediaType.Quality); @@ -286,13 +286,13 @@ public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwrit var quality = new NameValueHeaderValue("q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("q", mediaType.Parameters.First().Name.AsSpan()); Assert.Equal(0.132, mediaType.Quality); mediaType.Quality = 0.9; Assert.Equal(0.9, mediaType.Quality); Assert.Single(mediaType.Parameters); - Assert.Equal("q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("q", mediaType.Parameters.First().Name.AsSpan()); mediaType.Parameters.Remove(quality); Assert.Null(mediaType.Quality); @@ -306,7 +306,7 @@ public void Quality_AddQualityParameterUpperCase_CaseInsensitiveComparison() var quality = new NameValueHeaderValue("Q", "0.132"); mediaType.Parameters.Add(quality); Assert.Single(mediaType.Parameters); - Assert.Equal("Q".AsSpan(), mediaType.Parameters.First().Name); + Assert.Equal("Q", mediaType.Parameters.First().Name.AsSpan()); Assert.Equal(0.132, mediaType.Quality); } diff --git a/src/Http/Headers/test/NameValueHeaderValueTest.cs b/src/Http/Headers/test/NameValueHeaderValueTest.cs index 2031b6a77391..20cd9f91e92e 100644 --- a/src/Http/Headers/test/NameValueHeaderValueTest.cs +++ b/src/Http/Headers/test/NameValueHeaderValueTest.cs @@ -29,7 +29,7 @@ public void Ctor_NameInvalidFormat_ThrowFormatException() public void Ctor_NameValidFormat_SuccessfullyCreated() { var nameValue = new NameValueHeaderValue("text", null); - Assert.Equal("text".AsSpan(), nameValue.Name); + Assert.Equal("text", nameValue.Name.AsSpan()); } [Fact] @@ -66,7 +66,7 @@ public void Copy_NameOnly_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("othervalue", pair0.Value.AsSpan()); Assert.Null(pair1.Value.Value); } @@ -84,7 +84,7 @@ public void CopyAsReadOnly_NameOnly_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); + Assert.Equal("othervalue", pair0.Value.AsSpan()); Assert.Null(pair1.Value.Value); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -100,8 +100,8 @@ public void Copy_NameAndValue_SuccessfullyCopied() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair0.Value.AsSpan()); + Assert.Equal("value", pair1.Value.AsSpan()); } [Fact] @@ -117,8 +117,8 @@ public void CopyAsReadOnly_NameAndValue_CopiedAndReadOnly() // Change one value and verify the other is unchanged. pair0.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair0.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair0.Value.AsSpan()); + Assert.Equal("value", pair1.Value.AsSpan()); Assert.Throws(() => { pair1.Value = "othervalue"; }); } @@ -134,8 +134,8 @@ public void CopyFromReadOnly_NameAndValue_CopiedAsNonReadOnly() // Change one value and verify the other is unchanged. pair2.Value = "othervalue"; - Assert.Equal("othervalue".AsSpan(), pair2.Value); - Assert.Equal("value".AsSpan(), pair1.Value); + Assert.Equal("othervalue", pair2.Value.AsSpan()); + Assert.Equal("value", pair1.Value.AsSpan()); } [Fact] diff --git a/src/Http/Headers/test/RangeHeaderValueTest.cs b/src/Http/Headers/test/RangeHeaderValueTest.cs index 101759609c02..1f2c60b1a81e 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -16,7 +16,7 @@ public void Unit_GetAndSetValidAndInvalidValues_MatchExpectation() { var range = new RangeHeaderValue(); range.Unit = "myunit"; - Assert.Equal("myunit".AsSpan(), range.Unit); + Assert.Equal("myunit", range.Unit.AsSpan()); Assert.Throws(() => range.Unit = null); Assert.Throws(() => range.Unit = ""); diff --git a/src/Http/Headers/test/SetCookieHeaderValueTest.cs b/src/Http/Headers/test/SetCookieHeaderValueTest.cs index 7e53fad5e75c..eff008809559 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -318,8 +318,8 @@ public void SetCookieHeaderValue_CtorThrowsOnInvalidValue(string value) public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() { var header = new SetCookieHeaderValue("cookie"); - Assert.Equal("cookie".AsSpan(), header.Name); - Assert.Equal(string.Empty.AsSpan(), header.Value); + Assert.Equal("cookie", header.Name.AsSpan()); + Assert.Equal(string.Empty, header.Value.AsSpan()); } [Theory] @@ -329,18 +329,18 @@ public void SetCookieHeaderValue_Ctor1_InitializesCorrectly() public void SetCookieHeaderValue_Ctor2InitializesCorrectly(string name, string value) { var header = new SetCookieHeaderValue(name, value); - Assert.Equal(name.AsSpan(), header.Name); - Assert.Equal(value.AsSpan(), header.Value); + Assert.Equal(name, header.Name.AsSpan()); + Assert.Equal(value, header.Value.AsSpan()); } [Fact] public void SetCookieHeaderValue_Value() { var cookie = new SetCookieHeaderValue("name"); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(string.Empty, cookie.Value.AsSpan()); cookie.Value = "value1"; - Assert.Equal("value1".AsSpan(), cookie.Value); + Assert.Equal("value1", cookie.Value.AsSpan()); } [Theory] diff --git a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs index 5a786b6b70a8..eca804eb581d 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -9,7 +9,7 @@ public class StringWithQualityHeaderValueTest public void Ctor_StringOnlyOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token"); - Assert.Equal("token".AsSpan(), value.Value); + Assert.Equal("token", value.Value.AsSpan()); Assert.Null(value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null)); @@ -21,7 +21,7 @@ public void Ctor_StringOnlyOverload_MatchExpectation() public void Ctor_StringWithQualityOverload_MatchExpectation() { var value = new StringWithQualityHeaderValue("token", 0.5); - Assert.Equal("token".AsSpan(), value.Value); + Assert.Equal("token", value.Value.AsSpan()); Assert.Equal(0.5, value.Quality); Assert.Throws(() => new StringWithQualityHeaderValue(null, 0.1)); diff --git a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs index ebdb2fe0ad7d..25203570c16a 100644 --- a/src/Http/Http.Abstractions/test/CookieBuilderTests.cs +++ b/src/Http/Http.Abstractions/test/CookieBuilderTests.cs @@ -64,8 +64,8 @@ public void CookieBuilder_Extensions_Added() Assert.Contains("key=value", options.Extensions); var cookie = options.CreateCookieHeader("name", "value"); - Assert.Equal("name".AsSpan(), cookie.Name); - Assert.Equal("value".AsSpan(), cookie.Value); + Assert.Equal("name", cookie.Name.AsSpan()); + Assert.Equal("value", cookie.Value.AsSpan()); Assert.Equal(2, cookie.Extensions.Count); Assert.Contains("simple", cookie.Extensions); Assert.Contains("key=value", cookie.Extensions); diff --git a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs index d4861a9a527b..37c8475f28ea 100644 --- a/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs +++ b/src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs @@ -284,8 +284,8 @@ public void SaveTempData_RemovesCookie_WhenNoDataToSave() Assert.Single(responseCookies); var cookie = responseCookies.Single(); Assert.NotNull(cookie); - Assert.Equal(CookieTempDataProvider.CookieName.AsSpan(), cookie.Name); - Assert.Equal(string.Empty.AsSpan(), cookie.Value); + Assert.Equal(CookieTempDataProvider.CookieName, cookie.Name.AsSpan()); + Assert.Equal(string.Empty, cookie.Value.AsSpan()); Assert.NotNull(cookie.Expires); Assert.True(cookie.Expires.Value < DateTimeOffset.Now); // expired cookie } diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs index debdf250c46e..1738431352bf 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs @@ -80,7 +80,7 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) foreach (var cookieTempDataProviderCookie in cookieTempDataProviderCookies) { Assert.NotNull(cookieTempDataProviderCookie.Value.Value); - Assert.Equal("/".AsSpan(), cookieTempDataProviderCookie.Path); + Assert.Equal("/", cookieTempDataProviderCookie.Path.AsSpan()); Assert.Null(cookieTempDataProviderCookie.Domain.Value); Assert.False(cookieTempDataProviderCookie.Secure); } @@ -97,8 +97,8 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size) .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeader => setCookieHeader.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeaderValue); - Assert.Equal(string.Empty.AsSpan(), setCookieHeaderValue.Value); - Assert.Equal("/".AsSpan(), setCookieHeaderValue.Path); + Assert.Equal(string.Empty, setCookieHeaderValue.Value.AsSpan()); + Assert.Equal("/", setCookieHeaderValue.Path.AsSpan()); Assert.Null(setCookieHeaderValue.Domain.Value); Assert.NotNull(setCookieHeaderValue.Expires); Assert.True(setCookieHeaderValue.Expires < DateTimeOffset.Now); // expired cookie @@ -130,7 +130,7 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal("/", setCookieHeader.Path.AsSpan()); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); @@ -153,8 +153,8 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal(string.Empty.AsSpan(), setCookieHeader.Value); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal(string.Empty, setCookieHeader.Value.AsSpan()); + Assert.Equal("/", setCookieHeader.Path.AsSpan()); Assert.Null(setCookieHeader.Domain.Value); Assert.NotNull(setCookieHeader.Expires); Assert.True(setCookieHeader.Expires < DateTimeOffset.Now); // expired cookie @@ -183,7 +183,7 @@ public async Task CookieTempDataProviderCookie_DoesNotSetsSecureAttributeOnCooki .Select(setCookieValue => SetCookieHeaderValue.Parse(setCookieValue)) .FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName); Assert.NotNull(setCookieHeader); - Assert.Equal("/".AsSpan(), setCookieHeader.Path); + Assert.Equal("/", setCookieHeader.Path.AsSpan()); Assert.Null(setCookieHeader.Domain.Value); Assert.False(setCookieHeader.Secure); Assert.Null(setCookieHeader.Expires); diff --git a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs index 68d6e98ce124..39504a60c711 100644 --- a/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs +++ b/src/Security/Authentication/test/OpenIdConnect/OpenIdConnectChallengeTests.cs @@ -441,15 +441,15 @@ public async Task ChallengeSetsNonceAndStateCookies(OpenIdConnectRedirectBehavio Assert.True(nonceCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(nonceCookie.HttpOnly); - Assert.Equal("/signin-oidc".AsSpan(), nonceCookie.Path); - Assert.Equal("N".AsSpan(), nonceCookie.Value); + Assert.Equal("/signin-oidc", nonceCookie.Path.AsSpan()); + Assert.Equal("N", nonceCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.None, nonceCookie.SameSite); var correlationCookie = challengeCookies.Where(cookie => cookie.Name.StartsWith(".AspNetCore.Correlation.", StringComparison.Ordinal)).Single(); Assert.True(correlationCookie.Expires.HasValue); Assert.True(nonceCookie.Expires > DateTime.UtcNow); Assert.True(correlationCookie.HttpOnly); - Assert.Equal("/signin-oidc".AsSpan(), correlationCookie.Path); + Assert.Equal("/signin-oidc", correlationCookie.Path.AsSpan()); Assert.False(StringSegment.IsNullOrEmpty(correlationCookie.Value)); Assert.Equal(Net.Http.Headers.SameSiteMode.None, correlationCookie.SameSite); diff --git a/src/Security/CookiePolicy/test/CookieConsentTests.cs b/src/Security/CookiePolicy/test/CookieConsentTests.cs index 79905c22c9c6..e0c51f55c810 100644 --- a/src/Security/CookiePolicy/test/CookieConsentTests.cs +++ b/src/Security/CookiePolicy/test/CookieConsentTests.cs @@ -217,15 +217,15 @@ public async Task GrantConsentSetsCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("yes".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name.AsSpan()); + Assert.Equal("yes", consentCookie.Value.AsSpan()); Assert.True(consentCookie.Expires.HasValue); Assert.True(consentCookie.Expires.Value > DateTimeOffset.Now + TimeSpan.FromDays(364)); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); var testCookie = cookies[1]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("Value".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name.AsSpan()); + Assert.Equal("Value", testCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); } @@ -239,8 +239,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnAppendCookie = context => { - Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); - Assert.Equal("yes".AsSpan(), context.CookieValue); + Assert.Equal(".AspNet.Consent", context.CookieName.AsSpan()); + Assert.Equal("yes", context.CookieValue.AsSpan()); Assert.Equal(Http.SameSiteMode.Strict, context.CookieOptions.SameSite); context.CookieName += "1"; context.CookieValue += "1"; @@ -267,8 +267,8 @@ public async Task GrantConsentAppliesPolicyToConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("yes1".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name.AsSpan()); + Assert.Equal("yes1", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); Assert.Contains("extension", consentCookie.Extensions); @@ -398,13 +398,13 @@ public async Task WithdrawConsentDeletesCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Equal(2, cookies.Count); var testCookie = cookies[0]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("Value1".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name.AsSpan()); + Assert.Equal("Value1", testCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.Null(testCookie.Expires); var consentCookie = cookies[1]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name.AsSpan()); + Assert.Equal("", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -418,7 +418,7 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() options.MinimumSameSitePolicy = Http.SameSiteMode.Strict; options.OnDeleteCookie = context => { - Assert.Equal(".AspNet.Consent".AsSpan(), context.CookieName); + Assert.Equal(".AspNet.Consent", context.CookieName.AsSpan()); context.CookieName += "1"; }; }, @@ -445,8 +445,8 @@ public async Task WithdrawConsentAppliesPolicyToDeleteCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name.AsSpan()); + Assert.Equal("", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); } @@ -510,8 +510,8 @@ public async Task DeleteCookieDoesNotRequireConsent() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var testCookie = cookies[0]; - Assert.Equal("Test".AsSpan(), testCookie.Name); - Assert.Equal("".AsSpan(), testCookie.Value); + Assert.Equal("Test", testCookie.Name.AsSpan()); + Assert.Equal("", testCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, testCookie.SameSite); Assert.NotNull(testCookie.Expires); } @@ -574,8 +574,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookie() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("yes".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name.AsSpan()); + Assert.Equal("yes", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -627,8 +627,8 @@ public async Task CreateConsentCookieAppliesPolicy() var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent1".AsSpan(), consentCookie.Name); - Assert.Equal("yes1".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent1", consentCookie.Name.AsSpan()); + Assert.Equal("yes1", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Strict, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); @@ -672,8 +672,8 @@ public async Task CreateConsentCookieMatchesGrantConsentCookieWhenCookieValueIsC var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); Assert.Single(cookies); var consentCookie = cookies[0]; - Assert.Equal(".AspNet.Consent".AsSpan(), consentCookie.Name); - Assert.Equal("true".AsSpan(), consentCookie.Value); + Assert.Equal(".AspNet.Consent", consentCookie.Name.AsSpan()); + Assert.Equal("true", consentCookie.Value.AsSpan()); Assert.Equal(Net.Http.Headers.SameSiteMode.Unspecified, consentCookie.SameSite); Assert.NotNull(consentCookie.Expires); diff --git a/src/Security/CookiePolicy/test/CookiePolicyTests.cs b/src/Security/CookiePolicy/test/CookiePolicyTests.cs index 30a55a961d55..44a95186ee77 100644 --- a/src/Security/CookiePolicy/test/CookiePolicyTests.cs +++ b/src/Security/CookiePolicy/test/CookiePolicyTests.cs @@ -58,10 +58,10 @@ await RunTest("/secureAlways", transaction => { Assert.NotNull(transaction.SetCookie); - Assert.Equal("A=A; path=/; secure".AsSpan(), transaction.SetCookie[0]); - Assert.Equal("B=B; path=/; secure".AsSpan(), transaction.SetCookie[1]); - Assert.Equal("C=C; path=/; secure".AsSpan(), transaction.SetCookie[2]); - Assert.Equal("D=D; path=/; secure".AsSpan(), transaction.SetCookie[3]); + Assert.Equal("A=A; path=/; secure", transaction.SetCookie[0].AsSpan()); + Assert.Equal("B=B; path=/; secure", transaction.SetCookie[1].AsSpan()); + Assert.Equal("C=C; path=/; secure", transaction.SetCookie[2].AsSpan()); + Assert.Equal("D=D; path=/; secure", transaction.SetCookie[3].AsSpan()); })); } @@ -398,10 +398,10 @@ public async Task CookiePolicyAppliesToCookieAuth() Assert.NotNull(transaction.SetCookie); Assert.Single(transaction.SetCookie); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie".AsSpan(), cookie.Name); + Assert.Equal("TestCookie", cookie.Name.AsSpan()); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path.AsSpan()); Assert.Contains("extension", cookie.Extensions); } @@ -450,25 +450,25 @@ public async Task CookiePolicyAppliesToCookieAuthChunks() Assert.Equal(3, transaction.SetCookie.Count); var cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[0]); - Assert.Equal("TestCookie".AsSpan(), cookie.Name); - Assert.Equal("chunks-2".AsSpan(), cookie.Value); + Assert.Equal("TestCookie", cookie.Name.AsSpan()); + Assert.Equal("chunks-2", cookie.Value.AsSpan()); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path.AsSpan()); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[1]); - Assert.Equal("TestCookieC1".AsSpan(), cookie.Name); + Assert.Equal("TestCookieC1", cookie.Name.AsSpan()); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path.AsSpan()); Assert.Contains("ext", cookie.Extensions); cookie = SetCookieHeaderValue.Parse(transaction.SetCookie[2]); - Assert.Equal("TestCookieC2".AsSpan(), cookie.Name); + Assert.Equal("TestCookieC2", cookie.Name.AsSpan()); Assert.True(cookie.HttpOnly); Assert.True(cookie.Secure); - Assert.Equal("/".AsSpan(), cookie.Path); + Assert.Equal("/", cookie.Path.AsSpan()); Assert.Contains("ext", cookie.Extensions); } From 9c222b34587fc766fe8a22f35138dfb6f890b3ae Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Tue, 12 Nov 2024 00:21:02 +0100 Subject: [PATCH 11/18] Update .net SDK --- global.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global.json b/global.json index 375258806973..5132ecafe91a 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "10.0.100-alpha.1.24553.6" + "version": "10.0.100-alpha.1.24560.6" }, "tools": { - "dotnet": "10.0.100-alpha.1.24553.6", + "dotnet": "10.0.100-alpha.1.24560.6", "runtimes": { "dotnet/x86": [ "$(MicrosoftInternalRuntimeAspNetCoreTransportVersion)" From 02d8255dbf4f68eb70a9691e4a116168e7744f5d Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Tue, 12 Nov 2024 00:46:19 +0100 Subject: [PATCH 12/18] add path prefixes back --- src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj index a43b8e998eec..67488771552d 100644 --- a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj +++ b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj @@ -90,7 +90,7 @@ %(RecursiveDir)%(FileName)%(Extension) - + @@ -106,7 +106,7 @@ > - + From b24cdd140b39257d299704b3c9a896a43081e52a Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 11 Nov 2024 16:15:27 -0800 Subject: [PATCH 13/18] Update 9.0 prebuilt baseline --- eng/SourceBuildPrebuiltBaseline.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/SourceBuildPrebuiltBaseline.xml b/eng/SourceBuildPrebuiltBaseline.xml index df4d87887caf..7dc26323656a 100644 --- a/eng/SourceBuildPrebuiltBaseline.xml +++ b/eng/SourceBuildPrebuiltBaseline.xml @@ -50,7 +50,7 @@ - + From 0d0b5c685007201b4837059c03274a17cdc44753 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Tue, 12 Nov 2024 16:57:33 -0800 Subject: [PATCH 14/18] Fix package definition --- .../Microsoft.AspNetCore.Identity.UI.csproj | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj index 67488771552d..664b56196460 100644 --- a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj +++ b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj @@ -91,10 +91,26 @@ - + - + + @@ -116,8 +132,17 @@ - - + + + Discovered + + + Discovered + + + + + Date: Wed, 13 Nov 2024 01:28:06 -0800 Subject: [PATCH 15/18] Fix package --- src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj index 664b56196460..d36fe09d60c4 100644 --- a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj +++ b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj @@ -156,10 +156,10 @@ StaticWebAssetEndpoints="@(V5AssetEndpoints)" TargetPropsFilePath="$(IntermediateOutputPath)IdentityUI.V5.endpoints.targets" /> - + - + From 725b50b9a05fd82510bca96b93400c8d36f7412e Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 14 Nov 2024 08:43:06 -0800 Subject: [PATCH 16/18] Skip broken test --- .../test/Templates.Mvc.Tests/WebApiTemplateTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProjectTemplates/test/Templates.Mvc.Tests/WebApiTemplateTest.cs b/src/ProjectTemplates/test/Templates.Mvc.Tests/WebApiTemplateTest.cs index 7d79567321e6..78236be67d6c 100644 --- a/src/ProjectTemplates/test/Templates.Mvc.Tests/WebApiTemplateTest.cs +++ b/src/ProjectTemplates/test/Templates.Mvc.Tests/WebApiTemplateTest.cs @@ -98,7 +98,7 @@ public ITestOutputHelper Output [InlineData("SingleOrg", new [] { ArgConstants.UseProgramMain, ArgConstants.UseControllers, ArgConstants.CallsGraph })] public Task WebApiTemplateCSharp_IdentityWeb_SingleOrg_ProgramMain_BuildsAndPublishes(string auth, string[] args) => PublishAndBuildWebApiTemplate(languageOverride: null, auth: auth, args: args); - [ConditionalTheory] + [ConditionalTheory(Skip = "https://github.com/dotnet/aspnetcore/issues/58957")] [SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/28090", Queues = HelixConstants.Windows10Arm64 + HelixConstants.DebianArm64)] [InlineData("SingleOrg", null)] [InlineData("SingleOrg", new [] { ArgConstants.UseProgramMain, ArgConstants.NoHttps })] From 471f08f724bdb7f115652ec970c08e2220e81497 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Thu, 14 Nov 2024 09:25:13 -0800 Subject: [PATCH 17/18] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0822a5e4c138..2e2e8645cdd6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,7 @@ registries: url: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/ updates: - - package-ecosystem: NuGet + - package-ecosystem: nuget directory: "/" # Perform only security updates of our npm dependencies. open-pull-requests-limit: 0 From 59d3d634771c493233e5858e4d381b7882892141 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Thu, 14 Nov 2024 09:27:05 -0800 Subject: [PATCH 18/18] Update dependabot.yml --- .github/dependabot.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2e2e8645cdd6..11389fa622f1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,4 @@ version: 2 -registries: - dev.azure.com: - token: ${{secrets.DEPENDABOT_NPM_TOKEN}} - type: npm-registry - url: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/ updates: - package-ecosystem: nuget