Made sync test succeed for interception.

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 684051efa4
commit ed53a95e12

@ -8,5 +8,7 @@ namespace AbpDesk.Tickets
public interface ITicketAppService : IApplicationService
{
Task<ListResultDto<TicketDto>> GetAll(GetAllTicketsInput input);
ListResultDto<TicketDto> GetAll2(GetAllTicketsInput input);
}
}

@ -39,5 +39,23 @@ namespace AbpDesk.Tickets
return new ListResultDto<TicketDto>(tickets);
}
public ListResultDto<TicketDto> GetAll2(GetAllTicketsInput input)
{
var tickets = _ticketRepository
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
t => t.Title.Contains(input.Filter) || t.Body.Contains(input.Filter)
)
.Select(t => new TicketDto
{
Id = t.Id,
Title = t.Title,
Body = t.Body
})
.ToList();
return new ListResultDto<TicketDto>(tickets);
}
}
}

@ -19,11 +19,12 @@ namespace Volo.Abp.TestBase
BeforeAddApplication(services);
Application = services.AddApplication<TStartupModule>();
Application = services.AddApplication<TStartupModule>(SetAbpApplicationCreationOptions);
AfterAddApplication(services);
var serviceProvider = CreateServiceProvider(services);
MainServiceScope = CreateServiceProvider(services).CreateScope();
var serviceProvider = MainServiceScope.ServiceProvider;
Application.Initialize(serviceProvider);
}
@ -38,6 +39,11 @@ namespace Volo.Abp.TestBase
}
protected virtual void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
}
protected virtual void AfterAddApplication(IServiceCollection services)
{
@ -45,8 +51,7 @@ namespace Volo.Abp.TestBase
protected virtual IServiceProvider CreateServiceProvider(IServiceCollection services)
{
MainServiceScope = services.BuildServiceProvider().CreateScope();
return MainServiceScope.ServiceProvider;
return services.BuildServiceProvider();
}
public void Dispose()

@ -38,5 +38,17 @@ namespace AbpDesk.Tickets
result.Items.Count.ShouldBe(0);
}
[Fact]
public void GetAll2_Test()
{
//Act
var result = _ticketAppService.GetAll2(new GetAllTicketsInput());
//Assert
result.Items.Count.ShouldBe(1);
}
}
}

@ -10,7 +10,7 @@ namespace Volo.Abp.Autofac
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpCastleCoreTestModule>();
services.AddAssemblyOf<AbpAutofacModule>();
}
}
}

@ -1,9 +1,44 @@
using Volo.Abp.Castle.DynamicProxy;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Castle.DynamicProxy;
using Xunit;
namespace Volo.Abp.Autofac.Interception
{
public class Autofac_Interception_Test : CastleInterceptionTestBase<AutofacTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
protected override IServiceProvider CreateServiceProvider(IServiceCollection services)
{
return services.BuildAutofacServiceProvider();
}
[Fact]
public async Task Should_Intercept_Async_Methods()
{
//Arrange
var target = ServiceProvider.GetService<SimpleInterceptionTargetClass>();
//Act
var result = await target.GetValueAsync();
//Assert
result.ShouldBe(42);
target.Logs.Count.ShouldBe(5);
target.Logs[0].ShouldBe("BeforeInvocation");
target.Logs[1].ShouldBe("EnterGetValueAsync");
target.Logs[2].ShouldBe("MiddleGetValueAsync");
target.Logs[3].ShouldBe("ExitGetValueAsync");
target.Logs[4].ShouldBe("AfterInvocation");
}
}
}

@ -1,7 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Castle.DynamicProxy;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
namespace Volo.Abp.Castle
{

@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Modularity;

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.TestBase.Logging;
using Volo.DependencyInjection;
@ -13,5 +14,15 @@ namespace Volo.Abp.Castle.DynamicProxy
Logs.Add("ExecutingGetValue");
return 42;
}
public virtual async Task<int> GetValueAsync()
{
Logs.Add("EnterGetValueAsync");
await Task.Delay(1);
Logs.Add("MiddleGetValueAsync");
await Task.Delay(1);
Logs.Add("ExitGetValueAsync");
return 42;
}
}
}
Loading…
Cancel
Save