Browse Source

Merge pull request #26129 from abpframework/maliming/enum-adapter-uow-event-tests

Improve the child unit of work and enum adapter tests
rel-10.7
Enis Necipoglu 2 days ago
committed by GitHub
parent
commit
29c81feea6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/DataAnnotations/AbpValidationAttributeAdapterProvider_Tests.cs
  2. 28
      framework/test/Volo.Abp.Uow.Tests/Volo/Abp/Uow/UnitOfWork_Child_Events_Tests.cs

6
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/DataAnnotations/AbpValidationAttributeAdapterProvider_Tests.cs

@ -17,11 +17,7 @@ public class AbpValidationAttributeAdapterProvider_Tests
[Fact]
public void Should_Return_An_Adapter_For_The_EnumDataTypeAttribute()
{
//ASP.NET Core does not provide an adapter for the EnumDataTypeAttribute.
new ValidationAttributeAdapterProvider()
.GetAttributeAdapter(new EnumDataTypeAttribute(typeof(MyEnum)), null)
.ShouldBeNull();
//ABP supplies its own adapter for the EnumDataTypeAttribute.
_provider.GetAttributeAdapter(new EnumDataTypeAttribute(typeof(MyEnum)), null)
.ShouldBeOfType<EnumDataTypeAttributeAdapter>();
}

28
framework/test/Volo.Abp.Uow.Tests/Volo/Abp/Uow/UnitOfWork_Child_Events_Tests.cs

@ -56,6 +56,34 @@ public class UnitOfWork_Child_Events_Tests : AbpIntegratedTest<AbpUnitOfWorkModu
disposed.ShouldBeTrue();
}
[Fact]
public void Should_Not_Trigger_Disposed_Event_Unsubscribed_Over_A_Child_UnitOfWork()
{
var disposed = false;
using (var parentUow = _unitOfWorkManager.Begin())
{
var handlerCount = GetEventHandlerCount(parentUow, nameof(IUnitOfWork.Disposed));
using (var childUow = _unitOfWorkManager.Begin())
{
childUow.Id.ShouldBe(parentUow.Id); //It's a child of the parent UOW.
childUow.Disposed += OnDisposed;
childUow.Disposed -= OnDisposed;
}
GetEventHandlerCount(parentUow, nameof(IUnitOfWork.Disposed)).ShouldBe(handlerCount);
}
disposed.ShouldBeFalse();
void OnDisposed(object? sender, UnitOfWorkEventArgs args)
{
disposed = true;
}
}
private static int GetEventHandlerCount(IUnitOfWork unitOfWork, string eventName)
{
var field = unitOfWork.GetType().GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic);

Loading…
Cancel
Save