Browse Source

added Eto Extra property test

pull/7654/head
Galip Tolga Erdem 5 years ago
parent
commit
fe02e72e59
  1. 18
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs
  2. 10
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/MySimpleDistributedSingleInstanceEventHandler.cs
  3. 8
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/MySimpleEto.cs

18
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<MySimpleEto>(GetRequiredService<MySimpleDistributedSingleInstanceEventHandler>());
await DistributedEventBus.PublishAsync(new MySimpleEto
{
Properties =
{
{"TenantId", tenantId}
}
});
Assert.Equal(tenantId, MySimpleDistributedSingleInstanceEventHandler.TenantId);
}
}
}

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

8
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
{
}
}
Loading…
Cancel
Save