From 4ed29f33549328d576bad79c68e6221ed32f0fd0 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Thu, 16 Mar 2023 00:09:47 +0800 Subject: [PATCH] Register `EShopPaymentsObjectExtensions` --- .github/workflows/publish.yml | 39 ++++++------ Directory.Build.props | 2 +- common.props | 2 +- .../Payments/EShopPaymentsDomainModule.cs | 11 ++-- .../EShopPaymentsObjectExtensions.cs | 63 +++++++++++++++++++ .../Payments/PaymentAppServiceTests.cs | 17 +++-- .../Payments/TestCreatePaymentEventHandler.cs | 7 ++- 7 files changed, 110 insertions(+), 31 deletions(-) create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/ObjectExtending/EShopPaymentsObjectExtensions.cs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9bcba1ed..26571baa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - main jobs: publish: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: NuGet/setup-nuget@v1 @@ -38,36 +38,37 @@ jobs: run: dotnet test -c Release --no-restore --no-build - name: dotnet pack - run: dotnet pack -c Release --no-build -o dest + run: dotnet pack -c Release --no-build --property PackageOutputPath=${{ github.workspace }}/nugetPackages/ - name: remove unused packages run: | - cd dest - del * -Exclude EasyAbp.* - del * -Exclude *.${{ steps.getVersion.outputs.first_match }}.nupkg - del *.Blazor.Host.* - del *.Blazor.Server.Host.* - del *.Host.Shared.* - del *.HttpApi.Host.* - del *.IdentityServer.* - del *.AuthServer.* - del *.Web.Host.* - del *.Web.Unified.* - del *.HttpApi.Client.ConsoleTestApp.* - del *.Tests.* - del *.TestBase.* - dir -name + cd ${{ github.workspace }}/nugetPackages + shopt -s extglob + rm -f !(EasyAbp.*) + rm -f !(*.${{ steps.getVersion.outputs.first_match }}.nupkg) + rm -f *.Blazor.Host.* + rm -f *.Blazor.Server.Host.* + rm -f *.Host.Shared.* + rm -f *.HttpApi.Host.* + rm -f *.IdentityServer.* + rm -f *.AuthServer.* + rm -f *.Web.Host.* + rm -f *.Web.Unified.* + rm -f *.HttpApi.Client.ConsoleTestApp.* + rm -f *.Tests.* + rm -f *.TestBase.* + ls - name: dotnet nuget push to GitHub uses: tanaka-takayoshi/nuget-publish-to-github-packages-action@v2.1 with: - nupkg-path: 'dest\*.nupkg' + nupkg-path: '${{ github.workspace }}/nugetPackages/*.nupkg' repo-owner: 'EasyAbp' gh-user: 'EasyAbp' token: ${{ secrets.GITHUB_TOKEN }} - name: dotnet nuget push to NuGet - run: dotnet nuget push dest\*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + run: dotnet nuget push ${{ github.workspace }}/nugetPackages/*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate - name: determine if the tag exists uses: mukunku/tag-exists-action@v1.0.0 diff --git a/Directory.Build.props b/Directory.Build.props index 9c3744d1..0c12f122 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,7 +3,7 @@ 7.0.0 2.9.0 - 2.3.0 + 2.3.2 1.3.0 0.4.0 1.9.0 diff --git a/common.props b/common.props index 68bee29c..773fe41b 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - 3.3.1 + 3.3.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs index aae7a6ea..70a0621b 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs @@ -1,4 +1,5 @@ -using EasyAbp.EShop.Payments.Payments; +using EasyAbp.EShop.Payments.ObjectExtending; +using EasyAbp.EShop.Payments.Payments; using EasyAbp.EShop.Payments.Refunds; using EasyAbp.EShop.Stores; using Microsoft.Extensions.DependencyInjection; @@ -17,16 +18,18 @@ namespace EasyAbp.EShop.Payments { public override void PreConfigureServices(ServiceConfigurationContext context) { + EShopPaymentsObjectExtensions.Configure(); + Configure(options => { options.EtoMappings.Add(typeof(EShopPaymentsDomainModule)); options.EtoMappings.Add(typeof(EShopPaymentsDomainModule)); - + options.AutoEventSelectors.Add(); options.AutoEventSelectors.Add(); }); } - + public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAutoMapperObjectMapper(); @@ -37,4 +40,4 @@ namespace EasyAbp.EShop.Payments }); } } -} +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/ObjectExtending/EShopPaymentsObjectExtensions.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/ObjectExtending/EShopPaymentsObjectExtensions.cs new file mode 100644 index 00000000..7aa81748 --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/ObjectExtending/EShopPaymentsObjectExtensions.cs @@ -0,0 +1,63 @@ +using System; +using EasyAbp.EShop.Payments.Payments; +using EasyAbp.EShop.Payments.Refunds; +using EasyAbp.PaymentService.Payments; +using EasyAbp.PaymentService.Refunds; +using Volo.Abp.ObjectExtending; +using Volo.Abp.Threading; + +namespace EasyAbp.EShop.Payments.ObjectExtending +{ + public static class EShopPaymentsObjectExtensions + { + private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); + + public static void Configure() + { + OneTimeRunner.Run(() => + { + /* You can configure extension properties to entities or other object types + * defined in the depended modules. + * + * If you are using EF Core and want to map the entity extension properties to new + * table fields in the database, then configure them in the DenturePlusEfCoreEntityExtensionMappings + * + * Example: + * + * ObjectExtensionManager.Instance + * .AddOrUpdateProperty("Title"); + * + * See the documentation for more: + * https://docs.abp.io/en/abp/latest/Object-Extensions + */ + + ObjectExtensionManager.Instance + .AddOrUpdate(new [] + { + typeof(PaymentItem), + typeof(EShopPaymentItemEto), + typeof(PaymentItemEto), + typeof(CreatePaymentItemEto) + }, options => + { + options.AddOrUpdateProperty(nameof(PaymentItem.StoreId)); + }); + + ObjectExtensionManager.Instance + .AddOrUpdate(new [] + { + typeof(RefundItem), + typeof(EShopRefundItemEto), + typeof(RefundItemEto), + typeof(CreateRefundItemInput) + }, options => + { + options.AddOrUpdateProperty(nameof(RefundItem.StoreId)); + options.AddOrUpdateProperty(nameof(RefundItem.OrderId)); + options.AddOrUpdateProperty(nameof(RefundItem.OrderLines)); + options.AddOrUpdateProperty(nameof(RefundItem.OrderExtraFees)); + }); + }); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs b/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs index c4967028..ea32dd9b 100644 --- a/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs +++ b/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using EasyAbp.EShop.Orders.Orders; using EasyAbp.EShop.Orders.Orders.Dtos; @@ -7,6 +8,7 @@ using EasyAbp.EShop.Payments.Payments.Dtos; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; +using Volo.Abp.Data; using Xunit; namespace EasyAbp.EShop.Payments.Payments @@ -41,7 +43,7 @@ namespace EasyAbp.EShop.Payments.Payments } } })); - + services.AddTransient(_ => orderService); } @@ -66,8 +68,15 @@ namespace EasyAbp.EShop.Payments.Payments // Act & Assert await _paymentAppService.CreateAsync(request); - - _testCreatePaymentEventHandler.IsEventPublished.ShouldBe(true ); + + _testCreatePaymentEventHandler.IsEventPublished.ShouldBe(true); + _testCreatePaymentEventHandler.CreatePaymentEto.PaymentItems.Count.ShouldBe(1); + _testCreatePaymentEventHandler.CreatePaymentEto.PaymentItems.First().ItemType + .ShouldBe(PaymentsConsts.PaymentItemType); + _testCreatePaymentEventHandler.CreatePaymentEto.PaymentItems.First().ItemKey + .ShouldBe(PaymentsTestData.Order1.ToString()); + _testCreatePaymentEventHandler.CreatePaymentEto.PaymentItems.First() + .GetProperty(nameof(PaymentItem.StoreId)).ShouldBe(PaymentsTestData.Store1); } } -} +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/TestCreatePaymentEventHandler.cs b/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/TestCreatePaymentEventHandler.cs index 46d6104f..527c4dbb 100644 --- a/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/TestCreatePaymentEventHandler.cs +++ b/modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/TestCreatePaymentEventHandler.cs @@ -8,11 +8,14 @@ namespace EasyAbp.EShop.Payments.Payments public class TestCreatePaymentEventHandler : IDistributedEventHandler, ISingletonDependency { public bool IsEventPublished { get; protected set; } - + + public CreatePaymentEto CreatePaymentEto { get; protected set; } + public Task HandleEventAsync(CreatePaymentEto eventData) { IsEventPublished = true; - + CreatePaymentEto = eventData; + return Task.CompletedTask; } }