Skip to content

Commit

Permalink
Merge pull request #7654 from abpframework/gterdem/eventbus_eto_extra…
Browse files Browse the repository at this point in the history
…_property_test

Added Test for Eto Extra Properties
  • Loading branch information
maliming committed Feb 8, 2021
2 parents 7083364 + fe02e72 commit 835aa88
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,23 @@ public async Task Should_Change_TenantId_If_Generic_EventData_Is_MultiTenant()

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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
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;

Expand All @@ -28,5 +29,12 @@ public Task HandleEventAsync(EntityCreatedEto<MySimpleEventData> eventData)
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Volo.Abp.Domain.Entities.Events.Distributed;

namespace Volo.Abp.EventBus
{
public class MySimpleEto : EtoBase
{
}
}

0 comments on commit 835aa88

Please sign in to comment.