mirror of https://github.com/abpframework/abp.git
14 changed files with 102 additions and 36 deletions
@ -1,13 +1,9 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using Volo.Abp.Modularity; |
||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace Volo.Abp |
namespace Volo.Abp |
||||
{ |
{ |
||||
public class AbpTestBaseModule : AbpModule |
public class AbpTestBaseModule : AbpModule |
||||
{ |
{ |
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,29 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
||||
|
using Volo.Abp.EventBus.Distributed; |
||||
|
using Volo.Abp.Testing.Utils; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
public class DistributedUserUpdateHandler : IDistributedEventHandler<EntityUpdatedEto<UserEto>>, ITransientDependency |
||||
|
{ |
||||
|
private readonly ITestCounter _testCounter; |
||||
|
|
||||
|
public DistributedUserUpdateHandler(ITestCounter testCounter) |
||||
|
{ |
||||
|
_testCounter = testCounter; |
||||
|
} |
||||
|
|
||||
|
public Task HandleEventAsync(EntityUpdatedEto<UserEto> eventData) |
||||
|
{ |
||||
|
if (eventData.Entity.UserName == "john.nash") |
||||
|
{ |
||||
|
_testCounter.Increment("EntityUpdatedEto<UserEto>"); |
||||
|
} |
||||
|
|
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Identity; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.EventBus.Distributed; |
||||
|
using Volo.Abp.Testing.Utils; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Volo.Abp.Users; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Identity |
||||
|
{ |
||||
|
public class Distributed_User_Change_Event_Tests : AbpIdentityDomainTestBase |
||||
|
{ |
||||
|
private readonly IIdentityUserRepository _userRepository; |
||||
|
private readonly ILookupNormalizer _lookupNormalizer; |
||||
|
private readonly IdentityUserManager _userManager; |
||||
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
||||
|
private readonly ITestCounter _testCounter; |
||||
|
|
||||
|
public Distributed_User_Change_Event_Tests() |
||||
|
{ |
||||
|
_userRepository = GetRequiredService<IIdentityUserRepository>(); |
||||
|
_userManager = GetRequiredService<IdentityUserManager>(); |
||||
|
_lookupNormalizer = GetRequiredService<ILookupNormalizer>(); |
||||
|
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
||||
|
_testCounter = GetRequiredService<ITestCounter>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Register_Handler() |
||||
|
{ |
||||
|
var options = GetRequiredService<IOptions<DistributedEventBusOptions>>().Value; |
||||
|
options.EtoMappings.ShouldContain(m => m.Key == typeof(IdentityUser) && m.Value == typeof(UserEto)); |
||||
|
options.Handlers.ShouldContain(h => h == typeof(DistributedUserUpdateHandler)); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Trigger_Distributed_EntityUpdated_Event() |
||||
|
{ |
||||
|
using (var uow = _unitOfWorkManager.Begin()) |
||||
|
{ |
||||
|
var user = await _userRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.Normalize("john.nash")); |
||||
|
await _userManager.SetEmailAsync(user, "john.nash_UPDATED@abp.io"); |
||||
|
|
||||
|
_testCounter.GetValue("EntityUpdatedEto<UserEto>").ShouldBe(0); |
||||
|
await uow.CompleteAsync(); |
||||
|
} |
||||
|
|
||||
|
_testCounter.GetValue("EntityUpdatedEto<UserEto>").ShouldBe(1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue