mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 132 additions and 1 deletions
@ -0,0 +1,32 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace Volo.Abp.SettingManagement; |
|||
|
|||
public class DefaultLanguageSettingChangedHandler : |
|||
ILocalEventHandler<EntityChangedEventData<Setting>>, |
|||
ITransientDependency |
|||
{ |
|||
protected IDistributedEventBus DistributedEventBus { get; } |
|||
|
|||
public DefaultLanguageSettingChangedHandler(IDistributedEventBus distributedEventBus) |
|||
{ |
|||
DistributedEventBus = distributedEventBus; |
|||
} |
|||
|
|||
public virtual async Task HandleEventAsync(EntityChangedEventData<Setting> eventData) |
|||
{ |
|||
if (eventData.Entity.Name != LocalizationSettingNames.DefaultLanguage || |
|||
eventData.Entity.ProviderName == UserSettingValueProvider.ProviderName) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await DistributedEventBus.PublishAsync(new LanguageChangedEto()); |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Settings; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.SettingManagement; |
|||
|
|||
public class DefaultLanguageSettingChangedHandler_Tests : SettingsTestBase |
|||
{ |
|||
private readonly ISettingManagementStore _settingManagementStore; |
|||
private readonly IDistributedEventBus _distributedEventBus; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
public DefaultLanguageSettingChangedHandler_Tests() |
|||
{ |
|||
_settingManagementStore = GetRequiredService<ISettingManagementStore>(); |
|||
_distributedEventBus = GetRequiredService<IDistributedEventBus>(); |
|||
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Publish_LanguageChangedEto_When_DefaultLanguage_Setting_Changed() |
|||
{ |
|||
var languageChanged = false; |
|||
|
|||
using (var uow = _unitOfWorkManager.Begin()) |
|||
{ |
|||
_distributedEventBus.Subscribe<LanguageChangedEto>(_ => |
|||
{ |
|||
languageChanged = true; |
|||
return Task.CompletedTask; |
|||
}); |
|||
|
|||
await _settingManagementStore.SetAsync( |
|||
LocalizationSettingNames.DefaultLanguage, |
|||
"tr;tr", |
|||
GlobalSettingValueProvider.ProviderName, |
|||
null); |
|||
|
|||
await uow.CompleteAsync(); |
|||
} |
|||
|
|||
languageChanged.ShouldBeTrue(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Not_Publish_LanguageChangedEto_When_Other_Setting_Changed() |
|||
{ |
|||
var languageChanged = false; |
|||
|
|||
using (var uow = _unitOfWorkManager.Begin()) |
|||
{ |
|||
_distributedEventBus.Subscribe<LanguageChangedEto>(_ => |
|||
{ |
|||
languageChanged = true; |
|||
return Task.CompletedTask; |
|||
}); |
|||
|
|||
await _settingManagementStore.SetAsync( |
|||
"MySetting2", |
|||
"MySetting2Value-updated", |
|||
GlobalSettingValueProvider.ProviderName, |
|||
null); |
|||
|
|||
await uow.CompleteAsync(); |
|||
} |
|||
|
|||
languageChanged.ShouldBeFalse(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Not_Publish_LanguageChangedEto_When_User_DefaultLanguage_Setting_Changed() |
|||
{ |
|||
var languageChanged = false; |
|||
|
|||
using (var uow = _unitOfWorkManager.Begin()) |
|||
{ |
|||
_distributedEventBus.Subscribe<LanguageChangedEto>(_ => |
|||
{ |
|||
languageChanged = true; |
|||
return Task.CompletedTask; |
|||
}); |
|||
|
|||
await _settingManagementStore.SetAsync( |
|||
LocalizationSettingNames.DefaultLanguage, |
|||
"tr;tr", |
|||
UserSettingValueProvider.ProviderName, |
|||
Guid.NewGuid().ToString()); |
|||
|
|||
await uow.CompleteAsync(); |
|||
} |
|||
|
|||
languageChanged.ShouldBeFalse(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue