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/Local/GenericInheritanceTest.cs

75 lines
1.8 KiB

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