Browse Source

Refactor event bus and fix breaking code.

pull/625/head
Halil ibrahim Kalkan 8 years ago
parent
commit
08f50d0ff2
  1. 2
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs
  2. 2
      framework/src/Volo.Abp.TestBase/Volo/Abp/AbpIntegratedTest.cs
  3. 8
      framework/src/Volo.Abp.TestBase/Volo/Abp/AbpTestBaseModule.cs
  4. 4
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBusTestBase.cs
  5. 8
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs
  6. 15
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs
  7. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentitySettingDefinitionProvider.cs
  8. 7
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml
  9. 2
      modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs
  10. 29
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/DistributedUserUpdateHandler.cs
  11. 53
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/Distributed_User_Change_Event_Tests.cs
  12. 1
      modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs
  13. 1
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs
  14. 2
      modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGrantCacheItemInvalidator.cs

2
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.EventBus.Distributed
{ {
[Dependency(TryRegister = true)] [Dependency(TryRegister = true)]
[ExposeServices(typeof(IDistributedEventBus), typeof(LocalDistributedEventBus))] [ExposeServices(typeof(IDistributedEventBus), typeof(LocalDistributedEventBus))]
public class LocalDistributedEventBus : IDistributedEventBus, ITransientDependency public class LocalDistributedEventBus : IDistributedEventBus, ISingletonDependency
{ {
private readonly ILocalEventBus _localEventBus; private readonly ILocalEventBus _localEventBus;
protected IHybridServiceScopeFactory ServiceScopeFactory { get; } protected IHybridServiceScopeFactory ServiceScopeFactory { get; }

2
framework/src/Volo.Abp.TestBase/Volo/Abp/AbpIntegratedTest.cs

@ -4,6 +4,8 @@ using Volo.Abp.Modularity;
namespace Volo.Abp namespace Volo.Abp
{ {
//TODO: Move to "Testing" namespace
public abstract class AbpIntegratedTest<TStartupModule> : AbpTestBaseWithServiceProvider, IDisposable public abstract class AbpIntegratedTest<TStartupModule> : AbpTestBaseWithServiceProvider, IDisposable
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {

8
framework/src/Volo.Abp.TestBase/Volo/Abp/AbpTestBaseModule.cs

@ -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)
{
}
} }
} }

4
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBusTestBase.cs

@ -2,11 +2,11 @@ namespace Volo.Abp.EventBus.Distributed
{ {
public abstract class LocalDistributedEventBusTestBase : AbpIntegratedTest<EventBusTestModule> public abstract class LocalDistributedEventBusTestBase : AbpIntegratedTest<EventBusTestModule>
{ {
protected LocalDistributedEventBus LocalEventBus; protected IDistributedEventBus DistributedEventBus;
protected LocalDistributedEventBusTestBase() protected LocalDistributedEventBusTestBase()
{ {
LocalEventBus = GetRequiredService<LocalDistributedEventBus>(); DistributedEventBus = GetRequiredService<LocalDistributedEventBus>();
} }
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)

8
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs

@ -8,11 +8,11 @@ namespace Volo.Abp.EventBus.Distributed
[Fact] [Fact]
public async Task Should_Call_Handler_AndDispose() public async Task Should_Call_Handler_AndDispose()
{ {
LocalEventBus.Subscribe<MySimpleEventData, MySimpleDistributedTransientEventHandler>(); DistributedEventBus.Subscribe<MySimpleEventData, MySimpleDistributedTransientEventHandler>();
await LocalEventBus.PublishAsync(new MySimpleEventData(1)); await DistributedEventBus.PublishAsync(new MySimpleEventData(1));
await LocalEventBus.PublishAsync(new MySimpleEventData(2)); await DistributedEventBus.PublishAsync(new MySimpleEventData(2));
await LocalEventBus.PublishAsync(new MySimpleEventData(3)); await DistributedEventBus.PublishAsync(new MySimpleEventData(3));
Assert.Equal(3, MySimpleDistributedTransientEventHandler.HandleCount); Assert.Equal(3, MySimpleDistributedTransientEventHandler.HandleCount);
Assert.Equal(3, MySimpleDistributedTransientEventHandler.DisposeCount); Assert.Equal(3, MySimpleDistributedTransientEventHandler.DisposeCount);

15
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs

@ -1,8 +1,8 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Volo.Abp.Identity.Settings; using Volo.Abp.Identity.Settings;
using Volo.Abp.Settings;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
@ -28,19 +28,12 @@ namespace Volo.Abp.Identity
{ {
var user = await _userManager.GetByIdAsync(CurrentUser.GetId()); var user = await _userManager.GetByIdAsync(CurrentUser.GetId());
if (await SettingManager.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled))
var isUsernameUpdateEnabled = string.Equals(await (SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled)),
"true", StringComparison.OrdinalIgnoreCase);
if (isUsernameUpdateEnabled)
{ {
(await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
} }
var isEmailUpdateEnabled = !string.Equals(await (SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsEmailUpdateEnabled)), if (await SettingManager.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled))
"true", StringComparison.OrdinalIgnoreCase);
if (isEmailUpdateEnabled)
{ {
(await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors();
} }

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentitySettingDefinitionProvider.cs

@ -23,8 +23,8 @@ namespace Volo.Abp.Identity
new SettingDefinition(IdentitySettingNames.SignIn.RequireConfirmedEmail), new SettingDefinition(IdentitySettingNames.SignIn.RequireConfirmedEmail),
new SettingDefinition(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber), new SettingDefinition(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber),
new SettingDefinition(IdentitySettingNames.User.IsUserNameUpdateEnabled), new SettingDefinition(IdentitySettingNames.User.IsUserNameUpdateEnabled, "true"),
new SettingDefinition(IdentitySettingNames.User.IsEmailUpdateEnabled) new SettingDefinition(IdentitySettingNames.User.IsEmailUpdateEnabled, "true")
); );
} }

7
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Shared/PersonalSettingsModal.cshtml

@ -10,11 +10,8 @@
@inject ISettingManager SettingManager @inject ISettingManager SettingManager
@{ @{
Layout = null; Layout = null;
var isUserNameUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true", var isUserNameUpdateEnabled = await SettingManager.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled);
StringComparison.OrdinalIgnoreCase); var isEmailUpdateEnabled = await SettingManager.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled);
var isEmailUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsEmailUpdateEnabled), "true",
StringComparison.OrdinalIgnoreCase);
} }
<form asp-page="/Identity/Shared/PersonalSettingsModal"> <form asp-page="/Identity/Shared/PersonalSettingsModal">

2
modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs

@ -53,8 +53,6 @@ namespace Volo.Abp.Identity
[Fact] [Fact]
public async Task UpdateAsync() public async Task UpdateAsync()
{ {
//Arrange
//Arrange //Arrange
_currentUser.Id.Returns(_testData.UserJohnId); _currentUser.Id.Returns(_testData.UserJohnId);
_currentUser.IsAuthenticated.Returns(true); _currentUser.IsAuthenticated.Returns(true);

29
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/DistributedUserUpdateHandler.cs

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

53
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/Distributed_User_Change_Event_Tests.cs

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

1
modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs

@ -2,7 +2,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.EntityFrameworkCore;

1
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Shouldly; using Shouldly;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Xunit; using Xunit;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity

2
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGrantCacheItemInvalidator.cs

@ -7,7 +7,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.PermissionManagement namespace Volo.Abp.PermissionManagement
{ {
public class PermissionGrantCacheItemInvalidator : IEventHandler<EntityChangedEventData<PermissionGrant>>, ITransientDependency public class PermissionGrantCacheItemInvalidator : ILocalEventHandler<EntityChangedEventData<PermissionGrant>>, ITransientDependency
{ {
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }

Loading…
Cancel
Save