mirror of https://github.com/abpframework/abp.git
20 changed files with 241 additions and 17 deletions
@ -0,0 +1,14 @@ |
|||||
|
namespace Volo.Abp.ApiVersioning |
||||
|
{ |
||||
|
public class NullRequestedApiVersion : IRequestedApiVersion |
||||
|
{ |
||||
|
public static NullRequestedApiVersion Instance = new NullRequestedApiVersion(); |
||||
|
|
||||
|
public string Current => null; |
||||
|
|
||||
|
private NullRequestedApiVersion() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.0</TargetFramework> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<AssemblyName>Volo.Abp.AspNetCore.Mvc.Versioning.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.AspNetCore.Mvc.Versioning.Tests</PackageId> |
||||
|
<PreserveCompilationContext>true</PreserveCompilationContext> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
||||
|
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> |
||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Tests\Volo.Abp.AspNetCore.Tests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<!-- Below ItemGroup and Target tags are added according to https://github.com/aspnet/Hosting/issues/959#issuecomment-286351703 --> |
||||
|
|
||||
|
<!-- Solves Problem#2 (404 when executing service calls hosted in other assemblies) --> |
||||
|
<!-- https://github.com/Microsoft/vstest/issues/196.--> |
||||
|
<ItemGroup> |
||||
|
<None Update="xunit.runner.json"> |
||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
|
</None> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Folder Include="Volo\Abp\AspNetCore\Mvc\Versioning\App\Compat\" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<!-- https://github.com/NuGet/Home/issues/4412. --> |
||||
|
<Target Name="CopyDepsFiles" AfterTargets="Build" Condition="'$(TargetFramework)'!=''"> |
||||
|
<ItemGroup> |
||||
|
<DepsFilePaths Include="$([System.IO.Path]::ChangeExtension('%(_ResolvedProjectReferencePaths.FullPath)', '.deps.json'))" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<Copy SourceFiles="%(DepsFilePaths.FullPath)" DestinationFolder="$(OutputPath)" Condition="Exists('%(DepsFilePaths.FullPath)')" /> |
||||
|
</Target> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,48 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.AspNetCore.Modularity; |
||||
|
using Volo.Abp.AspNetCore.Mvc.Versioning.App; |
||||
|
using Volo.Abp.AspNetCore.TestBase; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Http.Client; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpAspNetCoreTestBaseModule), |
||||
|
typeof(AbpAspNetCoreMvcModule), |
||||
|
typeof(AbpAutofacModule), |
||||
|
typeof(AbpHttpClientModule) |
||||
|
)] |
||||
|
public class AbpAspNetCoreMvcVersioningTestModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddMvc(); |
||||
|
|
||||
|
services.Configure<AbpAspNetCoreMvcOptions>(options => |
||||
|
{ |
||||
|
options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => |
||||
|
{ |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
services.AddAssemblyOf<AbpAspNetCoreMvcVersioningTestModule>(); |
||||
|
|
||||
|
services.AddHttpClientProxy<ITodoAppService>(); |
||||
|
|
||||
|
services.Configure<RemoteServiceOptions>(options => |
||||
|
{ |
||||
|
options.RemoteServices.Default = new RemoteServiceConfiguration("/"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
|
app.UseMvcWithDefaultRoute(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App |
||||
|
{ |
||||
|
public interface ITodoAppService : IApplicationService |
||||
|
{ |
||||
|
string Get(int id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using Volo.Abp.ApiVersioning; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App |
||||
|
{ |
||||
|
public class TodoAppService : ITodoAppService |
||||
|
{ |
||||
|
private readonly IRequestedApiVersion _requestedApiVersion; |
||||
|
|
||||
|
public TodoAppService(IRequestedApiVersion requestedApiVersion) |
||||
|
{ |
||||
|
_requestedApiVersion = requestedApiVersion; |
||||
|
} |
||||
|
|
||||
|
public string Get(int id) |
||||
|
{ |
||||
|
return id + "-" + GetVersionOrNone(); |
||||
|
} |
||||
|
|
||||
|
private string GetVersionOrNone() |
||||
|
{ |
||||
|
return _requestedApiVersion.Current ?? "NONE"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning |
||||
|
{ |
||||
|
public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase<Startup> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning |
||||
|
{ |
||||
|
public class Startup |
||||
|
{ |
||||
|
public IServiceProvider ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddApplication<AbpAspNetCoreMvcVersioningTestModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
}); |
||||
|
|
||||
|
//TODO: This is needed because ASP.NET Core does not use IServiceProviderFactory!
|
||||
|
return services.BuildServiceProviderFromFactory(); |
||||
|
} |
||||
|
|
||||
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
||||
|
{ |
||||
|
app.InitializeApplication(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.Mvc.Versioning.App; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test |
||||
|
{ |
||||
|
public class TodoAppService_Tests : AspNetCoreMvcVersioningTestBase |
||||
|
{ |
||||
|
private readonly ITodoAppService _todoAppService; |
||||
|
|
||||
|
public TodoAppService_Tests() |
||||
|
{ |
||||
|
_todoAppService = ServiceProvider.GetRequiredService<ITodoAppService>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Get() |
||||
|
{ |
||||
|
_todoAppService.Get(42).ShouldBe("42-NONE"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue