From d60836c8dbcb09aa8d59bab26f5152eda26eddea Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Wed, 12 Dec 2018 14:24:07 +0300 Subject: [PATCH] #246 Implement concurrency stamp --- .../Abp/EntityFrameworkCore/AbpDbContext.cs | 1 + .../Abp/MongoDB/AbpBsonClassMapExtensions.cs | 5 +- .../Testing/EntityChangeEvents_Tests.cs | 54 +------------------ 3 files changed, 6 insertions(+), 54 deletions(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 530fb45ccf..6540930405 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -261,6 +261,7 @@ namespace Volo.Abp.EntityFrameworkCore return; } + Entry(entity).Property(x => x.ConcurrencyStamp).OriginalValue = entity.ConcurrencyStamp; entity.ConcurrencyStamp = Guid.NewGuid().ToString("N"); } diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs index 67fe25d9b6..68a2719c38 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs @@ -8,7 +8,10 @@ namespace Volo.Abp.MongoDB public static void ConfigureExtraProperties(this BsonClassMap map) where T : class, IHasExtraProperties { - map.MapExtraElementsProperty(x => x.ExtraProperties); + map.SetExtraElementsMember(new BsonMemberMap( + map, + typeof(T).GetMember(nameof(IHasExtraProperties.ExtraProperties))[0]) + ); } } } diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index 67032507f3..184b7698be 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -35,9 +35,6 @@ namespace Volo.Abp.TestApp.Testing var creatingEventTriggered = false; var createdEventTriggered = false; var createdEtoTriggered = false; - var updatedEtoTriggered = false; - var updatingEventTriggered = false; - var updatedEventTriggered = false; using (var uow = GetRequiredService().Begin()) { @@ -45,18 +42,14 @@ namespace Volo.Abp.TestApp.Testing { creatingEventTriggered.ShouldBeFalse(); createdEventTriggered.ShouldBeFalse(); - updatingEventTriggered.ShouldBeFalse(); - updatedEventTriggered.ShouldBeFalse(); creatingEventTriggered = true; data.Entity.Name.ShouldBe(personName); - /* Want to change age from 15 to 18 - * Expect to trigger EntityUpdatingEventData, EntityUpdatedEventData events */ + /* Want to change age from 15 to 18 */ data.Entity.Age.ShouldBe(15); data.Entity.Age = 18; - PersonRepository.Update(data.Entity); return Task.CompletedTask; }); @@ -64,8 +57,6 @@ namespace Volo.Abp.TestApp.Testing { creatingEventTriggered.ShouldBeTrue(); createdEventTriggered.ShouldBeFalse(); - updatingEventTriggered.ShouldBeTrue(); - updatedEventTriggered.ShouldBeFalse(); createdEventTriggered = true; @@ -84,46 +75,6 @@ namespace Volo.Abp.TestApp.Testing return Task.CompletedTask; }); - LocalEventBus.Subscribe>(data => - { - creatingEventTriggered.ShouldBeTrue(); - createdEventTriggered.ShouldBeFalse(); - updatingEventTriggered.ShouldBeFalse(); - updatedEventTriggered.ShouldBeFalse(); - - updatingEventTriggered = true; - - data.Entity.Name.ShouldBe(personName); - data.Entity.Age.ShouldBe(18); - - return Task.CompletedTask; - }); - - LocalEventBus.Subscribe>(data => - { - creatingEventTriggered.ShouldBeTrue(); - createdEventTriggered.ShouldBeTrue(); - updatingEventTriggered.ShouldBeTrue(); - updatedEventTriggered.ShouldBeFalse(); - - updatedEventTriggered = true; - - data.Entity.Name.ShouldBe(personName); - data.Entity.Age.ShouldBe(18); - - return Task.CompletedTask; - }); - - DistributedEventBus.Subscribe>(eto => - { - eto.Entity.Name.ShouldBe(personName); - eto.Entity.Age.ShouldBe(18); - - updatedEtoTriggered = true; - - return Task.CompletedTask; - }); - PersonRepository.Insert(new Person(Guid.NewGuid(), personName, 15)); uow.Complete(); @@ -132,9 +83,6 @@ namespace Volo.Abp.TestApp.Testing creatingEventTriggered.ShouldBeTrue(); createdEventTriggered.ShouldBeTrue(); createdEtoTriggered.ShouldBeTrue(); - updatingEventTriggered.ShouldBeTrue(); - updatedEventTriggered.ShouldBeTrue(); - updatedEtoTriggered.ShouldBeTrue(); } } }