mirror of https://github.com/EasyAbp/EShop.git
25 changed files with 2925 additions and 16 deletions
@ -0,0 +1,44 @@ |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Products.ProductDetails; |
|||
using EasyAbp.EShop.Products.ProductDetails.Dtos; |
|||
using EasyAbp.EShop.Products.ProductHistories; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductDetailHistories |
|||
{ |
|||
public class ProductDetailHistoryRecorder : ILocalEventHandler<EntityChangedEventData<ProductDetail>>, ITransientDependency |
|||
{ |
|||
private readonly IGuidGenerator _guidGenerator; |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
private readonly IProductDetailHistoryRepository _productDetailHistoryRepository; |
|||
|
|||
public ProductDetailHistoryRecorder( |
|||
IGuidGenerator guidGenerator, |
|||
IObjectMapper objectMapper, |
|||
IJsonSerializer jsonSerializer, |
|||
IProductDetailHistoryRepository productDetailHistoryRepository) |
|||
{ |
|||
_guidGenerator = guidGenerator; |
|||
_objectMapper = objectMapper; |
|||
_jsonSerializer = jsonSerializer; |
|||
_productDetailHistoryRepository = productDetailHistoryRepository; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(EntityChangedEventData<ProductDetail> eventData) |
|||
{ |
|||
var modificationTime = eventData.Entity.LastModificationTime ?? eventData.Entity.CreationTime; |
|||
|
|||
var serializedDto = |
|||
_jsonSerializer.Serialize(_objectMapper.Map<ProductDetail, ProductDetailDto>(eventData.Entity)); |
|||
|
|||
await _productDetailHistoryRepository.InsertAsync(new ProductDetailHistory(_guidGenerator.Create(), |
|||
eventData.Entity.Id, modificationTime, serializedDto)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Products.Products; |
|||
using EasyAbp.EShop.Products.Products.Dtos; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductHistories |
|||
{ |
|||
public class ProductHistoryRecorder : ILocalEventHandler<EntityChangedEventData<Product>>, ITransientDependency |
|||
{ |
|||
private readonly IGuidGenerator _guidGenerator; |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
private readonly IProductHistoryRepository _productHistoryRepository; |
|||
|
|||
public ProductHistoryRecorder( |
|||
IGuidGenerator guidGenerator, |
|||
IObjectMapper objectMapper, |
|||
IJsonSerializer jsonSerializer, |
|||
IProductHistoryRepository productHistoryRepository) |
|||
{ |
|||
_guidGenerator = guidGenerator; |
|||
_objectMapper = objectMapper; |
|||
_jsonSerializer = jsonSerializer; |
|||
_productHistoryRepository = productHistoryRepository; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(EntityChangedEventData<Product> eventData) |
|||
{ |
|||
var modificationTime = eventData.Entity.LastModificationTime ?? eventData.Entity.CreationTime; |
|||
|
|||
var serializedDto = _jsonSerializer.Serialize(_objectMapper.Map<Product, ProductDto>(eventData.Entity)); |
|||
|
|||
await _productHistoryRepository.InsertAsync(new ProductHistory(_guidGenerator.Create(), eventData.Entity.Id, |
|||
modificationTime, serializedDto)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductDetailHistories |
|||
{ |
|||
public interface IProductDetailHistoryRepository : IRepository<ProductDetailHistory, Guid> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductDetailHistories |
|||
{ |
|||
public class ProductDetailHistory : AggregateRoot<Guid> |
|||
{ |
|||
public virtual Guid ProductDetailId { get; protected set; } |
|||
|
|||
public virtual DateTime ModificationTime { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string SerializedDto { get; protected set; } |
|||
|
|||
protected ProductDetailHistory() {} |
|||
|
|||
public ProductDetailHistory( |
|||
Guid id, |
|||
Guid productDetailId, |
|||
DateTime modificationTime, |
|||
[NotNull] string serializedDto) : base(id) |
|||
{ |
|||
ProductDetailId = productDetailId; |
|||
ModificationTime = modificationTime; |
|||
SerializedDto = serializedDto; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductHistories |
|||
{ |
|||
public interface IProductHistoryRepository : IRepository<ProductHistory, Guid> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductHistories |
|||
{ |
|||
public class ProductHistory : AggregateRoot<Guid> |
|||
{ |
|||
public virtual Guid ProductId { get; protected set; } |
|||
|
|||
public virtual DateTime ModificationTime { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string SerializedDto { get; protected set; } |
|||
|
|||
protected ProductHistory() {} |
|||
|
|||
public ProductHistory( |
|||
Guid id, |
|||
Guid productId, |
|||
DateTime modificationTime, |
|||
[NotNull] string serializedDto) : base(id) |
|||
{ |
|||
ProductId = productId; |
|||
ModificationTime = modificationTime; |
|||
SerializedDto = serializedDto; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using EasyAbp.EShop.Products.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductDetailHistories |
|||
{ |
|||
public class ProductDetailHistoryRepository : EfCoreRepository<ProductsDbContext, ProductDetailHistory, Guid>, IProductDetailHistoryRepository |
|||
{ |
|||
public ProductDetailHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using EasyAbp.EShop.Products.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductHistories |
|||
{ |
|||
public class ProductHistoryRepository : EfCoreRepository<ProductsDbContext, ProductHistory, Guid>, IProductHistoryRepository |
|||
{ |
|||
public ProductHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductDetailHistories |
|||
{ |
|||
public class ProductDetailHistoryDomainTests : ProductsDomainTestBase |
|||
{ |
|||
public ProductDetailHistoryDomainTests() |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Test1() |
|||
{ |
|||
// Arrange
|
|||
|
|||
// Assert
|
|||
|
|||
// Assert
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductHistories |
|||
{ |
|||
public class ProductHistoryDomainTests : ProductsDomainTestBase |
|||
{ |
|||
public ProductHistoryDomainTests() |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Test1() |
|||
{ |
|||
// Arrange
|
|||
|
|||
// Assert
|
|||
|
|||
// Assert
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Products.ProductDetailHistories; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Xunit; |
|||
|
|||
namespace EasyAbp.EShop.Products.EntityFrameworkCore.ProductDetailHistories |
|||
{ |
|||
public class ProductDetailHistoryRepositoryTests : ProductsEntityFrameworkCoreTestBase |
|||
{ |
|||
private readonly IRepository<ProductDetailHistory, Guid> _productDetailHistoryRepository; |
|||
|
|||
public ProductDetailHistoryRepositoryTests() |
|||
{ |
|||
_productDetailHistoryRepository = GetRequiredService<IRepository<ProductDetailHistory, Guid>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Test1() |
|||
{ |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
// Arrange
|
|||
|
|||
// Act
|
|||
|
|||
//Assert
|
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EasyAbp.EShop.Products.ProductHistories; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Xunit; |
|||
|
|||
namespace EasyAbp.EShop.Products.EntityFrameworkCore.ProductHistories |
|||
{ |
|||
public class ProductHistoryRepositoryTests : ProductsEntityFrameworkCoreTestBase |
|||
{ |
|||
private readonly IRepository<ProductHistory, Guid> _productHistoryRepository; |
|||
|
|||
public ProductHistoryRepositoryTests() |
|||
{ |
|||
_productHistoryRepository = GetRequiredService<IRepository<ProductHistory, Guid>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Test1() |
|||
{ |
|||
await WithUnitOfWorkAsync(async () => |
|||
{ |
|||
// Arrange
|
|||
|
|||
// Act
|
|||
|
|||
//Assert
|
|||
}); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace EasyMall.Migrations |
|||
{ |
|||
public partial class AddedHistoryEntities : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "ProductsProductDetailHistories", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(nullable: false), |
|||
ExtraProperties = table.Column<string>(nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(nullable: true), |
|||
ProductDetailId = table.Column<Guid>(nullable: false), |
|||
ModificationTime = table.Column<DateTime>(nullable: false), |
|||
SerializedDto = table.Column<string>(nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_ProductsProductDetailHistories", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "ProductsProductHistories", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(nullable: false), |
|||
ExtraProperties = table.Column<string>(nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(nullable: true), |
|||
ProductId = table.Column<Guid>(nullable: false), |
|||
ModificationTime = table.Column<DateTime>(nullable: false), |
|||
SerializedDto = table.Column<string>(nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_ProductsProductHistories", x => x.Id); |
|||
}); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "ProductsProductDetailHistories"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "ProductsProductHistories"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue