Browse Source

Add ValidationInterceptor.

pull/2550/head
Mehmet Tüken 7 years ago
parent
commit
d2cca7306e
  1. 6
      framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs
  2. 1
      framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj
  3. 4
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs
  4. 32
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs
  5. 15
      framework/test/Volo.Abp.TestApp.Tests/Volo/Abp/TestApp/Application/PersonAppService_Tests.cs
  6. 2
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs

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

@ -8,6 +8,7 @@ using Volo.Abp;
using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.Castle.DynamicProxy;
using Volo.Abp.Http.Client; using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.DynamicProxying; using Volo.Abp.Http.Client.DynamicProxying;
using Volo.Abp.Validation;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
@ -154,6 +155,9 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient(interceptorType); services.AddTransient(interceptorType);
var interceptorAdapterType = typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(interceptorType); var interceptorAdapterType = typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(interceptorType);
var validationInterceptorAdapterType =
typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(typeof(ValidationInterceptor));
if (asDefaultService) if (asDefaultService)
{ {
@ -162,6 +166,7 @@ namespace Microsoft.Extensions.DependencyInjection
serviceProvider => ProxyGeneratorInstance serviceProvider => ProxyGeneratorInstance
.CreateInterfaceProxyWithoutTarget( .CreateInterfaceProxyWithoutTarget(
type, type,
(IInterceptor)serviceProvider.GetRequiredService(validationInterceptorAdapterType),
(IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType) (IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType)
) )
); );
@ -174,6 +179,7 @@ namespace Microsoft.Extensions.DependencyInjection
var service = ProxyGeneratorInstance var service = ProxyGeneratorInstance
.CreateInterfaceProxyWithoutTarget( .CreateInterfaceProxyWithoutTarget(
type, type,
(IInterceptor)serviceProvider.GetRequiredService(validationInterceptorAdapterType),
(IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType) (IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType)
); );

1
framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj

@ -24,6 +24,7 @@
<ProjectReference Include="..\Volo.Abp.Http\Volo.Abp.Http.csproj" /> <ProjectReference Include="..\Volo.Abp.Http\Volo.Abp.Http.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" /> <ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" /> <ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />
<ProjectReference Include="..\Volo.Abp.Validation\Volo.Abp.Validation.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

4
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs

@ -3,6 +3,7 @@ using Volo.Abp.Castle;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Validation;
namespace Volo.Abp.Http.Client namespace Volo.Abp.Http.Client
{ {
@ -10,7 +11,8 @@ namespace Volo.Abp.Http.Client
typeof(AbpHttpModule), typeof(AbpHttpModule),
typeof(AbpCastleCoreModule), typeof(AbpCastleCoreModule),
typeof(AbpThreadingModule), typeof(AbpThreadingModule),
typeof(AbpMultiTenancyModule) typeof(AbpMultiTenancyModule),
typeof(AbpValidationModule)
)] )]
public class AbpHttpClientModule : AbpModule public class AbpHttpClientModule : AbpModule
{ {

32
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NSubstitute.Extensions;
using Shouldly; using Shouldly;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -9,6 +10,7 @@ using Volo.Abp.Http.Client;
using Volo.Abp.TestApp.Application; using Volo.Abp.TestApp.Application;
using Volo.Abp.TestApp.Application.Dto; using Volo.Abp.TestApp.Application.Dto;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
using Volo.Abp.Validation;
using Xunit; using Xunit;
namespace Volo.Abp.Http.DynamicProxying namespace Volo.Abp.Http.DynamicProxying
@ -38,7 +40,8 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact] [Fact]
public async Task GetList() public async Task GetList()
{ {
var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto()).ConfigureAwait(false); var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto())
.ConfigureAwait(false);
people.TotalCount.ShouldBeGreaterThan(0); people.TotalCount.ShouldBeGreaterThan(0);
people.Items.Count.ShouldBe((int) people.TotalCount); people.Items.Count.ShouldBe((int) people.TotalCount);
} }
@ -59,11 +62,11 @@ namespace Volo.Abp.Http.DynamicProxying
{ {
var uniquePersonName = Guid.NewGuid().ToString(); var uniquePersonName = Guid.NewGuid().ToString();
var person = await _peopleAppService.CreateAsync(new PersonDto var person = await _peopleAppService.CreateAsync(new PersonDto
{ {
Name = uniquePersonName, Name = uniquePersonName,
Age = 42 Age = 42
} }
).ConfigureAwait(false); ).ConfigureAwait(false);
person.ShouldNotBeNull(); person.ShouldNotBeNull();
@ -74,7 +77,20 @@ namespace Volo.Abp.Http.DynamicProxying
personInDb.ShouldNotBeNull(); personInDb.ShouldNotBeNull();
personInDb.Id.ShouldBe(person.Id); personInDb.Id.ShouldBe(person.Id);
} }
[Fact]
public async Task Create_Validate_Exception()
{
await Assert.ThrowsAsync<AbpValidationException>(async () =>
{
var person = await _peopleAppService.CreateAsync(new PersonDto
{
Age = 42
}
).ConfigureAwait(false);
}).ConfigureAwait(false);
}
[Fact] [Fact]
public async Task Update() public async Task Update()
{ {
@ -135,4 +151,4 @@ namespace Volo.Abp.Http.DynamicProxying
result.Inner1.Inner2.Value3.ShouldBe("value three"); result.Inner1.Inner2.Value3.ShouldBe("value three");
} }
} }
} }

15
framework/test/Volo.Abp.TestApp.Tests/Volo/Abp/TestApp/Application/PersonAppService_Tests.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.TestApp.Application
public PersonAppService_Tests() public PersonAppService_Tests()
{ {
_peopleAppService = ServiceProvider.GetRequiredService<IPeopleAppService>(); _peopleAppService = ServiceProvider.GetRequiredService<IPeopleAppService>();
} }
protected override void AfterAddApplication(IServiceCollection services) protected override void AfterAddApplication(IServiceCollection services)
@ -31,14 +31,17 @@ namespace Volo.Abp.TestApp.Application
[Fact] [Fact]
public async Task GetList() public async Task GetList()
{ {
var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto()).ConfigureAwait(false); var people = await _peopleAppService.GetListAsync(new PagedAndSortedResultRequestDto())
.ConfigureAwait(false);
people.Items.Count.ShouldBeGreaterThan(0); people.Items.Count.ShouldBeGreaterThan(0);
} }
[Fact] [Fact]
public async Task Create() public async Task Create()
{ {
var personDto = await _peopleAppService.CreateAsync(new PersonDto()).ConfigureAwait(false); var uniquePersonName = Guid.NewGuid().ToString();
var personDto = await _peopleAppService.CreateAsync(new PersonDto {Name = uniquePersonName})
.ConfigureAwait(false);
var repository = ServiceProvider.GetService<IRepository<Person, Guid>>(); var repository = ServiceProvider.GetService<IRepository<Person, Guid>>();
var person = await repository.FindAsync(personDto.Id).ConfigureAwait(false); var person = await repository.FindAsync(personDto.Id).ConfigureAwait(false);
@ -52,7 +55,9 @@ namespace Volo.Abp.TestApp.Application
{ {
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1);
var personDto = await _peopleAppService.CreateAsync(new PersonDto()).ConfigureAwait(false); var uniquePersonName = Guid.NewGuid().ToString();
var personDto = await _peopleAppService.CreateAsync(new PersonDto {Name = uniquePersonName})
.ConfigureAwait(false);
var repository = ServiceProvider.GetService<IRepository<Person, Guid>>(); var repository = ServiceProvider.GetService<IRepository<Person, Guid>>();
var person = await repository.FindAsync(personDto.Id).ConfigureAwait(false); var person = await repository.FindAsync(personDto.Id).ConfigureAwait(false);
@ -63,4 +68,4 @@ namespace Volo.Abp.TestApp.Application
person.TenantId.ShouldBe(TestDataBuilder.TenantId1); person.TenantId.ShouldBe(TestDataBuilder.TenantId1);
} }
} }
} }

2
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/Dto/PersonDto.cs

@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@ -6,6 +7,7 @@ namespace Volo.Abp.TestApp.Application.Dto
{ {
public class PersonDto : EntityDto<Guid>, IMultiTenant public class PersonDto : EntityDto<Guid>, IMultiTenant
{ {
[Required]
public string Name { get; set; } public string Name { get; set; }
public int Age { get; set; } public int Age { get; set; }

Loading…
Cancel
Save