Browse Source
Merge pull request #7654 from abpframework/gterdem/eventbus_eto_extra_property_test
Added Test for Eto Extra Properties
pull/7662/head
maliming
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
35 additions and
1 deletions
-
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs
-
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs
-
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.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<MySimpleEto>(GetRequiredService<MySimpleDistributedSingleInstanceEventHandler>()); |
|
|
|
|
|
|
|
await DistributedEventBus.PublishAsync(new MySimpleEto |
|
|
|
{ |
|
|
|
Properties = |
|
|
|
{ |
|
|
|
{"TenantId", tenantId} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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<MySimpleEventData>, IDistributedEventHandler<EntityCreatedEto<MySimpleEventData>>, ITransientDependency |
|
|
|
public class MySimpleDistributedSingleInstanceEventHandler : IDistributedEventHandler<MySimpleEventData>, IDistributedEventHandler<EntityCreatedEto<MySimpleEventData>>, IDistributedEventHandler<MySimpleEto>, 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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,8 @@ |
|
|
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
|
|
|
|
|
|
|
namespace Volo.Abp.EventBus |
|
|
|
{ |
|
|
|
public class MySimpleEto : EtoBase |
|
|
|
{ |
|
|
|
} |
|
|
|
} |