|
|
@ -3,7 +3,7 @@ using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Shouldly; |
|
|
using Shouldly; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.EventBus; |
|
|
using Volo.Abp.EventBus.Distributed; |
|
|
using Volo.Abp.EventBus.Local; |
|
|
using Volo.Abp.EventBus.Local; |
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.TestApp.Domain; |
|
|
using Volo.Abp.TestApp.Domain; |
|
|
@ -16,11 +16,13 @@ namespace Volo.Abp.TestApp.Testing |
|
|
{ |
|
|
{ |
|
|
protected readonly IRepository<Person, Guid> PersonRepository; |
|
|
protected readonly IRepository<Person, Guid> PersonRepository; |
|
|
protected readonly ILocalEventBus LocalEventBus; |
|
|
protected readonly ILocalEventBus LocalEventBus; |
|
|
|
|
|
protected readonly IDistributedEventBus DistributedEventBus; |
|
|
|
|
|
|
|
|
protected DomainEvents_Tests() |
|
|
protected DomainEvents_Tests() |
|
|
{ |
|
|
{ |
|
|
PersonRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|
|
PersonRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|
|
LocalEventBus = GetRequiredService<ILocalEventBus>(); |
|
|
LocalEventBus = GetRequiredService<ILocalEventBus>(); |
|
|
|
|
|
DistributedEventBus = GetRequiredService<IDistributedEventBus>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -28,13 +30,22 @@ namespace Volo.Abp.TestApp.Testing |
|
|
{ |
|
|
{ |
|
|
//Arrange
|
|
|
//Arrange
|
|
|
|
|
|
|
|
|
var isTriggered = false; |
|
|
var isLocalEventTriggered = false; |
|
|
|
|
|
var isDistributedEventTriggered = false; |
|
|
|
|
|
|
|
|
LocalEventBus.Subscribe<PersonNameChangedEvent>(data => |
|
|
LocalEventBus.Subscribe<PersonNameChangedEvent>(data => |
|
|
{ |
|
|
{ |
|
|
data.OldName.ShouldBe("Douglas"); |
|
|
data.OldName.ShouldBe("Douglas"); |
|
|
data.Person.Name.ShouldBe("Douglas-Changed"); |
|
|
data.Person.Name.ShouldBe("Douglas-Changed"); |
|
|
isTriggered = true; |
|
|
isLocalEventTriggered = true; |
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
DistributedEventBus.Subscribe<PersonNameChangedEto>(data => |
|
|
|
|
|
{ |
|
|
|
|
|
data.OldName.ShouldBe("Douglas"); |
|
|
|
|
|
data.NewName.ShouldBe("Douglas-Changed"); |
|
|
|
|
|
isDistributedEventTriggered = true; |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -49,7 +60,8 @@ namespace Volo.Abp.TestApp.Testing |
|
|
|
|
|
|
|
|
//Assert
|
|
|
//Assert
|
|
|
|
|
|
|
|
|
isTriggered.ShouldBeTrue(); |
|
|
isLocalEventTriggered.ShouldBeTrue(); |
|
|
|
|
|
isDistributedEventTriggered.ShouldBeTrue(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |