-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse versions single header CSVs. Fixes #1070
- Loading branch information
1 parent
59ff9e6
commit 4093dc0
Showing
2 changed files
with
173 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/Client/test/Asp.Versioning.Http.Client.Tests/ApiVersionEnumeratorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
|
||
namespace Asp.Versioning.Http; | ||
|
||
public class ApiVersionEnumeratorTest | ||
{ | ||
[Fact] | ||
public void enumerator_should_process_single_header_value() | ||
{ | ||
// arrange | ||
var response = new HttpResponseMessage(); | ||
|
||
response.Headers.Add( "api-supported-versions", "1.0" ); | ||
|
||
var enumerator = new ApiVersionEnumerator( response, "api-supported-versions" ); | ||
|
||
// act | ||
var results = enumerator.ToArray(); | ||
|
||
// assert | ||
results.Should().BeEquivalentTo( [new ApiVersion( 1.0 )] ); | ||
} | ||
|
||
[Fact] | ||
public void enumerator_should_process_multiple_header_values() | ||
{ | ||
// arrange | ||
var response = new HttpResponseMessage(); | ||
|
||
response.Headers.Add( "api-supported-versions", ["1.0", "2.0"] ); | ||
|
||
var enumerator = new ApiVersionEnumerator( response, "api-supported-versions" ); | ||
|
||
// act | ||
var results = enumerator.ToArray(); | ||
|
||
// assert | ||
results.Should().BeEquivalentTo( new ApiVersion[] { new( 1.0 ), new( 2.0 ) } ); | ||
} | ||
|
||
[Theory] | ||
[InlineData( "1.0,2.0" )] | ||
[InlineData( "1.0, 2.0" )] | ||
[InlineData( "1.0,,2.0" )] | ||
[InlineData( "1.0, abc, 2.0" )] | ||
public void enumerator_should_process_single_header_comma_separated_values( string value ) | ||
{ | ||
// arrange | ||
var response = new HttpResponseMessage(); | ||
|
||
response.Headers.Add( "api-supported-versions", [value] ); | ||
|
||
var enumerator = new ApiVersionEnumerator( response, "api-supported-versions" ); | ||
|
||
// act | ||
var results = enumerator.ToArray(); | ||
|
||
// assert | ||
results.Should().BeEquivalentTo( new ApiVersion[] { new( 1.0 ), new( 2.0 ) } ); | ||
} | ||
|
||
[Fact] | ||
public void enumerator_should_process_many_header_comma_separated_values() | ||
{ | ||
// arrange | ||
const string Value = "1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0"; | ||
var response = new HttpResponseMessage(); | ||
|
||
response.Headers.Add( "api-supported-versions", [Value] ); | ||
|
||
var enumerator = new ApiVersionEnumerator( response, "api-supported-versions" ); | ||
|
||
// act | ||
var results = enumerator.ToArray(); | ||
|
||
// assert | ||
results.Should().BeEquivalentTo( | ||
new ApiVersion[] | ||
{ | ||
new( 1.0 ), | ||
new( 2.0 ), | ||
new( 3.0 ), | ||
new( 4.0 ), | ||
new( 5.0 ), | ||
new( 6.0 ), | ||
new( 7.0 ), | ||
new( 8.0 ), | ||
new( 9.0 ), | ||
new( 10.0 ), | ||
} ); | ||
} | ||
|
||
[Fact] | ||
public void enumerator_should_process_multiple_header_comma_separated_values() | ||
{ | ||
// arrange | ||
var response = new HttpResponseMessage(); | ||
|
||
response.Headers.Add( "api-supported-versions", ["1.0, 2.0", "3.0, 4.0"] ); | ||
|
||
var enumerator = new ApiVersionEnumerator( response, "api-supported-versions" ); | ||
|
||
// act | ||
var results = enumerator.ToArray(); | ||
|
||
// assert | ||
results.Should().BeEquivalentTo( | ||
new ApiVersion[] | ||
{ | ||
new( 1.0 ), | ||
new( 2.0 ), | ||
new( 3.0 ), | ||
new( 4.0 ), | ||
} ); | ||
} | ||
} |