diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index 12b3fa01c0..64724312ea 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Domain.Entities.Events; using Volo.Abp.Domain.Entities.Events.Distributed; @@ -17,16 +18,26 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase where TStartupModule : IAbpModule { protected IRepository PersonRepository { get; } + protected ICityRepository CityRepository { get; } protected ILocalEventBus LocalEventBus { get; } protected IDistributedEventBus DistributedEventBus { get; } protected EntityChangeEvents_Tests() { PersonRepository = GetRequiredService>(); + CityRepository = GetRequiredService(); LocalEventBus = GetRequiredService(); DistributedEventBus = GetRequiredService(); } + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.IgnoreEventSelectors.Add(); + }); + } + [Fact] public async Task Complex_Event_Test() { @@ -62,7 +73,7 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase await uow.CompleteAsync(); } - + createdEventTriggered.ShouldBeTrue(); createdEtoTriggered.ShouldBeTrue(); } @@ -113,4 +124,33 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase updateEventCount.ShouldBe(1); updatedAge.ShouldBe(45); } + + [Fact] + public async Task Should_Not_Trigger_Event_If_Ignore_Event_Selector_Is_Configured() + { + var personCreatedEtoTriggered = false; + var cityCreatedEtoTriggered = false; + using (var uow = GetRequiredService().Begin()) + { + DistributedEventBus.Subscribe>(eto => + { + cityCreatedEtoTriggered = true; + return Task.CompletedTask; + }); + + DistributedEventBus.Subscribe>(eto => + { + personCreatedEtoTriggered = true; + return Task.CompletedTask; + }); + + await CityRepository.InsertAsync(new City(Guid.NewGuid(), "Istanbul")); + await PersonRepository.InsertAsync(new Person(Guid.NewGuid(), "John", 15)); + + await uow.CompleteAsync(); + } + + personCreatedEtoTriggered.ShouldBeTrue(); + cityCreatedEtoTriggered.ShouldBeFalse(); + } }