|
|
|
@ -4,14 +4,15 @@ using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Shouldly; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Domain.ChangeTracking; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.TestApp.Domain; |
|
|
|
using Volo.Abp.TestApp.Testing; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Volo.Abp.EntityFrameworkCore.Repositories; |
|
|
|
namespace Volo.Abp.EntityFrameworkCore.ChangeTracking; |
|
|
|
|
|
|
|
public class RepositoryInterceptor_Tests : TestAppTestBase<AbpEntityFrameworkCoreTestModule> |
|
|
|
public class ChangeTrackingInterceptor_Tests : TestAppTestBase<AbpEntityFrameworkCoreTestModule> |
|
|
|
{ |
|
|
|
[Fact] |
|
|
|
public async Task ReadOnly_Repository_Should_Not_Track_Entities() |
|
|
|
@ -65,18 +66,6 @@ public class RepositoryInterceptor_Tests : TestAppTestBase<AbpEntityFrameworkCor |
|
|
|
db.ChangeTracker.Entries().Count().ShouldBe(1); // Track one entity from GetPeoplesAsync
|
|
|
|
}); |
|
|
|
|
|
|
|
await WithUnitOfWorkAsync(async () => |
|
|
|
{ |
|
|
|
var service = GetRequiredService<MyServiceEnableEntityChangeTrackingOnInterface>(); |
|
|
|
var db = await repository.GetDbContextAsync(); |
|
|
|
db.ChangeTracker.Entries().Count().ShouldBe(0); |
|
|
|
|
|
|
|
var list = await service.GetPeoplesAsync(); |
|
|
|
list.Count.ShouldBeGreaterThan(0); |
|
|
|
|
|
|
|
db.ChangeTracker.Entries().Count().ShouldBe(1); // Track one entity from GetPeoplesAsync
|
|
|
|
}); |
|
|
|
|
|
|
|
await WithUnitOfWorkAsync(async () => |
|
|
|
{ |
|
|
|
var service = GetRequiredService<MyServiceChangeTrackingByEntityChangeTrackingProvider>(); |
|
|
|
@ -163,38 +152,6 @@ public class MyServiceEnableEntityChangeTracking : ITransientDependency |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[EnableEntityChangeTracking] |
|
|
|
public interface IMyServiceEnableEntityChangeTrackingOnInterface |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class MyServiceEnableEntityChangeTrackingOnInterface : IMyServiceEnableEntityChangeTrackingOnInterface, ITransientDependency |
|
|
|
{ |
|
|
|
private readonly IRepository<Person, Guid> _repository; |
|
|
|
|
|
|
|
public MyServiceEnableEntityChangeTrackingOnInterface(IRepository<Person, Guid> repository) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<Person>> GetPeoplesAsync() |
|
|
|
{ |
|
|
|
var p1 = await GetPeopleAsync(); |
|
|
|
var p2 = await _repository.FindAsync(x => x.Name == "people2"); |
|
|
|
|
|
|
|
return new List<Person> {p1, p2}; |
|
|
|
} |
|
|
|
|
|
|
|
[DisableEntityChangeTracking] |
|
|
|
public virtual async Task<Person> GetPeopleAsync() |
|
|
|
{ |
|
|
|
var p1 = await _repository.FindAsync(x => x.Name == "people1"); |
|
|
|
return p1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class MyServiceChangeTrackingByEntityChangeTrackingProvider : ITransientDependency |
|
|
|
{ |
|
|
|
private readonly IRepository<Person, Guid> _repository; |