Skip to content

Commit 4bc9010

Browse files
author
Matthias Gessinger
committed
Fix failing unit tests
1 parent d9a2d7e commit 4bc9010

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

src/Abstractions/src/Asp.Versioning.Abstractions/DeprecationPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ public bool IsEffective( DateTimeOffset? dateTimeOffset )
7373
return true;
7474
}
7575

76-
return date < when;
76+
return date <= when;
7777
}
7878
}

src/AspNet/WebApi/src/Asp.Versioning.WebApi.ApiExplorer/ApiExplorer/VersionedApiExplorer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,11 @@ protected virtual ApiDescriptionGroupCollection InitializeApiDescriptions()
238238
}
239239

240240
var routes = FlattenRoutes( Configuration.Routes ).ToArray();
241-
var sunsetPolicyManager = Configuration.GetSunsetPolicyManager();
242-
var deprecationPolicyManager = Configuration.GetDeprecationPolicyManager();
243241

244242
foreach ( var apiVersion in FlattenApiVersions( controllerMappings ) )
245243
{
246-
sunsetPolicyManager.TryGetPolicy( apiVersion, out var sunsetPolicy );
247-
deprecationPolicyManager.TryGetPolicy( apiVersion, out var deprecationPolicy );
244+
SunsetPolicyManager.TryGetPolicy( apiVersion, out var sunsetPolicy );
245+
DeprecationPolicyManager.TryGetPolicy( apiVersion, out var deprecationPolicy );
248246

249247
for ( var i = 0; i < routes.Length; i++ )
250248
{

src/AspNet/WebApi/test/Asp.Versioning.WebApi.Tests/DefaultApiVersionReporterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class DefaultApiVersionReporterTest
1313
public void report_should_add_expected_headers()
1414
{
1515
// arrange
16-
var sunsetDate = DateTimeOffset.Now;
17-
var deprecationDate = DateTimeOffset.Now;
16+
var sunsetDate = DateTimeOffset.Now.AddDays( 2 );
17+
var deprecationDate = DateTimeOffset.Now.AddDays( 1 );
1818
var reporter = new DefaultApiVersionReporter( new TestSunsetPolicyManager( sunsetDate ), new TestDeprecationPolicyManager( deprecationDate ) );
1919
var configuration = new HttpConfiguration();
2020
var request = new HttpRequestMessage();

src/Client/test/Asp.Versioning.Http.Client.Tests/net#.0/ApiVersionHandlerLoggerTTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public async Task on_api_deprecated_should_log_message()
2323
var date = DateTimeOffset.Now;
2424
var expected = "API version 1.0 for http://tempuri.org has been deprecated since <unspecified> and will " +
2525
$"sunset on {date.ToUniversalTime()}. Additional information: " +
26-
"API Policy (en): http://tempuri.org/policy/en, " +
27-
"API Política (es): http://tempuri.org/policy/es";
26+
"[API Policy (en): http://tempuri.org/policy/en, " +
27+
"API Política (es): http://tempuri.org/policy/es]";
2828

2929
response.Headers.Add( "sunset", date.ToString( "r" ) );
3030
response.Headers.Add( "link", "<policy/en>; rel=\"sunset\"; type=\"text/html\"; title=\"API Policy\"; hreflang=\"en\"" );

src/Common/src/Common/DefaultApiVersionReporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
104104

105105
if ( deprecationPolicyManager.TryResolvePolicy( name, version, out var deprecationPolicy ) )
106106
{
107+
// Only emit a deprecation header if the deprecation policy becomes effective before the sunset date.
107108
if ( deprecationPolicy.IsEffective( sunsetDate ) )
108109
{
109110
response.WriteDeprecationPolicy( deprecationPolicy );

src/Common/test/Common.Tests/DeprecationPolicyBuilderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void link_should_should_return_existing_builder()
5151
}
5252

5353
[Fact]
54-
public void build_should_construct_sunset_policy()
54+
public void build_should_construct_deprecation_policy()
5555
{
5656
// arrange
5757
var builder = new DeprecationPolicyBuilder( default, ApiVersion.Default );
@@ -66,6 +66,6 @@ public void build_should_construct_sunset_policy()
6666
policy.Should().BeEquivalentTo(
6767
new DeprecationPolicy(
6868
new DateTimeOffset( new DateTime( 2022, 2, 1 ) ),
69-
new LinkHeaderValue( new Uri( "http://tempuri.org" ), "sunset" ) ) );
69+
new LinkHeaderValue( new Uri( "http://tempuri.org" ), "deprecation" ) ) );
7070
}
7171
}

0 commit comments

Comments
 (0)