Browse Source

Added unit test: Should_Rollback_Uow_If_Event_Handler_Throws_Exception

pull/9909/head
Halil İbrahim Kalkan 5 years ago
parent
commit
e18313e9eb
  1. 10
      framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DomainEvents/DomainEvents_Tests.cs
  2. 28
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs
  3. 1
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/TestAppTestBase.cs

10
framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DomainEvents/DomainEvents_Tests.cs

@ -1,9 +1,15 @@
using Volo.Abp.TestApp.Testing;
using System.Threading.Tasks;
using Volo.Abp.TestApp.Testing;
using Xunit;
namespace Volo.Abp.MemoryDb.DomainEvents
{
public class DomainEvents_Tests : DomainEvents_Tests<AbpMemoryDbTestModule>
{
[Fact(Skip = "MemoryDB doesn't support transactions.")]
public override Task Should_Rollback_Uow_If_Event_Handler_Throws_Exception()
{
return base.Should_Rollback_Uow_If_Event_Handler_Throws_Exception();
}
}
}

28
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs

@ -2,11 +2,13 @@
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.EventBus.Local;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.TestApp.Testing
@ -25,6 +27,32 @@ namespace Volo.Abp.TestApp.Testing
DistributedEventBus = GetRequiredService<IDistributedEventBus>();
}
[Fact]
public virtual async Task Should_Rollback_Uow_If_Event_Handler_Throws_Exception()
{
(await PersonRepository.FindAsync(x => x.Name == "TestPerson1")).ShouldBeNull();
LocalEventBus.Subscribe<EntityCreatedEventData<Person>>(data =>
{
data.Entity.Name.ShouldBe("TestPerson1");
throw new ApplicationException("Just to rollback the UOW");
});
var exception = await Assert.ThrowsAsync<ApplicationException>(async () =>
{
await WithUnitOfWorkAsync(new AbpUnitOfWorkOptions{IsTransactional = true}, async () =>
{
await PersonRepository.InsertAsync(
new Person(Guid.NewGuid(), "TestPerson1", 42)
);
});
});
exception.Message.ShouldBe("Just to rollback the UOW");
(await PersonRepository.FindAsync(x => x.Name == "TestPerson1")).ShouldBeNull();
}
[Fact]
public async Task Should_Trigger_Domain_Events_For_Aggregate_Root()
{

1
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/TestAppTestBase.cs

@ -31,7 +31,6 @@ namespace Volo.Abp.TestApp.Testing
using (var uow = uowManager.Begin(options))
{
await action();
await uow.CompleteAsync();
}
}

Loading…
Cancel
Save