Browse Source

Send version for query string or path in C# client.

pull/122/head
Halil İbrahim Kalkan 9 years ago
parent
commit
515bd63f1c
  1. 2
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs
  2. 4
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  3. 1
      src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs
  4. 22
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiVersionInfo.cs
  5. 33
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  6. 2
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs
  7. 38
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs
  8. 13
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs
  9. 2
      src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs
  10. 28
      src/Volo.Abp/System/Collections/Generic/AbpDictionaryExtensions.cs
  11. 3
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo.Abp.AspNetCore.Mvc.Versioning.Tests.csproj
  12. 28
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs
  13. 9
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/Compat/ITodoAppService.cs
  14. 24
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/Compat/TodoAppService.cs
  15. 17
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs
  16. 10
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/IHelloController.cs
  17. 23
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/Compat/TodoAppService_Tests.cs
  18. 24
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/HelloController_Tests.cs
  19. 2
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/TodoAppService_Tests.cs

2
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs

@ -43,7 +43,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[CanBeNull] [CanBeNull]
public Func<UrlActionNameNormalizerContext, string> UrlActionNameNormalizer { get; set; } public Func<UrlActionNameNormalizerContext, string> UrlActionNameNormalizer { get; set; }
public List<ApiVersion> ApiVersions { get; set; } public List<ApiVersion> ApiVersions { get; }
public Action<ApiVersioningOptions> ApiVersionConfigurer { get; set; } public Action<ApiVersioningOptions> ApiVersionConfigurer { get; set; }

4
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
@ -80,7 +81,8 @@ namespace Volo.Abp.AspNetCore.Mvc
var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create( var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
method, method,
apiDescription.RelativePath, apiDescription.RelativePath,
apiDescription.HttpMethod apiDescription.HttpMethod,
setting?.ApiVersions.Select(v => v.ToString()).ToList() ?? new List<string>()
)); ));
AddParameterDescriptionsToModel(actionModel, method, apiDescription); AddParameterDescriptionsToModel(actionModel, method, apiDescription);

1
src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs

@ -15,6 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddHttpClientProxies(this IServiceCollection services, Assembly assembly, string remoteServiceName = RemoteServiceConfigurationDictionary.DefaultName) public static IServiceCollection AddHttpClientProxies(this IServiceCollection services, Assembly assembly, string remoteServiceName = RemoteServiceConfigurationDictionary.DefaultName)
{ {
//TODO: Make a configuration option and add remoteServiceName inside it!
//TODO: Add option to change type filter //TODO: Add option to change type filter
var serviceTypes = assembly.GetTypes().Where(t => var serviceTypes = assembly.GetTypes().Where(t =>

22
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiVersionInfo.cs

@ -0,0 +1,22 @@
using System;
namespace Volo.Abp.Http.Client.DynamicProxying
{
internal class ApiVersionInfo
{
public string BindingSource { get; }
public string Version { get; }
public ApiVersionInfo(string bindingSource, string version)
{
BindingSource = bindingSource;
Version = version;
}
public bool ShouldSendInQueryString()
{
//TODO: Constant! TODO: Other sources!
return !BindingSource.IsIn("Path");
}
}
}

33
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

@ -57,7 +57,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
else else
{ {
var responseAsString = AsyncHelper.RunSync(() => MakeRequest(invocation)); var responseAsString = AsyncHelper.RunSync(() => MakeRequest(invocation));
//TODO: Think on that //TODO: Think on that
if (TypeHelper.IsPrimitiveExtendedIncludingNullable(invocation.Method.ReturnType, true)) if (TypeHelper.IsPrimitiveExtendedIncludingNullable(invocation.Method.ReturnType, true))
{ {
@ -105,10 +105,9 @@ namespace Volo.Abp.Http.Client.DynamicProxying
using (var client = _httpClientFactory.Create()) using (var client = _httpClientFactory.Create())
{ {
var baseUrl = GetBaseUrl(); var baseUrl = GetBaseUrl();
var version = GetVersion(); //TODO: Add version to the request (querystring, media type, path value or custom header!)
var action = await _apiDescriptionFinder.FindActionAsync(baseUrl, typeof(TService), invocation.Method); var action = await _apiDescriptionFinder.FindActionAsync(baseUrl, typeof(TService), invocation.Method);
var url = baseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary); var apiVersion = GetApiVersionInfo(action);
var url = baseUrl + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion);
var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url)
{ {
@ -128,6 +127,30 @@ namespace Volo.Abp.Http.Client.DynamicProxying
} }
} }
private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action)
{
var apiVersion = FindBestApiVersion(action);
var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion");
return new ApiVersionInfo(versionParam?.BindingSourceId, apiVersion);
}
private string FindBestApiVersion(ActionApiDescriptionModel action)
{
var configuredVersion = GetConfiguredApiVersion();
if (action.SupportedVersions.IsNullOrEmpty())
{
return configuredVersion ?? "1.0";
}
if (action.SupportedVersions.Contains(configuredVersion))
{
return configuredVersion;
}
return action.SupportedVersions.Last(); //TODO: Ensure to get the latest version!
}
private static void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage) private static void AddHeaders(IAbpMethodInvocation invocation, ActionApiDescriptionModel action, HttpRequestMessage requestMessage)
{ {
foreach (var headerParameter in action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header)) foreach (var headerParameter in action.Parameters.Where(p => p.BindingSourceId == ParameterBindingSources.Header))
@ -150,7 +173,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
?? throw new AbpException($"Could not find Base URL for {typeof(TService).FullName}."); ?? throw new AbpException($"Could not find Base URL for {typeof(TService).FullName}.");
} }
private string GetVersion() private string GetConfiguredApiVersion()
{ {
var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) var clientConfig = _clientOptions.HttpClientProxies.GetOrDefault(typeof(TService))
?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}.");

2
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpActionParameterHelper.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
public static object FindParameterValue(IReadOnlyDictionary<string, object> methodArguments, ParameterApiDescriptionModel apiParameter) public static object FindParameterValue(IReadOnlyDictionary<string, object> methodArguments, ParameterApiDescriptionModel apiParameter)
{ {
var value = methodArguments[apiParameter.NameOnMethod]; var value = methodArguments.GetOrDefault(apiParameter.NameOnMethod);
if (value == null) if (value == null)
{ {
return null; return null;

38
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs

@ -9,17 +9,17 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{ {
internal static class UrlBuilder internal static class UrlBuilder
{ {
public static string GenerateUrlWithParameters(ActionApiDescriptionModel action, IReadOnlyDictionary<string, object> methodArguments) public static string GenerateUrlWithParameters(ActionApiDescriptionModel action, IReadOnlyDictionary<string, object> methodArguments, ApiVersionInfo apiVersion)
{ {
var urlBuilder = new StringBuilder(action.Url); var urlBuilder = new StringBuilder(action.Url);
ReplacePathVariables(urlBuilder, action.Parameters, methodArguments); ReplacePathVariables(urlBuilder, action.Parameters, methodArguments, apiVersion);
AddQueryStringParameters(urlBuilder, action.Parameters, methodArguments); AddQueryStringParameters(urlBuilder, action.Parameters, methodArguments, apiVersion);
return urlBuilder.ToString(); return urlBuilder.ToString();
} }
private static void ReplacePathVariables(StringBuilder urlBuilder, IList<ParameterApiDescriptionModel> actionParameters, IReadOnlyDictionary<string, object> methodArguments) private static void ReplacePathVariables(StringBuilder urlBuilder, IList<ParameterApiDescriptionModel> actionParameters, IReadOnlyDictionary<string, object> methodArguments, ApiVersionInfo apiVersion)
{ {
var pathParameters = actionParameters var pathParameters = actionParameters
.Where(p => p.BindingSourceId == ParameterBindingSources.Path) .Where(p => p.BindingSourceId == ParameterBindingSources.Path)
@ -30,9 +30,15 @@ namespace Volo.Abp.Http.Client.DynamicProxying
return; return;
} }
foreach (var pathParameter in pathParameters) if (pathParameters.Any(p => p.Name == "apiVersion"))
{
urlBuilder = urlBuilder.Replace("{apiVersion}", apiVersion.Version);
}
foreach (var pathParameter in pathParameters.Where(p => p.Name != "apiVersion")) //TODO: Constant!
{ {
var value = HttpActionParameterHelper.FindParameterValue(methodArguments, pathParameter); var value = HttpActionParameterHelper.FindParameterValue(methodArguments, pathParameter);
if (value == null) if (value == null)
{ {
if (pathParameter.IsOptional) if (pathParameter.IsOptional)
@ -55,18 +61,14 @@ namespace Volo.Abp.Http.Client.DynamicProxying
} }
} }
private static void AddQueryStringParameters(StringBuilder urlBuilder, IList<ParameterApiDescriptionModel> actionParameters, IReadOnlyDictionary<string, object> methodArguments) private static void AddQueryStringParameters(StringBuilder urlBuilder, IList<ParameterApiDescriptionModel> actionParameters, IReadOnlyDictionary<string, object> methodArguments, ApiVersionInfo apiVersion)
{ {
var queryStringParameters = actionParameters var queryStringParameters = actionParameters
.Where(p => p.BindingSourceId.IsIn(ParameterBindingSources.ModelBinding, ParameterBindingSources.Query)) .Where(p => p.BindingSourceId.IsIn(ParameterBindingSources.ModelBinding, ParameterBindingSources.Query))
.ToArray(); .ToArray();
if (!queryStringParameters.Any())
{
return;
}
var isFirstParam = true; var isFirstParam = true;
foreach (var queryStringParameter in queryStringParameters) foreach (var queryStringParameter in queryStringParameters)
{ {
var value = HttpActionParameterHelper.FindParameterValue(methodArguments, queryStringParameter); var value = HttpActionParameterHelper.FindParameterValue(methodArguments, queryStringParameter);
@ -75,11 +77,21 @@ namespace Volo.Abp.Http.Client.DynamicProxying
continue; continue;
} }
urlBuilder.Append(isFirstParam ? "?" : "&"); AddQueryStringParameter(urlBuilder, isFirstParam, queryStringParameter.Name, value);
urlBuilder.Append(queryStringParameter.Name + "=" + System.Net.WebUtility.UrlEncode(value.ToString()));
isFirstParam = false; isFirstParam = false;
} }
if (apiVersion.ShouldSendInQueryString())
{
AddQueryStringParameter(urlBuilder, isFirstParam, "apiVersion", apiVersion.Version); //TODO: Constant!
}
}
private static void AddQueryStringParameter(StringBuilder urlBuilder, bool isFirstParam, string name, object value)
{
urlBuilder.Append(isFirstParam ? "?" : "&");
urlBuilder.Append(name + "=" + System.Net.WebUtility.UrlEncode(value.ToString()));
} }
} }
} }

13
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ActionApiDescriptionModel.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using JetBrains.Annotations;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
{ {
@ -15,6 +16,8 @@ namespace Volo.Abp.Http.Modeling
public string Url { get; set; } public string Url { get; set; }
public IList<string> SupportedVersions { get; set; }
public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; } public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; }
public IList<ParameterApiDescriptionModel> Parameters { get; set; } public IList<ParameterApiDescriptionModel> Parameters { get; set; }
@ -26,8 +29,13 @@ namespace Volo.Abp.Http.Modeling
} }
public static ActionApiDescriptionModel Create(MethodInfo method, string url, string httpMethod) public static ActionApiDescriptionModel Create([NotNull] MethodInfo method, [NotNull] string url, [NotNull] string httpMethod, [NotNull] IList<string> supportedVersions)
{ {
Check.NotNull(method, nameof(method));
Check.NotNull(url, nameof(url));
Check.NotNull(httpMethod, nameof(httpMethod));
Check.NotNull(supportedVersions, nameof(supportedVersions));
return new ActionApiDescriptionModel return new ActionApiDescriptionModel
{ {
Name = method.Name, Name = method.Name,
@ -38,7 +46,8 @@ namespace Volo.Abp.Http.Modeling
ParametersOnMethod = method ParametersOnMethod = method
.GetParameters() .GetParameters()
.Select(MethodParameterApiDescriptionModel.Create) .Select(MethodParameterApiDescriptionModel.Create)
.ToList() .ToList(),
SupportedVersions = supportedVersions
}; };
} }

2
src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs

@ -30,7 +30,7 @@ namespace Volo.Abp.Http.Modeling
{ {
Name = name, Name = name,
NameOnMethod = nameOnMethod, NameOnMethod = nameOnMethod,
TypeAsString = type.GetFullNameWithAssemblyName(), TypeAsString = type?.GetFullNameWithAssemblyName(),
IsOptional = isOptional, IsOptional = isOptional,
DefaultValue = defaultValue, DefaultValue = defaultValue,
ConstraintTypes = constraintTypes, ConstraintTypes = constraintTypes,

28
src/Volo.Abp/System/Collections/Generic/AbpDictionaryExtensions.cs

@ -26,6 +26,20 @@ namespace System.Collections.Generic
return false; return false;
} }
/// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
{
TValue obj;
return dictionary.TryGetValue(key, out obj) ? obj : default(TValue);
}
/// <summary> /// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find. /// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary> /// </summary>
@ -40,6 +54,20 @@ namespace System.Collections.Generic
return dictionary.TryGetValue(key, out obj) ? obj : default(TValue); return dictionary.TryGetValue(key, out obj) ? obj : default(TValue);
} }
/// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public static TValue GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
{
TValue obj;
return dictionary.TryGetValue(key, out obj) ? obj : default(TValue);
}
/// <summary> /// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find. /// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary> /// </summary>

3
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo.Abp.AspNetCore.Mvc.Versioning.Tests.csproj

@ -35,9 +35,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Volo\Abp\AspNetCore\Mvc\Versioning\App\Compat\" />
</ItemGroup>
<!-- https://github.com/NuGet/Home/issues/4412. --> <!-- https://github.com/NuGet/Home/issues/4412. -->
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''"> <Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''">

28
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Modularity; using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc.Versioning.App; using Volo.Abp.AspNetCore.Mvc.Versioning.App;
@ -23,15 +25,35 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning
services.Configure<AbpAspNetCoreMvcOptions>(options => services.Configure<AbpAspNetCoreMvcOptions>(options =>
{ {
//2.0 Version
options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts =>
{ {
opts.TypePredicate = t => t.Namespace == typeof(Volo.Abp.AspNetCore.Mvc.Versioning.App.TodoAppService).Namespace;
opts.ApiVersions.Add(new ApiVersion(2, 0));
});
//1.0 Compatability version
options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts =>
{
opts.TypePredicate = t => t.Namespace == typeof(Volo.Abp.AspNetCore.Mvc.Versioning.App.Compat.TodoAppService).Namespace;
opts.ApiVersions.Add(new ApiVersion(1, 0));
opts.RootPath = "app/compat";
}); });
}); });
services.AddAssemblyOf<AbpAspNetCoreMvcVersioningTestModule>(); services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = new QueryStringApiVersionReader("apiVersion");
services.AddHttpClientProxy<ITodoAppService>(); options.ConfigureAbp(services);
});
services.AddAssemblyOf<AbpAspNetCoreMvcVersioningTestModule>();
services.AddHttpClientProxies(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly);
services.Configure<RemoteServiceOptions>(options => services.Configure<RemoteServiceOptions>(options =>
{ {

9
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/Compat/ITodoAppService.cs

@ -0,0 +1,9 @@
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.Compat
{
public interface ITodoAppService : IApplicationService
{
string Get(int id);
}
}

24
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/Compat/TodoAppService.cs

@ -0,0 +1,24 @@
using Volo.Abp.ApiVersioning;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.Compat
{
public class TodoAppService : ITodoAppService
{
private readonly IRequestedApiVersion _requestedApiVersion;
public TodoAppService(IRequestedApiVersion requestedApiVersion)
{
_requestedApiVersion = requestedApiVersion;
}
public string Get(int id)
{
return "Compat-" + id + "-" + GetVersionOrNone();
}
private string GetVersionOrNone()
{
return _requestedApiVersion.Current ?? "NONE";
}
}
}

17
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs

@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App
{
[ApiVersion("1.0")]
[ApiVersion("2.0")]
[Route("api/v{apiVersion:apiVersion}/[controller]")]
public class HelloController : AbpController, IHelloController
{
[HttpPost]
public Task<string> PostAsync()
{
return Task.FromResult($"42-{HttpContext.GetRequestedApiVersion().ToString()}");
}
}
}

10
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/IHelloController.cs

@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App
{
public interface IHelloController : IRemoteService
{
Task<string> PostAsync();
}
}

23
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/Compat/TodoAppService_Tests.cs

@ -0,0 +1,23 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.AspNetCore.Mvc.Versioning.App.Compat;
using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test.Compat
{
public class TodoAppService_Tests : AspNetCoreMvcVersioningTestBase
{
private readonly ITodoAppService _todoAppService;
public TodoAppService_Tests()
{
_todoAppService = ServiceProvider.GetRequiredService<ITodoAppService>();
}
[Fact]
public void Get()
{
_todoAppService.Get(42).ShouldBe("Compat-42-1.0");
}
}
}

24
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/HelloController_Tests.cs

@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.AspNetCore.Mvc.Versioning.App;
using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test
{
public class HelloController_Tests: AspNetCoreMvcVersioningTestBase
{
private readonly IHelloController _todoAppService;
public HelloController_Tests()
{
_todoAppService = ServiceProvider.GetRequiredService<IHelloController>();
}
[Fact]
public async Task PostAsync()
{
(await _todoAppService.PostAsync()).ShouldBe("42-2.0");
}
}
}

2
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/TodoAppService_Tests.cs

@ -17,7 +17,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test
[Fact] [Fact]
public void Get() public void Get()
{ {
_todoAppService.Get(42).ShouldBe("42-NONE"); _todoAppService.Get(42).ShouldBe("42-2.0");
} }
} }
} }

Loading…
Cancel
Save