-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20012 from abpframework/ApplyAbpConceptsForModifi…
…edEntity Apply `AbpConcepts` to entities which navigation property changes.
- Loading branch information
Showing
6 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...o.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/EntityChange_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Volo.Abp.TestApp.Testing; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.Domain; | ||
|
||
public class EntityChange_Tests : EntityChange_Tests<AbpEntityFrameworkCoreTestModule> | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Domain/EntityChange_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Volo.Abp.TestApp.Testing; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.MongoDB.Domain; | ||
|
||
[Collection(MongoTestCollection.Name)] | ||
public class EntityChange_Tests : EntityChange_Tests<AbpMongoDbTestModule> | ||
{ | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/AppEntityWithNavigations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChange_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Shouldly; | ||
using Volo.Abp.Data; | ||
using Volo.Abp.Domain.Repositories; | ||
using Volo.Abp.Modularity; | ||
using Volo.Abp.TestApp.Domain; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.TestApp.Testing; | ||
|
||
public abstract class EntityChange_Tests<TStartupModule> : TestAppTestBase<TStartupModule> | ||
where TStartupModule : IAbpModule | ||
{ | ||
protected readonly IRepository<AppEntityWithNavigations, Guid> AppEntityWithNavigationsRepository; | ||
|
||
protected EntityChange_Tests() | ||
{ | ||
AppEntityWithNavigationsRepository = GetRequiredService<IRepository<AppEntityWithNavigations, Guid>>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Update_AbpConcepts_Properties_When_Entity_Or_Its_Navigation_Property_Changed() | ||
{ | ||
var entityId = Guid.NewGuid(); | ||
var entity = await AppEntityWithNavigationsRepository.InsertAsync(new AppEntityWithNavigations(entityId, "TestEntity")); | ||
var concurrencyStamp = entity.ConcurrencyStamp; | ||
var lastModificationTime = entity.LastModificationTime; | ||
|
||
// Test with simple property | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); | ||
entity.Name = Guid.NewGuid().ToString(); | ||
await AppEntityWithNavigationsRepository.UpdateAsync(entity); | ||
}); | ||
concurrencyStamp.ShouldNotBe(entity.ConcurrencyStamp); | ||
lastModificationTime.ShouldNotBe(entity.LastModificationTime); | ||
concurrencyStamp = entity.ConcurrencyStamp; | ||
lastModificationTime = entity.LastModificationTime; | ||
|
||
// Test with value object | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); | ||
entity.AppEntityWithValueObjectAddress = new AppEntityWithValueObjectAddress("Turkey"); | ||
await AppEntityWithNavigationsRepository.UpdateAsync(entity); | ||
}); | ||
concurrencyStamp.ShouldNotBe(entity.ConcurrencyStamp); | ||
lastModificationTime.ShouldNotBe(entity.LastModificationTime); | ||
concurrencyStamp = entity.ConcurrencyStamp; | ||
lastModificationTime = entity.LastModificationTime; | ||
|
||
// Test with one to one | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); | ||
entity.OneToOne = new AppEntityWithNavigationChildOneToOne | ||
{ | ||
ChildName = "ChildName" | ||
}; | ||
await AppEntityWithNavigationsRepository.UpdateAsync(entity); | ||
}); | ||
concurrencyStamp.ShouldNotBe(entity.ConcurrencyStamp); | ||
lastModificationTime.ShouldNotBe(entity.LastModificationTime); | ||
concurrencyStamp = entity.ConcurrencyStamp; | ||
lastModificationTime = entity.LastModificationTime; | ||
|
||
// Test with one to many | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); | ||
entity.OneToMany = new List<AppEntityWithNavigationChildOneToMany>() | ||
{ | ||
new AppEntityWithNavigationChildOneToMany | ||
{ | ||
AppEntityWithNavigationId = entity.Id, | ||
ChildName = "ChildName1" | ||
} | ||
}; | ||
await AppEntityWithNavigationsRepository.UpdateAsync(entity); | ||
}); | ||
concurrencyStamp.ShouldNotBe(entity.ConcurrencyStamp); | ||
lastModificationTime.ShouldNotBe(entity.LastModificationTime); | ||
concurrencyStamp = entity.ConcurrencyStamp; | ||
lastModificationTime = entity.LastModificationTime; | ||
|
||
// Test with many to many | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); | ||
entity.ManyToMany = new List<AppEntityWithNavigationChildManyToMany>() | ||
{ | ||
new AppEntityWithNavigationChildManyToMany | ||
{ | ||
ChildName = "ChildName1" | ||
} | ||
}; | ||
await AppEntityWithNavigationsRepository.UpdateAsync(entity); | ||
}); | ||
concurrencyStamp.ShouldNotBe(entity.ConcurrencyStamp); | ||
lastModificationTime.ShouldNotBe(entity.LastModificationTime); | ||
|
||
} | ||
} |