You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/GenericInheritanceTest.cs

57 lines
1.5 KiB

using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Events;
using Xunit;
namespace Volo.Abp.EventBus
{
public class GenericInheritanceTest : EventBusTestBase
{
[Fact]
public async Task Should_Trigger_For_Inherited_Generic_1()
{
var triggeredEvent = false;
EventBus.Register<EntityChangedEventData<Person>>(
eventData =>
{
eventData.Entity.Id.ShouldBe(42);
triggeredEvent = true;
return Task.CompletedTask;
});
await EventBus.TriggerAsync(new EntityUpdatedEventData<Person>(new Person { Id = 42 }));
triggeredEvent.ShouldBe(true);
}
[Fact]
public async Task Should_Trigger_For_Inherited_Generic_2()
{
var triggeredEvent = false;
EventBus.Register<EntityChangedEventData<Person>>(
eventData =>
{
eventData.Entity.Id.ShouldBe(42);
triggeredEvent = true;
return Task.CompletedTask;
});
await EventBus.TriggerAsync(new EntityChangedEventData<Student>(new Student { Id = 42 }));
triggeredEvent.ShouldBe(true);
}
public class Person : Entity<int>
{
}
public class Student : Person
{
}
}
}