From fe02e72e5990a59bf57c399e0fb358dcbc2efa8d Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 8 Feb 2021 16:13:51 +0300 Subject: [PATCH] added Eto Extra property test --- .../LocalDistributedEventBus_Test.cs | 18 ++++++++++++++++++ ...pleDistributedSingleInstanceEventHandler.cs | 10 +++++++++- .../Volo/Abp/EventBus/MySimpleEto.cs | 8 ++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.cs diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs index d3371f383a..7022f41b21 100644 --- a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs @@ -44,5 +44,23 @@ namespace Volo.Abp.EventBus.Distributed Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId); } + + [Fact] + public async Task Should_Get_TenantId_From_EventEto_Extra_Property() + { + var tenantId = Guid.NewGuid(); + + DistributedEventBus.Subscribe(GetRequiredService()); + + await DistributedEventBus.PublishAsync(new MySimpleEto + { + Properties = + { + {"TenantId", tenantId} + } + }); + + Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId); + } } } diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs index 53fe8e347b..9141a28024 100644 --- a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events.Distributed; @@ -6,7 +7,7 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.EventBus.Distributed { - public class MySimpleDistributedSingleInstanceEventHandler : IDistributedEventHandler, IDistributedEventHandler>, ITransientDependency + public class MySimpleDistributedSingleInstanceEventHandler : IDistributedEventHandler, IDistributedEventHandler>, IDistributedEventHandler, ITransientDependency { private readonly ICurrentTenant _currentTenant; @@ -28,5 +29,12 @@ namespace Volo.Abp.EventBus.Distributed TenantId = _currentTenant.Id; return Task.CompletedTask; } + + public Task HandleEventAsync(MySimpleEto eventData) + { + var tenantIdString = eventData.Properties.GetOrDefault("TenantId").ToString(); + TenantId = tenantIdString != null ? new Guid(tenantIdString) : _currentTenant.Id; + return Task.CompletedTask; + } } } diff --git a/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.cs b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.cs new file mode 100644 index 0000000000..55d176c392 --- /dev/null +++ b/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Domain.Entities.Events.Distributed; + +namespace Volo.Abp.EventBus +{ + public class MySimpleEto : EtoBase + { + } +} \ No newline at end of file