Browse Source

Created unit tests.

pull/122/head
Halil İbrahim Kalkan 8 years ago
parent
commit
a5c8e82e2c
  1. 11
      Volo.Abp.sln
  2. 8
      src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs
  3. 3
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs
  4. 18
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  5. 3
      src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs
  6. 2
      src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs
  7. 3
      src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
  8. 14
      src/Volo.Abp/Volo/Abp/ApiVersioning/NullRequestedApiVersion.cs
  9. 3
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
  10. 2
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs
  11. 51
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo.Abp.AspNetCore.Mvc.Versioning.Tests.csproj
  12. 48
      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/ITodoAppService.cs
  14. 24
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/TodoAppService.cs
  15. 6
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs
  16. 27
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs
  17. 23
      test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/TodoAppService_Tests.cs
  18. 0
      test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs
  19. 1
      test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpTestBase.cs
  20. 2
      test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpTestModule.cs

11
Volo.Abp.sln

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}"
EndProject
@ -142,7 +142,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.EntityFrameworkCor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleConsoleDemo", "test\SimpleConsoleDemo\SimpleConsoleDemo.csproj", "{2B48CF90-DBDB-469F-941C-5B5AECEEACE0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.EntityFrameworkCore.Tests.SecondContext", "test\Volo.Abp.EntityFrameworkCore.Tests.SecondContext\Volo.Abp.EntityFrameworkCore.Tests.SecondContext.csproj", "{127FC2BF-DC40-4370-B845-16088328264C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.EntityFrameworkCore.Tests.SecondContext", "test\Volo.Abp.EntityFrameworkCore.Tests.SecondContext\Volo.Abp.EntityFrameworkCore.Tests.SecondContext.csproj", "{127FC2BF-DC40-4370-B845-16088328264C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Versioning.Tests", "test\Volo.Abp.AspNetCore.Mvc.Versioning.Tests\Volo.Abp.AspNetCore.Mvc.Versioning.Tests.csproj", "{A8C8B76D-0869-4C11-AC55-DB9DD115788E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -366,6 +368,10 @@ Global
{127FC2BF-DC40-4370-B845-16088328264C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{127FC2BF-DC40-4370-B845-16088328264C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{127FC2BF-DC40-4370-B845-16088328264C}.Release|Any CPU.Build.0 = Release|Any CPU
{A8C8B76D-0869-4C11-AC55-DB9DD115788E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8C8B76D-0869-4C11-AC55-DB9DD115788E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8C8B76D-0869-4C11-AC55-DB9DD115788E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8C8B76D-0869-4C11-AC55-DB9DD115788E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -434,6 +440,7 @@ Global
{3AF7C7F5-6513-47D4-8DD0-6E1AF14568D8} = {37087D1B-3693-4E96-983D-A69F210BDE53}
{2B48CF90-DBDB-469F-941C-5B5AECEEACE0} = {37087D1B-3693-4E96-983D-A69F210BDE53}
{127FC2BF-DC40-4370-B845-16088328264C} = {37087D1B-3693-4E96-983D-A69F210BDE53}
{A8C8B76D-0869-4C11-AC55-DB9DD115788E} = {37087D1B-3693-4E96-983D-A69F210BDE53}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

8
src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs

@ -3,19 +3,23 @@ using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.Mvc.Versioning.Conventions;
using Volo.Abp.ApiVersioning;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Versioning;
namespace Microsoft.Extensions.DependencyInjection
{
public static class AbpApiVersioningOptionsExtensions
{
public static void ConfigureAbpModules(this ApiVersioningOptions options, IServiceCollection services)
public static void ConfigureAbp(this ApiVersioningOptions options, IServiceCollection services)
{
//TODO: Use new builder will be released with Api Versioning 2.1 instead of reflection!
services.AddTransient<IRequestedApiVersion, HttpContextRequestedApiVersion>();
services.Configure<AbpAspNetCoreMvcOptions>(op =>
{
//TODO: Configuring api version should be done directly inside ConfigureAbpModules,
//TODO: Configuring api version should be done directly inside ConfigureAbp,
//TODO: not in a callback that will be called by MVC later! For that, we immediately need to controllerAssemblySettings
foreach (var setting in op.AppServiceControllers.ControllerAssemblySettings)

3
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Versioning/HttpContextRequestedApiVersion.cs

@ -1,11 +1,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.ApiVersioning;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Mvc.Versioning
{
public class HttpContextRequestedApiVersion : IRequestedApiVersion, ITransientDependency
public class HttpContextRequestedApiVersion : IRequestedApiVersion
{
public string Current => _httpContextAccessor.HttpContext?.GetRequestedApiVersion().ToString();

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

@ -56,10 +56,20 @@ namespace Volo.Abp.Http.Client.DynamicProxying
}
else
{
invocation.ReturnValue = _jsonSerializer.Deserialize(
invocation.Method.ReturnType,
AsyncHelper.RunSync(() => MakeRequest(invocation))
);
var responseAsString = AsyncHelper.RunSync(() => MakeRequest(invocation));
//TODO: Think on that
if (TypeHelper.IsPrimitiveExtendedIncludingNullable(invocation.Method.ReturnType, true))
{
invocation.ReturnValue = Convert.ChangeType(responseAsString, invocation.Method.ReturnType);
}
else
{
invocation.ReturnValue = _jsonSerializer.Deserialize(
invocation.Method.ReturnType,
responseAsString
);
}
}
}

3
src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs

@ -11,9 +11,10 @@
}
public RemoteServiceConfiguration(string baseUrl)
public RemoteServiceConfiguration(string baseUrl, string version = null)
{
BaseUrl = baseUrl;
Version = version;
}
}
}

2
src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs

@ -60,7 +60,7 @@ namespace Volo.Abp.Identity.HttpApi.Host
//o.Conventions.Controller<IdentityUserAppService>().HasApiVersion(2, 0);
//o.Conventions.Controller<IdentityRoleAppService>().IsApiVersionNeutral();
o.ConfigureAbpModules(services);
o.ConfigureAbp(services);
});
services.AddSwaggerGen(

3
src/Volo.Abp/Volo/Abp/AbpKernelModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.ApiVersioning;
using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Reflection;
@ -33,6 +34,8 @@ namespace Volo.Abp
services.AddLogging();
services.AddAssemblyOf<AbpKernelModule>();
services.AddSingleton<IRequestedApiVersion>(NullRequestedApiVersion.Instance);
services.Configure<ModuleLifecycleOptions>(options =>
{

14
src/Volo.Abp/Volo/Abp/ApiVersioning/NullRequestedApiVersion.cs

@ -0,0 +1,14 @@
namespace Volo.Abp.ApiVersioning
{
public class NullRequestedApiVersion : IRequestedApiVersion
{
public static NullRequestedApiVersion Instance = new NullRequestedApiVersion();
public string Current => null;
private NullRequestedApiVersion()
{
}
}
}

3
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/AbpAspNetCoreMvcTestModule.cs → test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs

@ -2,14 +2,13 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Autofac;
using Volo.Abp.MemoryDb;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp;
namespace Volo.Abp.AspNetCore.App
namespace Volo.Abp.AspNetCore.Mvc
{
[DependsOn(
typeof(AbpAspNetCoreTestBaseModule),

2
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Startup.cs → test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs

@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Volo.Abp.AspNetCore.App
namespace Volo.Abp.AspNetCore.Mvc
{
public class Startup
{

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

@ -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>

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

@ -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();
}
}
}

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

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

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

@ -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";
}
}
}

6
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs

@ -0,0 +1,6 @@
namespace Volo.Abp.AspNetCore.Mvc.Versioning
{
public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase<Startup>
{
}
}

27
test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs

@ -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();
}
}
}

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

@ -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");
}
}
}

0
test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AppTestBase.cs → test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs

1
test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpTestBase.cs

@ -1,5 +1,4 @@
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.App;
namespace Volo.Abp.Http
{

2
test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpTestModule.cs

@ -1,5 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.App;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.DynamicProxying;
using Volo.Abp.Modularity;

Loading…
Cancel
Save