Skip to content

Commit

Permalink
Flip around where AsSpan is called with string comparisons in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Nov 6, 2024
1 parent 540cf1a commit 7a8ae19
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Http/Headers/test/CacheControlHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter()
Assert.Throws<FormatException>(() => 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<ArgumentException>(() => cacheControl.PrivateHeaders.Add(null));
Assert.Throws<FormatException>(() => 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);
Expand Down
94 changes: 47 additions & 47 deletions src/Http/Headers/test/ContentDispositionHeaderValueTest.cs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/Http/Headers/test/ContentRangeHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<ArgumentException>(() => range.Unit = null);
Assert.Throws<ArgumentException>(() => range.Unit = "");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Headers/test/CookieHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
28 changes: 14 additions & 14 deletions src/Http/Headers/test/MediaTypeHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -221,20 +221,20 @@ 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]
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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
18 changes: 9 additions & 9 deletions src/Http/Headers/test/NameValueHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

Expand All @@ -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<InvalidOperationException>(() => { pair1.Value = "othervalue"; });
}
Expand All @@ -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]
Expand All @@ -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<InvalidOperationException>(() => { pair1.Value = "othervalue"; });
}

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Headers/test/RangeHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentException>(() => range.Unit = null);
Assert.Throws<ArgumentException>(() => range.Unit = "");
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Headers/test/SetCookieHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void SetCookieHeaderValue_CtorThrowsOnInvalidValue(string value)
public void SetCookieHeaderValue_Ctor1_InitializesCorrectly()
{
var header = new SetCookieHeaderValue("cookie");
Assert.Equal("cookie".AsSpan(), header.Name);
Assert.Equal("cookie", header.Name.AsSpan());
Assert.Equal(string.Empty.AsSpan(), header.Value);
}

Expand All @@ -340,7 +340,7 @@ public void SetCookieHeaderValue_Value()
Assert.Equal(string.Empty.AsSpan(), cookie.Value);

cookie.Value = "value1";
Assert.Equal("value1".AsSpan(), cookie.Value);
Assert.Equal("value1", cookie.Value.AsSpan());
}

[Theory]
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Headers/test/StringWithQualityHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentException>(() => new StringWithQualityHeaderValue(null));
Expand All @@ -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<ArgumentException>(() => new StringWithQualityHeaderValue(null, 0.1));
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Http.Abstractions/test/CookieBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -98,7 +98,7 @@ public async Task RoundTripLargeData_WorksWithChunkingCookies(int size)
.FirstOrDefault(setCookieHeader => setCookieHeader.Name == CookieTempDataProvider.CookieName);
Assert.NotNull(setCookieHeaderValue);
Assert.Equal(string.Empty.AsSpan(), setCookieHeaderValue.Value);
Assert.Equal("/".AsSpan(), setCookieHeaderValue.Path);
Assert.Equal("/", setCookieHeaderValue.Path.AsSpan());
Assert.Null(setCookieHeaderValue.Domain.Value);
Assert.NotNull(setCookieHeaderValue.Expires);
Assert.True(setCookieHeaderValue.Expires < DateTimeOffset.Now); // expired cookie
Expand Down Expand Up @@ -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);
Expand All @@ -154,7 +154,7 @@ public async Task Redirect_RetainsTempData_EvenIfAccessed_AndSetsAppropriateCook
.FirstOrDefault(setCookieHeaderValue => setCookieHeaderValue.Name == CookieTempDataProvider.CookieName);
Assert.NotNull(setCookieHeader);
Assert.Equal(string.Empty.AsSpan(), setCookieHeader.Value);
Assert.Equal("/".AsSpan(), setCookieHeader.Path);
Assert.Equal("/", setCookieHeader.Path.AsSpan());
Assert.Null(setCookieHeader.Domain.Value);
Assert.NotNull(setCookieHeader.Expires);
Assert.True(setCookieHeader.Expires < DateTimeOffset.Now); // expired cookie
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 7a8ae19

Please sign in to comment.