Upgrade to xunit 2.3.0-beta4

This commit is contained in:
Nate McMaster 2017-08-22 16:29:13 -07:00 committed by GitHub
parent 27b0f60f09
commit 5b58a6a71d
14 changed files with 87 additions and 81 deletions

View File

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

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Authentication
Assert.Null(props.GetTokenValue("One")); Assert.Null(props.GetTokenValue("One"));
Assert.Null(props.GetTokenValue("Two")); Assert.Null(props.GetTokenValue("Two"));
Assert.Null(props.GetTokenValue("Three")); Assert.Null(props.GetTokenValue("Three"));
Assert.Equal(1, props.GetTokens().Count()); Assert.Single(props.GetTokens());
} }
[Fact] [Fact]

View File

@ -138,8 +138,7 @@ namespace Microsoft.AspNetCore.Http
var source = new PathString(sourcePath); var source = new PathString(sourcePath);
var test = new PathString(testPath); var test = new PathString(testPath);
PathString remaining; var result = source.StartsWithSegments(test, out var remaining);
var result = source.StartsWithSegments(test, out remaining);
Assert.Equal(expectedResult, result); Assert.Equal(expectedResult, result);
} }
@ -181,26 +180,33 @@ namespace Microsoft.AspNetCore.Http
var source = new PathString(sourcePath); var source = new PathString(sourcePath);
var test = new PathString(testPath); var test = new PathString(testPath);
PathString remaining; var result = source.StartsWithSegments(test, comparison, out var remaining);
var result = source.StartsWithSegments(test, comparison, out remaining);
Assert.Equal(expectedResult, result); Assert.Equal(expectedResult, result);
} }
[Theory] [Theory]
[InlineData("unreserved", "/abc123.-_~", "/abc123.-_~")] // unreserved
[InlineData("colon", "/:", "/:")] [InlineData("/abc123.-_~", "/abc123.-_~")]
[InlineData("at", "/@", "/@")] // colon
[InlineData("sub-delims", "/!$&'()*+,;=", "/!$&'()*+,;=")] [InlineData("/:", "/:")]
[InlineData("reserved", "/?#[]", "/%3F%23%5B%5D")] // at
[InlineData("pct-encoding", "/单行道", "/%E5%8D%95%E8%A1%8C%E9%81%93")] [InlineData("/@", "/@")]
[InlineData("mixed1", "/index/单行道=(x*y)[abc]", "/index/%E5%8D%95%E8%A1%8C%E9%81%93=(x*y)%5Babc%5D")] // sub-delims
[InlineData("mixed2", "/index/单行道=(x*y)[abc]_", "/index/%E5%8D%95%E8%A1%8C%E9%81%93=(x*y)%5Babc%5D_")] [InlineData("/!$&'()*+,;=", "/!$&'()*+,;=")]
[InlineData("encoded", "/http%3a%2f%2f[foo]%3A5000/", "/http%3a%2f%2f%5Bfoo%5D%3A5000/")] // reserved
[InlineData("encoded", "/http%3a%2f%2f[foo]%3A5000/%", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%25")] [InlineData("/?#[]", "/%3F%23%5B%5D")]
[InlineData("encoded", "/http%3a%2f%2f[foo]%3A5000/%2", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%252")] // pct-encoding
[InlineData("encoded", "/http%3a%2f%2f[foo]%3A5000/%2F", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%2F")] [InlineData("/单行道", "/%E5%8D%95%E8%A1%8C%E9%81%93")]
public void ToUriComponentEscapeCorrectly(string category, string input, string expected) // mixed
[InlineData("/index/单行道=(x*y)[abc]", "/index/%E5%8D%95%E8%A1%8C%E9%81%93=(x*y)%5Babc%5D")]
[InlineData("/index/单行道=(x*y)[abc]_", "/index/%E5%8D%95%E8%A1%8C%E9%81%93=(x*y)%5Babc%5D_")]
// encoded
[InlineData("/http%3a%2f%2f[foo]%3A5000/", "/http%3a%2f%2f%5Bfoo%5D%3A5000/")]
[InlineData("/http%3a%2f%2f[foo]%3A5000/%", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%25")]
[InlineData("/http%3a%2f%2f[foo]%3A5000/%2", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%252")]
[InlineData("/http%3a%2f%2f[foo]%3A5000/%2F", "/http%3a%2f%2f%5Bfoo%5D%3A5000/%2F")]
public void ToUriComponentEscapeCorrectly(string input, string expected)
{ {
var path = new PathString(input); var path = new PathString(input);

View File

@ -227,8 +227,8 @@ namespace Microsoft.AspNetCore.Http
Assert.True(Assert.IsType<bool>(context.Items["after"])); Assert.True(Assert.IsType<bool>(context.Items["after"]));
Assert.NotNull(middlewareFactory.Created); Assert.NotNull(middlewareFactory.Created);
Assert.NotNull(middlewareFactory.Released); Assert.NotNull(middlewareFactory.Released);
Assert.IsType(typeof(Middleware), middlewareFactory.Created); Assert.IsType<Middleware>(middlewareFactory.Created);
Assert.IsType(typeof(Middleware), middlewareFactory.Released); Assert.IsType<Middleware>(middlewareFactory.Released);
Assert.Same(middlewareFactory.Created, middlewareFactory.Released); Assert.Same(middlewareFactory.Created, middlewareFactory.Released);
} }

View File

@ -84,21 +84,21 @@ namespace Microsoft.AspNetCore.Http
{ {
var context = new DefaultHttpContext(new FeatureCollection()); var context = new DefaultHttpContext(new FeatureCollection());
Assert.NotNull(context.User); Assert.NotNull(context.User);
Assert.Equal(1, context.User.Identities.Count()); Assert.Single(context.User.Identities);
Assert.True(object.ReferenceEquals(context.User, context.User)); Assert.True(object.ReferenceEquals(context.User, context.User));
Assert.False(context.User.Identity.IsAuthenticated); Assert.False(context.User.Identity.IsAuthenticated);
Assert.True(string.IsNullOrEmpty(context.User.Identity.AuthenticationType)); Assert.True(string.IsNullOrEmpty(context.User.Identity.AuthenticationType));
context.User = null; context.User = null;
Assert.NotNull(context.User); Assert.NotNull(context.User);
Assert.Equal(1, context.User.Identities.Count()); Assert.Single(context.User.Identities);
Assert.True(object.ReferenceEquals(context.User, context.User)); Assert.True(object.ReferenceEquals(context.User, context.User));
Assert.False(context.User.Identity.IsAuthenticated); Assert.False(context.User.Identity.IsAuthenticated);
Assert.True(string.IsNullOrEmpty(context.User.Identity.AuthenticationType)); Assert.True(string.IsNullOrEmpty(context.User.Identity.AuthenticationType));
context.User = new ClaimsPrincipal(); context.User = new ClaimsPrincipal();
Assert.NotNull(context.User); Assert.NotNull(context.User);
Assert.Equal(0, context.User.Identities.Count()); Assert.Empty(context.User.Identities);
Assert.True(object.ReferenceEquals(context.User, context.User)); Assert.True(object.ReferenceEquals(context.User, context.User));
Assert.Null(context.User.Identity); Assert.Null(context.User.Identity);

View File

@ -15,6 +15,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit.analyzers" Version="$(XunitAnalyzersVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" /> <PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" /> <PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup> </ItemGroup>

View File

@ -283,7 +283,8 @@ namespace Microsoft.AspNetCore.WebUtilities.Test
return new MemoryStream(data.ToArray()); return new MemoryStream(data.ToArray());
} }
private static IEnumerable<object[]> HttpRequestNullData()
public static IEnumerable<object[]> HttpRequestNullData()
{ {
yield return new object[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared }; yield return new object[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
yield return new object[] { new MemoryStream(), null, ArrayPool<byte>.Shared, ArrayPool<char>.Shared }; yield return new object[] { new MemoryStream(), null, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
@ -291,7 +292,7 @@ namespace Microsoft.AspNetCore.WebUtilities.Test
yield return new object[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null }; yield return new object[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null };
} }
private static IEnumerable<object[]> HttpRequestDisposeData() public static IEnumerable<object[]> HttpRequestDisposeData()
{ {
yield return new object[] { new Action<HttpRequestStreamReader>((httpRequestStreamReader) => yield return new object[] { new Action<HttpRequestStreamReader>((httpRequestStreamReader) =>
{ {

View File

@ -521,7 +521,7 @@ namespace Microsoft.AspNetCore.WebUtilities.Test
} }
} }
private static IEnumerable<object[]> HttpResponseStreamWriterData() public static IEnumerable<object[]> HttpResponseStreamWriterData()
{ {
yield return new object[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared }; yield return new object[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
yield return new object[] { new MemoryStream(), null, ArrayPool<byte>.Shared, ArrayPool<char>.Shared }; yield return new object[] { new MemoryStream(), null, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
@ -529,7 +529,7 @@ namespace Microsoft.AspNetCore.WebUtilities.Test
yield return new object[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null }; yield return new object[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null };
} }
private static IEnumerable<object[]> HttpResponseDisposeData() public static IEnumerable<object[]> HttpResponseDisposeData()
{ {
yield return new object[] { new Action<HttpResponseStreamWriter>((httpResponseStreamWriter) => yield return new object[] { new Action<HttpResponseStreamWriter>((httpResponseStreamWriter) =>
{ {
@ -549,7 +549,8 @@ namespace Microsoft.AspNetCore.WebUtilities.Test
httpResponseStreamWriter.Flush(); httpResponseStreamWriter.Flush();
})}; })};
} }
private static IEnumerable<object[]> HttpResponseDisposeDataAsync()
public static IEnumerable<object[]> HttpResponseDisposeDataAsync()
{ {
yield return new object[] { new Func<HttpResponseStreamWriter, Task>(async (httpResponseStreamWriter) => yield return new object[] { new Func<HttpResponseStreamWriter, Task>(async (httpResponseStreamWriter) =>
{ {

View File

@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -190,7 +190,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -216,7 +216,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -242,7 +242,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -289,7 +289,7 @@ namespace Microsoft.AspNetCore.WebUtilities
//first section can be read successfully //first section can be read successfully
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\"", section.Headers["Content-Disposition"][0]);
var read = section.Body.Read(buffer, 0, buffer.Length); var read = section.Body.Read(buffer, 0, buffer.Length);
Assert.Equal("text default", GetString(buffer, read)); Assert.Equal("text default", GetString(buffer, read));
@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\" filename=\"a\uFFFD!.txt\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\" filename=\"a\uFFFD!.txt\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);
@ -371,7 +371,7 @@ namespace Microsoft.AspNetCore.WebUtilities
var section = await reader.ReadNextSectionAsync(); var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section); Assert.NotNull(section);
Assert.Equal(1, section.Headers.Count); Assert.Single(section.Headers);
Assert.Equal("form-data; name=\"text\" filename=\"a\uFFFDU.txt\"", section.Headers["Content-Disposition"][0]); Assert.Equal("form-data; name=\"text\" filename=\"a\uFFFDU.txt\"", section.Headers["Content-Disposition"][0]);
var buffer = new MemoryStream(); var buffer = new MemoryStream();
await section.Body.CopyToAsync(buffer); await section.Body.CopyToAsync(buffer);

View File

@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.WebUtilities
public void ParseQueryWithEmptyKeyWorks() public void ParseQueryWithEmptyKeyWorks()
{ {
var collection = QueryHelpers.ParseQuery("?=value1&="); var collection = QueryHelpers.ParseQuery("?=value1&=");
Assert.Equal(1, collection.Count); Assert.Single(collection);
Assert.Equal(new[] { "value1", "" }, collection[""]); Assert.Equal(new[] { "value1", "" }, collection[""]);
} }

View File

@ -223,9 +223,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(CookieHeaderDataSet))] [MemberData(nameof(CookieHeaderDataSet))]
public void CookieHeaderValue_TryParse_AcceptsValidValues(CookieHeaderValue cookie, string expectedValue) public void CookieHeaderValue_TryParse_AcceptsValidValues(CookieHeaderValue cookie, string expectedValue)
{ {
CookieHeaderValue header; Assert.True(CookieHeaderValue.TryParse(expectedValue, out var header));
var result = CookieHeaderValue.TryParse(expectedValue, out header);
Assert.True(result);
Assert.Equal(cookie, header); Assert.Equal(cookie, header);
Assert.Equal(expectedValue, header.ToString()); Assert.Equal(expectedValue, header.ToString());
@ -242,10 +240,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(InvalidCookieHeaderDataSet))] [MemberData(nameof(InvalidCookieHeaderDataSet))]
public void CookieHeaderValue_TryParse_RejectsInvalidValues(string value) public void CookieHeaderValue_TryParse_RejectsInvalidValues(string value)
{ {
CookieHeaderValue header; Assert.False(CookieHeaderValue.TryParse(value, out var _));
var result = CookieHeaderValue.TryParse(value, out header);
Assert.False(result);
} }
[Theory] [Theory]
@ -270,8 +265,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListOfCookieHeaderDataSet))] [MemberData(nameof(ListOfCookieHeaderDataSet))]
public void CookieHeaderValue_TryParseList_AcceptsValidValues(IList<CookieHeaderValue> cookies, string[] input) public void CookieHeaderValue_TryParseList_AcceptsValidValues(IList<CookieHeaderValue> cookies, string[] input)
{ {
IList<CookieHeaderValue> results; var result = CookieHeaderValue.TryParseList(input, out var results);
var result = CookieHeaderValue.TryParseList(input, out results);
Assert.True(result); Assert.True(result);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
@ -281,8 +275,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListOfCookieHeaderDataSet))] [MemberData(nameof(ListOfCookieHeaderDataSet))]
public void CookieHeaderValue_TryParseStrictList_AcceptsValidValues(IList<CookieHeaderValue> cookies, string[] input) public void CookieHeaderValue_TryParseStrictList_AcceptsValidValues(IList<CookieHeaderValue> cookies, string[] input)
{ {
IList<CookieHeaderValue> results; var result = CookieHeaderValue.TryParseStrictList(input, out var results);
var result = CookieHeaderValue.TryParseStrictList(input, out results);
Assert.True(result); Assert.True(result);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
@ -301,25 +294,31 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListWithInvalidCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidCookieHeaderDataSet))]
public void CookieHeaderValue_TryParseList_ExcludesInvalidValues(IList<CookieHeaderValue> cookies, string[] input) public void CookieHeaderValue_TryParseList_ExcludesInvalidValues(IList<CookieHeaderValue> cookies, string[] input)
{ {
IList<CookieHeaderValue> results; var result = CookieHeaderValue.TryParseList(input, out var results);
var result = CookieHeaderValue.TryParseList(input, out results);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
Assert.Equal(cookies?.Count > 0, result); Assert.Equal(cookies?.Count > 0, result);
} }
[Theory] [Theory]
[MemberData(nameof(ListWithInvalidCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidCookieHeaderDataSet))]
public void CookieHeaderValue_ParseStrictList_ThrowsForAnyInvalidValues(IList<CookieHeaderValue> cookies, string[] input) public void CookieHeaderValue_ParseStrictList_ThrowsForAnyInvalidValues(
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
IList<CookieHeaderValue> cookies,
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
string[] input)
{ {
Assert.Throws<FormatException>(() => CookieHeaderValue.ParseStrictList(input)); Assert.Throws<FormatException>(() => CookieHeaderValue.ParseStrictList(input));
} }
[Theory] [Theory]
[MemberData(nameof(ListWithInvalidCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidCookieHeaderDataSet))]
public void CookieHeaderValue_TryParseStrictList_FailsForAnyInvalidValues(IList<CookieHeaderValue> cookies, string[] input) public void CookieHeaderValue_TryParseStrictList_FailsForAnyInvalidValues(
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
IList<CookieHeaderValue> cookies,
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
string[] input)
{ {
IList<CookieHeaderValue> results; var result = CookieHeaderValue.TryParseStrictList(input, out var results);
var result = CookieHeaderValue.TryParseStrictList(input, out results);
Assert.Null(results); Assert.Null(results);
Assert.False(result); Assert.False(result);
} }

View File

@ -15,12 +15,11 @@ namespace Microsoft.Net.Http.Headers
{ {
// We don't need to validate all possible date values, since they're already tested in HttpRuleParserTest. // We don't need to validate all possible date values, since they're already tested in HttpRuleParserTest.
// Just make sure the parser calls HttpRuleParser methods correctly. // Just make sure the parser calls HttpRuleParser methods correctly.
DateTimeOffset result; Assert.True(HeaderUtilities.TryParseDate(input, out var result));
Assert.True(HeaderUtilities.TryParseDate(input, out result));
Assert.Equal(expected, result); Assert.Equal(expected, result);
} }
private static IEnumerable<object[]> ValidStringData() public static IEnumerable<object[]> ValidStringData()
{ {
yield return new object[] { "Tue, 15 Nov 1994 08:12:31 GMT", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero) }; yield return new object[] { "Tue, 15 Nov 1994 08:12:31 GMT", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero) };
yield return new object[] { " Sunday, 06-Nov-94 08:49:37 GMT ", new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero) }; yield return new object[] { " Sunday, 06-Nov-94 08:49:37 GMT ", new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero) };
@ -32,12 +31,11 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(InvalidStringData))] [MemberData(nameof(InvalidStringData))]
public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input) public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input)
{ {
DateTimeOffset result; Assert.False(HeaderUtilities.TryParseDate(input, out var result));
Assert.False(HeaderUtilities.TryParseDate(input, out result));
Assert.Equal(new DateTimeOffset(), result); Assert.Equal(new DateTimeOffset(), result);
} }
private static IEnumerable<object[]> InvalidStringData() public static IEnumerable<object[]> InvalidStringData()
{ {
yield return new object[] { null }; yield return new object[] { null };
yield return new object[] { string.Empty }; yield return new object[] { string.Empty };

View File

@ -136,7 +136,7 @@ namespace Microsoft.Net.Http.Headers
Assert.True(RangeHeaderValue.TryParse("byte=" + input, out result), input); Assert.True(RangeHeaderValue.TryParse("byte=" + input, out result), input);
var ranges = result.Ranges.ToArray(); var ranges = result.Ranges.ToArray();
Assert.Equal(1, ranges.Length); Assert.Single(ranges);
var range = ranges.First(); var range = ranges.First();

View File

@ -326,9 +326,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(SetCookieHeaderDataSet))] [MemberData(nameof(SetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParse_AcceptsValidValues(SetCookieHeaderValue cookie, string expectedValue) public void SetCookieHeaderValue_TryParse_AcceptsValidValues(SetCookieHeaderValue cookie, string expectedValue)
{ {
SetCookieHeaderValue header; Assert.True(SetCookieHeaderValue.TryParse(expectedValue, out var header));
bool result = SetCookieHeaderValue.TryParse(expectedValue, out header);
Assert.True(result);
Assert.Equal(cookie, header); Assert.Equal(cookie, header);
Assert.Equal(expectedValue, header.ToString()); Assert.Equal(expectedValue, header.ToString());
@ -345,10 +343,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(InvalidSetCookieHeaderDataSet))] [MemberData(nameof(InvalidSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParse_RejectsInvalidValues(string value) public void SetCookieHeaderValue_TryParse_RejectsInvalidValues(string value)
{ {
SetCookieHeaderValue header; Assert.False(SetCookieHeaderValue.TryParse(value, out var _));
bool result = SetCookieHeaderValue.TryParse(value, out header);
Assert.False(result);
} }
[Theory] [Theory]
@ -364,8 +359,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListOfSetCookieHeaderDataSet))] [MemberData(nameof(ListOfSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParseList_AcceptsValidValues(IList<SetCookieHeaderValue> cookies, string[] input) public void SetCookieHeaderValue_TryParseList_AcceptsValidValues(IList<SetCookieHeaderValue> cookies, string[] input)
{ {
IList<SetCookieHeaderValue> results; bool result = SetCookieHeaderValue.TryParseList(input, out var results);
bool result = SetCookieHeaderValue.TryParseList(input, out results);
Assert.True(result); Assert.True(result);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
@ -384,8 +378,7 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListOfSetCookieHeaderDataSet))] [MemberData(nameof(ListOfSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParseStrictList_AcceptsValidValues(IList<SetCookieHeaderValue> cookies, string[] input) public void SetCookieHeaderValue_TryParseStrictList_AcceptsValidValues(IList<SetCookieHeaderValue> cookies, string[] input)
{ {
IList<SetCookieHeaderValue> results; bool result = SetCookieHeaderValue.TryParseStrictList(input, out var results);
bool result = SetCookieHeaderValue.TryParseStrictList(input, out results);
Assert.True(result); Assert.True(result);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
@ -404,25 +397,31 @@ namespace Microsoft.Net.Http.Headers
[MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParseList_ExcludesInvalidValues(IList<SetCookieHeaderValue> cookies, string[] input) public void SetCookieHeaderValue_TryParseList_ExcludesInvalidValues(IList<SetCookieHeaderValue> cookies, string[] input)
{ {
IList<SetCookieHeaderValue> results; bool result = SetCookieHeaderValue.TryParseList(input, out var results);
bool result = SetCookieHeaderValue.TryParseList(input, out results);
Assert.Equal(cookies, results); Assert.Equal(cookies, results);
Assert.Equal(cookies?.Count > 0, result); Assert.Equal(cookies?.Count > 0, result);
} }
[Theory] [Theory]
[MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_ParseStrictList_ThrowsForAnyInvalidValues(IList<SetCookieHeaderValue> cookies, string[] input) public void SetCookieHeaderValue_ParseStrictList_ThrowsForAnyInvalidValues(
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
IList<SetCookieHeaderValue> cookies,
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
string[] input)
{ {
Assert.Throws<FormatException>(() => SetCookieHeaderValue.ParseStrictList(input)); Assert.Throws<FormatException>(() => SetCookieHeaderValue.ParseStrictList(input));
} }
[Theory] [Theory]
[MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))] [MemberData(nameof(ListWithInvalidSetCookieHeaderDataSet))]
public void SetCookieHeaderValue_TryParseStrictList_FailsForAnyInvalidValues(IList<SetCookieHeaderValue> cookies, string[] input) public void SetCookieHeaderValue_TryParseStrictList_FailsForAnyInvalidValues(
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
IList<SetCookieHeaderValue> cookies,
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
string[] input)
{ {
IList<SetCookieHeaderValue> results; bool result = SetCookieHeaderValue.TryParseStrictList(input, out var results);
bool result = SetCookieHeaderValue.TryParseStrictList(input, out results);
Assert.Null(results); Assert.Null(results);
Assert.False(result); Assert.False(result);
} }