Skip to content

Commit 9de3861

Browse files
Add support for .NET Core 3.1 to 6.0. Fixes #815
1 parent d4d522a commit 9de3861

File tree

59 files changed

+457
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+457
-29
lines changed

build/test.props

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
2121
</ItemGroup>
2222

23-
<ItemGroup Condition=" '$(IsAspNetCore)' == 'true' ">
24-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.2-*" />
25-
</ItemGroup>
26-
2723
<ItemGroup>
2824
<Using Include="Moq" />
2925
<Using Include="Xunit" />

build/test.targets

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup>
5-
<FluentAssertionsVersion>6.5.1</FluentAssertionsVersion>
6-
<FluentAssertionsVersion Condition=" '$(TargetFramework)' != 'net6.0' ">5.10.3</FluentAssertionsVersion>
5+
<FluentAssertionsVersion>6.6.0</FluentAssertionsVersion>
6+
<FluentAssertionsVersion Condition=" '$(TargetFramework)' == 'net452' ">5.10.3</FluentAssertionsVersion>
7+
<TestHostVersion>6.0.4-*</TestHostVersion>
8+
<TestHostVersion Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">3.1.24</TestHostVersion>
79
</PropertyGroup>
810

911
<ItemGroup Condition=" '$(IsSharedProject)' == 'false' ">
1012
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
1113
</ItemGroup>
1214

15+
<ItemGroup Condition=" '$(IsAspNetCore)' == 'true' ">
16+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(TestHostVersion)" />
17+
</ItemGroup>
18+
1319
<ItemGroup>
1420
<Using Include="FluentAssertions" />
1521
</ItemGroup>

src/Abstractions/src/Asp.Versioning.Abstractions/ISunsetPolicyManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool TryGetPolicy(
2222
string? name,
2323
ApiVersion? apiVersion,
2424
#if !NETSTANDARD
25-
[MaybeNullWhen(false)]
25+
[MaybeNullWhen( false )]
2626
#endif
2727
out SunsetPolicy sunsetPolicy );
2828
}

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/Asp.Versioning.Mvc.Acceptance.Tests.csproj

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
55
<RootNamespace>Asp.Versioning</RootNamespace>
66
</PropertyGroup>
77

8+
<PropertyGroup>
9+
<RuntimeCompilationVersion>6.0.4-*</RuntimeCompilationVersion>
10+
<RuntimeCompilationVersion Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">3.1.24</RuntimeCompilationVersion>
11+
</PropertyGroup>
12+
813
<ItemGroup>
914
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
10-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.2" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="$(RuntimeCompilationVersion)" />
16+
</ItemGroup>
17+
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
19+
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
20+
</ItemGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
23+
<Compile Remove="Http\**\*.cs" />
24+
<None Include="Http\**\*.cs" />
1125
</ItemGroup>
1226

1327
<ItemGroup>

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/HttpServerFixture.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Asp.Versioning;
1313
using Microsoft.Extensions.DependencyInjection;
1414
using System.IO;
1515
using System.Reflection;
16+
using System.Text;
1617
using static Microsoft.Extensions.DependencyInjection.ServiceDescriptor;
1718

1819
public abstract partial class HttpServerFixture
@@ -35,14 +36,34 @@ protected virtual void OnAddApiVersioning( IApiVersioningBuilder builder ) { }
3536

3637
private static string GenerateEndpointDirectedGraph( IServiceProvider services )
3738
{
39+
const int MaxUriLength = 65519;
3840
var dfa = services.GetRequiredService<DfaGraphWriter>();
3941
var dataSource = services.GetRequiredService<EndpointDataSource>();
40-
using var writer = new StringWriter();
42+
string graph;
4143

42-
dfa.Write( dataSource, writer );
43-
writer.Flush();
44+
using ( var writer = new StringWriter() )
45+
{
46+
dfa.Write( dataSource, writer );
47+
writer.Flush();
48+
graph = writer.ToString();
49+
}
50+
51+
var count = graph.Length / MaxUriLength;
52+
var fragment = new StringBuilder();
53+
54+
for ( var i = 0; i <= count; i++ )
55+
{
56+
if ( i < count )
57+
{
58+
fragment.Append( Uri.EscapeDataString( graph.Substring( MaxUriLength * i, MaxUriLength ) ) );
59+
}
60+
else
61+
{
62+
fragment.Append( Uri.EscapeDataString( graph[( MaxUriLength * i )..] ) );
63+
}
64+
}
4465

45-
return "https://edotor.net/?engine=dot#" + Uri.EscapeDataString( writer.ToString() );
66+
return "https://edotor.net/?engine=dot#" + fragment.ToString();
4667
}
4768

4869
private TestServer CreateServer()

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/OData/Basic/Controllers/WeatherForecastsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22

3+
#pragma warning disable IDE0060 // Remove unused parameter
34
#pragma warning disable CA1822 // Mark members as static
45

56
namespace Asp.Versioning.OData.Basic.Controllers;

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/OData/Basic/given a versioned ODataController/when using a query string and split into two types.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ public async Task then_get_should_return_400_for_an_unspecified_version()
107107
var problem = await response.Content.ReadAsProblemDetailsAsync();
108108

109109
// assert
110+
111+
// change from 3.1 to 6.0; DELETE is version-neutral
112+
// and the only candidate, so GET returns 405
113+
#if NETCOREAPP3_1
114+
response.StatusCode.Should().Be( MethodNotAllowed );
115+
#else
110116
response.StatusCode.Should().Be( BadRequest );
111117
problem.Type.Should().Be( ProblemDetailsDefaults.Unspecified.Type );
118+
#endif
112119
}
113120

114121
public when_using_a_query_string_and_split_into_two_types( BasicFixture fixture, ITestOutputHelper console )

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/OData/Basic/given a versioned ODataController/when using a query string.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ public async Task then_get_should_return_400_for_an_unspecified_version()
4747
var problem = await response.Content.ReadAsProblemDetailsAsync();
4848

4949
// assert
50+
51+
// change from 3.1 to 6.0; DELETE is version-neutral
52+
// and the only candidate, so GET returns 405
53+
#if NETCOREAPP3_1
54+
response.StatusCode.Should().Be( MethodNotAllowed );
55+
#else
5056
response.StatusCode.Should().Be( BadRequest );
5157
problem.Type.Should().Be( ProblemDetailsDefaults.Unspecified.Type );
58+
#endif
5259
}
5360

5461
public when_using_a_query_string( BasicFixture fixture, ITestOutputHelper console )

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/OData/UsingConventions/given a versioned ODataController using conventions/when using a query string and split into two types.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ public async Task then_get_should_return_400_for_an_unspecified_version()
8888
{
8989
// arrange
9090

91-
9291
// act
9392
var response = await GetAsync( "api/people" );
9493
var problem = await response.Content.ReadAsProblemDetailsAsync();
9594

9695
// assert
96+
97+
// change from 3.1 to 6.0; DELETE is version-neutral
98+
// and the only candidate, so GET returns 405
99+
#if NETCOREAPP3_1
100+
response.StatusCode.Should().Be( MethodNotAllowed );
101+
#else
97102
response.StatusCode.Should().Be( BadRequest );
98103
problem.Type.Should().Be( ProblemDetailsDefaults.Unspecified.Type );
104+
#endif
99105
}
100106

101107
public when_using_a_query_string_and_split_into_two_types( ConventionsFixture fixture ) : base( fixture ) { }

src/AspNetCore/Acceptance/Asp.Versioning.Mvc.Acceptance.Tests/OData/UsingConventions/given a versioned ODataController using conventions/when using a query string.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task then_get_should_return_200( string requestUrl )
1717

1818

1919
// act
20-
var response = (await GetAsync( requestUrl )).EnsureSuccessStatusCode();
20+
var response = ( await GetAsync( requestUrl ) ).EnsureSuccessStatusCode();
2121

2222
// assert
2323
response.Headers.GetValues( "api-supported-versions" ).Single().Should().Be( "1.0" );
@@ -47,8 +47,15 @@ public async Task then_get_should_return_400_for_an_unspecified_version()
4747
var problem = await response.Content.ReadAsProblemDetailsAsync();
4848

4949
// assert
50+
51+
// change from 3.1 to 6.0; DELETE is version-neutral
52+
// and the only candidate, so GET returns 405
53+
#if NETCOREAPP3_1
54+
response.StatusCode.Should().Be( MethodNotAllowed );
55+
#else
5056
response.StatusCode.Should().Be( BadRequest );
5157
problem.Type.Should().Be( ProblemDetailsDefaults.Unspecified.Type );
58+
#endif
5259
}
5360

5461
public when_using_a_query_string( ConventionsFixture fixture ) : base( fixture ) { }

src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/Asp.Versioning.OData.ApiExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<VersionPrefix>6.0.0</VersionPrefix>
55
<AssemblyVersion>6.0.0.0</AssemblyVersion>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
77
<RootNamespace>Asp.Versioning</RootNamespace>
88
<AssemblyTitle>ASP.NET Core API Versioning API Explorer for OData v4.0</AssemblyTitle>
99
<Description>The API Explorer extensions for ASP.NET Core API Versioning and OData v4.0.</Description>

src/AspNetCore/OData/src/Asp.Versioning.OData/Asp.Versioning.OData.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<VersionPrefix>6.0.0</VersionPrefix>
55
<AssemblyVersion>6.0.0.0</AssemblyVersion>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
77
<RootNamespace>Asp.Versioning</RootNamespace>
88
<AssemblyTitle>ASP.NET Core API Versioning with OData v4.0</AssemblyTitle>
99
<Description>A service API versioning library for Microsoft ASP.NET Core with OData v4.0.</Description>
@@ -14,6 +14,16 @@
1414
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1515
</ItemGroup>
1616

17+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
18+
<Compile Remove="net6.0\**\*.cs" />
19+
<None Include="net6.0\**\*.cs" />
20+
</ItemGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
23+
<Compile Remove="netcoreapp3.1\**\*.cs" />
24+
<None Include="netcoreapp3.1\**\*.cs" />
25+
</ItemGroup>
26+
1727
<ItemGroup>
1828
<PackageReference Include="Microsoft.AspNetCore.OData" Version="[8.0.8,9.0.0)" />
1929
</ItemGroup>

src/AspNetCore/OData/src/Asp.Versioning.OData/DependencyInjection/IApiVersioningBuilderExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ namespace Microsoft.Extensions.DependencyInjection;
2121
/// <summary>
2222
/// Provides ASP.NET Core OData specific extension methods for <see cref="IApiVersioningBuilder"/>.
2323
/// </summary>
24+
#if NETCOREAPP3_1
25+
[CLSCompliant( false )]
26+
#endif
2427
public static class IApiVersioningBuilderExtensions
2528
{
2629
/// <summary>

src/AspNetCore/OData/src/Asp.Versioning.OData/OData/ODataApiVersioningOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Asp.Versioning.OData;
99
/// Represents the possible API versioning options for OData services.
1010
/// </summary>
1111
[CLSCompliant( false )]
12-
public class ODataApiVersioningOptions
12+
public partial class ODataApiVersioningOptions
1313
{
1414
private Dictionary<string, Action<IServiceCollection>>? configurations;
1515

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning.OData;
4+
5+
using Microsoft.Extensions.Options;
6+
using System.ComponentModel;
7+
8+
/// <content>
9+
/// Additional implementation specific ASP.NET Core 3.1.
10+
/// </content>
11+
public partial class ODataApiVersioningOptions
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="ODataApiVersioningOptions"/> class.
15+
/// </summary>
16+
/// <remarks>This constructor is meant to serve the public parameter type constraint of
17+
/// <see cref="IOptionsFactory{T}"/>, but should not be used.</remarks>
18+
[EditorBrowsable( EditorBrowsableState.Never )]
19+
public ODataApiVersioningOptions() :
20+
this( new( new ODataApiVersionCollectionProvider(), Enumerable.Empty<IModelConfiguration>() ) )
21+
{
22+
}
23+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+
namespace Asp.Versioning.OData;
4+
5+
using Microsoft.Extensions.Options;
6+
7+
/// <summary>
8+
/// Represents a factory to create API versioning options specific to OData.
9+
/// </summary>
10+
[CLSCompliant( false )]
11+
public class ODataApiVersioningOptionsFactory : IOptionsFactory<ODataApiVersioningOptions>
12+
{
13+
private readonly IConfigureOptions<ODataApiVersioningOptions>[] setups;
14+
private readonly IPostConfigureOptions<ODataApiVersioningOptions>[] postConfigures;
15+
private readonly VersionedODataModelBuilder modelBuilder;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="ODataApiVersioningOptionsFactory"/> class.
19+
/// </summary>
20+
/// <param name="modelBuilder">The associated <see cref="VersionedODataModelBuilder">model builder</see>.</param>
21+
/// <param name="setups">The <see cref="IEnumerable{T}">sequence</see> of
22+
/// <see cref="IConfigureOptions{TOptions}">configuration actions</see> to run.</param>
23+
/// <param name="postConfigures">The <see cref="IEnumerable{T}">sequence</see> of
24+
/// <see cref="IPostConfigureOptions{TOptions}">initialization actions</see> to run.</param>
25+
public ODataApiVersioningOptionsFactory(
26+
VersionedODataModelBuilder modelBuilder,
27+
IEnumerable<IConfigureOptions<ODataApiVersioningOptions>> setups,
28+
IEnumerable<IPostConfigureOptions<ODataApiVersioningOptions>> postConfigures )
29+
{
30+
this.setups = setups as IConfigureOptions<ODataApiVersioningOptions>[] ?? new List<IConfigureOptions<ODataApiVersioningOptions>>( setups ).ToArray();
31+
this.postConfigures = postConfigures as IPostConfigureOptions<ODataApiVersioningOptions>[] ?? new List<IPostConfigureOptions<ODataApiVersioningOptions>>( postConfigures ).ToArray();
32+
this.modelBuilder = modelBuilder ?? throw new ArgumentNullException( nameof( modelBuilder ) );
33+
}
34+
35+
/// <inheritdoc />
36+
public virtual ODataApiVersioningOptions Create( string name )
37+
{
38+
var options = new ODataApiVersioningOptions( modelBuilder );
39+
40+
foreach ( var setup in setups )
41+
{
42+
if ( setup is IConfigureNamedOptions<ODataApiVersioningOptions> namedSetup )
43+
{
44+
namedSetup.Configure( name, options );
45+
}
46+
else if ( name == Options.DefaultName )
47+
{
48+
setup.Configure( options );
49+
}
50+
}
51+
52+
foreach ( var post in postConfigures )
53+
{
54+
post.PostConfigure( name, options );
55+
}
56+
57+
return options;
58+
}
59+
}

src/AspNetCore/OData/test/Asp.Versioning.OData.ApiExplorer.Tests/Asp.Versioning.OData.ApiExplorer.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
55
<RootNamespace>Asp.Versioning</RootNamespace>
66
</PropertyGroup>
77

src/AspNetCore/OData/test/Asp.Versioning.OData.Tests/Asp.Versioning.OData.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
55
<RootNamespace>Asp.Versioning</RootNamespace>
66
</PropertyGroup>
77

src/AspNetCore/WebApi/src/Asp.Versioning.Http/Asp.Versioning.Http.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<VersionPrefix>6.0.0</VersionPrefix>
55
<AssemblyVersion>6.0.0.0</AssemblyVersion>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
77
<RootNamespace>Asp.Versioning</RootNamespace>
88
<AssemblyTitle>ASP.NET Core API Versioning</AssemblyTitle>
99
<Description>A service API versioning library for Microsoft ASP.NET Core.</Description>
@@ -14,6 +14,16 @@
1414
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1515
</ItemGroup>
1616

17+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
18+
<Compile Remove="net6.0\**\*.cs" />
19+
<None Include="net6.0\**\*.cs" />
20+
</ItemGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
23+
<Compile Remove="netcoreapp3.1\**\*.cs" />
24+
<None Include="netcoreapp3.1\**\*.cs" />
25+
</ItemGroup>
26+
1727
<ItemGroup>
1828
<ProjectReference Include="..\..\..\..\Abstractions\src\Asp.Versioning.Abstractions\Asp.Versioning.Abstractions.csproj" />
1929
</ItemGroup>

src/AspNetCore/WebApi/src/Asp.Versioning.Http/IApiVersioningBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Asp.Versioning;
77
/// <summary>
88
/// Defines the behavior for configuring API versioning.
99
/// </summary>
10-
public interface IApiVersioningBuilder
10+
public partial interface IApiVersioningBuilder
1111
{
1212
/// <summary>
1313
/// Gets the services used when configuring API versioning.

0 commit comments

Comments
 (0)