From a4aaeb3bc3783e1fb98ef9cb0c339454dac2d0a0 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sat, 2 Jul 2022 00:05:33 +0800 Subject: [PATCH] Add UTs --- ...OrderCreationAuthorizationHandlersTests.cs | 143 ++++++++++++++++++ ...ymentCreationAuthorizationHandlersTests.cs | 123 +++++++++++++++ .../BookingApplicationTestModule.cs | 113 +++++++++++++- .../BookingProductGroupDefinitionTests.cs | 20 +++ ...p.Plugins.Booking.Application.Tests.csproj | 4 +- .../Orders/BookingOrderCreationTests.cs | 66 ++++++++ ....EShop.Plugins.Booking.Domain.Tests.csproj | 2 - ...s.Booking.EntityFrameworkCore.Tests.csproj | 2 - ...EShop.Plugins.Booking.MongoDB.Tests.csproj | 2 - .../BookingDataSeedContributor.cs | 54 +++++-- .../BookingTestBaseModule.cs | 13 +- .../BookingTestConsts.cs | 36 +++++ ...yAbp.EShop.Plugins.Booking.TestBase.csproj | 2 - 13 files changed, 553 insertions(+), 27 deletions(-) create mode 100644 plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingOrderCreationAuthorizationHandlersTests.cs create mode 100644 plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingPaymentCreationAuthorizationHandlersTests.cs create mode 100644 plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingProductGroupDefinitions/BookingProductGroupDefinitionTests.cs create mode 100644 plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Orders/BookingOrderCreationTests.cs create mode 100644 plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestConsts.cs diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingOrderCreationAuthorizationHandlersTests.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingOrderCreationAuthorizationHandlersTests.cs new file mode 100644 index 00000000..c83db52a --- /dev/null +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingOrderCreationAuthorizationHandlersTests.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EasyAbp.EShop.Orders; +using EasyAbp.EShop.Orders.Booking.Authorization; +using EasyAbp.EShop.Orders.Orders; +using EasyAbp.EShop.Orders.Orders.Dtos; +using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; +using EasyAbp.EShop.Plugins.Booking.ProductAssets; +using EasyAbp.EShop.Products.Products.Dtos; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Data; +using Volo.Abp.Security.Claims; +using Xunit; + +namespace EasyAbp.EShop.Plugins.Booking.Authorization; + +public class BookingOrderCreationAuthorizationHandlersTests : BookingApplicationTestBase +{ + [Fact] + public async Task Should_Not_Has_Failed_If_Valid() + { + var handler = ServiceProvider.GetRequiredService(); + + var context = await CreateAuthorizationHandlerContextAsync(); + + await handler.HandleAsync(context); + + context.HasFailed.ShouldBeFalse(); + } + + [Fact] + public async Task Should_Failed_If_ProductAsset_Mapping_Not_Exists() + { + var productAssetRepository = ServiceProvider.GetRequiredService(); + + var productAsset = await productAssetRepository.GetAsync(x => + x.AssetId == BookingTestConsts.Asset1Id && x.ProductId == BookingTestConsts.BookingProduct1Id); + + await productAssetRepository.DeleteAsync(productAsset, true); + + var handler = ServiceProvider.GetRequiredService(); + + var context = await CreateAuthorizationHandlerContextAsync(); + + await handler.HandleAsync(context); + + context.HasFailed.ShouldBeTrue(); + + await productAssetRepository.InsertAsync(productAsset, true); + } + + [Fact] + public async Task Should_Failed_If_ProductAssetCategory_Mapping_Not_Exists() + { + var productAssetCategoryRepository = ServiceProvider.GetRequiredService(); + + var productAsset = await productAssetCategoryRepository.GetAsync(x => + x.AssetCategoryId == BookingTestConsts.AssetCategory1Id && + x.ProductId == BookingTestConsts.BookingProduct1Id); + + await productAssetCategoryRepository.DeleteAsync(productAsset, true); + + var handler = ServiceProvider.GetRequiredService(); + + var context = await CreateAuthorizationHandlerContextAsync(); + + await handler.HandleAsync(context); + + context.HasFailed.ShouldBeTrue(); + + await productAssetCategoryRepository.InsertAsync(productAsset, true); + } + + private Task CreateAuthorizationHandlerContextAsync() + { + var orderLine1 = new CreateOrderLineDto + { + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1 + }; + + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var orderLine2 = new CreateOrderLineDto + { + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1 + }; + + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId, + BookingTestConsts.AssetCategory1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var currentPrincipalAccessor = ServiceProvider.GetRequiredService(); + + return Task.FromResult(new AuthorizationHandlerContext( + new[] { new OrderOperationAuthorizationRequirement(OrderOperation.Creation) }, + currentPrincipalAccessor.Principal, + new OrderCreationResource + { + Input = new CreateOrderDto + { + StoreId = BookingTestConsts.Store1Id, + OrderLines = new List + { + orderLine1, orderLine2 + } + }, + ProductDictionary = new Dictionary + { + { + BookingTestConsts.BookingProduct1Id, + new ProductDto + { + Id = BookingTestConsts.BookingProduct1Id, + StoreId = BookingTestConsts.Store1Id, + ProductGroupName = BookingTestConsts.BookingProductGroupName + } + } + } + })); + } +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingPaymentCreationAuthorizationHandlersTests.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingPaymentCreationAuthorizationHandlersTests.cs new file mode 100644 index 00000000..42e07c94 --- /dev/null +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingPaymentCreationAuthorizationHandlersTests.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EasyAbp.EShop.Orders; +using EasyAbp.EShop.Orders.Orders.Dtos; +using EasyAbp.EShop.Payments.Booking.Authorization; +using EasyAbp.EShop.Payments.Payments; +using EasyAbp.EShop.Payments.Payments.Dtos; +using EasyAbp.EShop.Plugins.Booking.ProductAssets; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Data; +using Volo.Abp.Security.Claims; +using Xunit; + +namespace EasyAbp.EShop.Plugins.Booking.Authorization; + +public class BookingPaymentCreationAuthorizationHandlersTests : BookingApplicationTestBase +{ + [Fact] + public async Task Should_Not_Has_Failed_If_Valid() + { + var handler = ServiceProvider.GetRequiredService(); + + var context = await CreateAuthorizationHandlerContextAsync(); + + await handler.HandleAsync(context); + + context.HasFailed.ShouldBeFalse(); + } + + [Fact] + public async Task Should_Failed_If_ProductAsset_Mapping_Not_Exists() + { + var productAssetRepository = ServiceProvider.GetRequiredService(); + + var productAsset = await productAssetRepository.GetAsync(x => + x.AssetId == BookingTestConsts.Asset1Id && x.ProductId == BookingTestConsts.BookingProduct1Id); + + await productAssetRepository.DeleteAsync(productAsset, true); + + var handler = ServiceProvider.GetRequiredService(); + + var context = await CreateAuthorizationHandlerContextAsync(); + + await handler.HandleAsync(context); + + context.HasFailed.ShouldBeFalse(); + + await productAssetRepository.InsertAsync(productAsset, true); + } + + private Task CreateAuthorizationHandlerContextAsync() + { + var orderLine1 = new OrderLineDto + { + Id = BookingTestConsts.OrderLine1Id, + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1, + ExtraProperties = new ExtraPropertyDictionary() + }; + + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var orderLine2 = new OrderLineDto + { + Id = BookingTestConsts.OrderLine2Id, + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1, + ExtraProperties = new ExtraPropertyDictionary() + }; + + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId, + BookingTestConsts.AssetCategory1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var currentPrincipalAccessor = ServiceProvider.GetRequiredService(); + + return Task.FromResult(new AuthorizationHandlerContext( + new[] { new PaymentOperationAuthorizationRequirement(PaymentOperation.Creation) }, + currentPrincipalAccessor.Principal, + new PaymentCreationResource + { + Input = new CreatePaymentDto + { + PaymentMethod = "Free", + OrderIds = new List + { + BookingTestConsts.Order1Id + } + }, + Orders = new List + { + new() + { + Id = BookingTestConsts.Order1Id, + OrderLines = new List + { + orderLine1, orderLine2 + } + } + } + })); + } +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingApplicationTestModule.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingApplicationTestModule.cs index 16058913..80ba9e51 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingApplicationTestModule.cs +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingApplicationTestModule.cs @@ -1,12 +1,121 @@ -using Volo.Abp.Modularity; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EasyAbp.BookingService.AssetCategories; +using EasyAbp.BookingService.AssetCategories.Dtos; +using EasyAbp.BookingService.AssetOccupancies; +using EasyAbp.BookingService.Assets; +using EasyAbp.BookingService.Assets.Dtos; +using EasyAbp.BookingService.AssetSchedules; +using EasyAbp.BookingService.Dtos; +using EasyAbp.BookingService.PeriodSchemes; +using EasyAbp.BookingService.PeriodSchemes.Dtos; +using EasyAbp.EShop.Orders.Booking; +using EasyAbp.EShop.Orders.Booking.Authorization; +using EasyAbp.EShop.Orders.Orders; +using EasyAbp.EShop.Payments.Booking; +using EasyAbp.EShop.Payments.Booking.Authorization; +using EasyAbp.EShop.Products.ProductDetails; +using EasyAbp.EShop.Products.Products; +using EasyAbp.EShop.Products.Products.Dtos; +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; +using NSubstitute.ReturnsExtensions; +using Volo.Abp.Modularity; namespace EasyAbp.EShop.Plugins.Booking; [DependsOn( + typeof(EShopOrdersBookingApplicationModule), + typeof(EShopPaymentsBookingApplicationModule), typeof(EShopPluginsBookingApplicationModule), typeof(BookingDomainTestModule) - )] +)] public class BookingApplicationTestModule : AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddTransient(); + context.Services.AddTransient(); + } + public override void ConfigureServices(ServiceConfigurationContext context) + { + var services = context.Services; + + var periodSchemeAppService = Substitute.For(); + services.AddTransient(_ => periodSchemeAppService); + periodSchemeAppService.GetAsync(BookingTestConsts.PeriodScheme1Id).Returns(new PeriodSchemeDto + { + Id = BookingTestConsts.PeriodScheme1Id, + Name = "PeriodScheme1", + IsDefault = true, + Periods = new List + { + new() + { + Id = BookingTestConsts.Period1Id, + StartingTime = BookingTestConsts.Period1StartingTime, + Duration = BookingTestConsts.Period1Duration + } + } + }); + + var assetOccupancyAppService = Substitute.For(); + services.AddTransient(_ => assetOccupancyAppService); + assetOccupancyAppService.CheckBulkCreateAsync(null).ReturnsForAnyArgs(Task.CompletedTask); + + var productAppService = Substitute.For(); + services.AddTransient(_ => productAppService); + productAppService.GetAsync(BookingTestConsts.BookingProduct1Id).Returns(new ProductDto + { + Id = BookingTestConsts.BookingProduct1Id, + StoreId = BookingTestConsts.Store1Id, + ProductGroupName = BookingTestConsts.BookingProductGroupName, + ProductSkus = new List + { + new() + { + Id = BookingTestConsts.BookingProduct1Sku1Id, + AttributeOptionIds = new List(), + Currency = "USD", + OrderMinQuantity = 1, + OrderMaxQuantity = 2 + } + } + }); + + var assetAppService = Substitute.For(); + services.AddTransient(_ => assetAppService); + assetAppService.GetAsync(BookingTestConsts.Asset1Id).Returns(new AssetDto + { + Id = BookingTestConsts.Asset1Id, + Name = "Camera1", + AssetDefinitionName = "Camera", + AssetCategoryId = BookingTestConsts.AssetCategory1Id, + PeriodSchemeId = BookingTestConsts.PeriodScheme1Id, + DefaultPeriodUsable = PeriodUsable.Accept, + Volume = 1, + TimeInAdvance = new TimeInAdvanceDto + { + MaxDaysInAdvance = 7, + MinDaysInAdvance = 1 + }, + }); + + var assetCategoryAppService = Substitute.For(); + services.AddTransient(_ => assetCategoryAppService); + assetCategoryAppService.GetAsync(BookingTestConsts.AssetCategory1Id).Returns(new AssetCategoryDto + { + Id = BookingTestConsts.AssetCategory1Id, + DisplayName = "Cameras" + }); + + var productDetailAppService = Substitute.For(); + services.AddTransient(_ => productDetailAppService); + + var orderRepository = Substitute.For(); + services.AddTransient(_ => orderRepository); + orderRepository.InsertAsync(null).ReturnsNullForAnyArgs(); + } } diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingProductGroupDefinitions/BookingProductGroupDefinitionTests.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingProductGroupDefinitions/BookingProductGroupDefinitionTests.cs new file mode 100644 index 00000000..5d2b046c --- /dev/null +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingProductGroupDefinitions/BookingProductGroupDefinitionTests.cs @@ -0,0 +1,20 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Xunit; + +namespace EasyAbp.EShop.Plugins.Booking.BookingProductGroupDefinitions; + +public class BookingProductGroupDefinitionTests : BookingApplicationTestBase +{ + [Fact] + public async Task Should_Match_Booking_Product() + { + var definitionAppService = ServiceProvider.GetRequiredService(); + + var productGroupNames = (await definitionAppService.GetListAsync()).Items.Select(x => x.ProductGroupName); + + productGroupNames.ShouldContain(BookingTestConsts.BookingProductGroupName); + } +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj index 58dfa8cf..01cf0e28 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj @@ -1,13 +1,13 @@ - - net6.0 EasyAbp.EShop.Plugins.Booking + + diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Orders/BookingOrderCreationTests.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Orders/BookingOrderCreationTests.cs new file mode 100644 index 00000000..4221c8ea --- /dev/null +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Orders/BookingOrderCreationTests.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using EasyAbp.EShop.Orders; +using EasyAbp.EShop.Orders.Orders; +using EasyAbp.EShop.Orders.Orders.Dtos; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Data; +using Xunit; + +namespace EasyAbp.EShop.Plugins.Booking.Orders; + +public class BookingOrderCreationTests : BookingApplicationTestBase +{ + [Fact] + public async Task Should_Override_Booking_Price() + { + var orderAppService = ServiceProvider.GetRequiredService(); + + var orderLine1 = new CreateOrderLineDto + { + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1 + }; + + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var orderLine2 = new CreateOrderLineDto + { + ProductId = BookingTestConsts.BookingProduct1Id, + ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, + Quantity = 1 + }; + + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, + BookingTestConsts.PeriodScheme1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId, + BookingTestConsts.AssetCategory1Id); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, + BookingTestConsts.Period1StartingTime); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); + orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); + + var order = await orderAppService.CreateAsync(new CreateOrderDto + { + StoreId = BookingTestConsts.Store1Id, + OrderLines = new List + { + orderLine1, orderLine2 + } + }); + + order.ActualTotalPrice.ShouldBe(15m); + } +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj index 815b084e..2b3d16d0 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj @@ -1,7 +1,5 @@ - - net6.0 EasyAbp.EShop.Plugins.Booking diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj index c180be41..13943578 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj @@ -1,7 +1,5 @@ - - net6.0 EasyAbp.EShop.Plugins.Booking diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj index 5c8d2da1..9fdea266 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj @@ -1,7 +1,5 @@ - - net6.0 EasyAbp.EShop.Plugins.Booking diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingDataSeedContributor.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingDataSeedContributor.cs index 9138c859..1b10fba2 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingDataSeedContributor.cs +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingDataSeedContributor.cs @@ -1,8 +1,13 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using EasyAbp.EShop.Plugins.Booking.GrantedStores; +using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; +using EasyAbp.EShop.Plugins.Booking.ProductAssets; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; +using Volo.Abp.Uow; namespace EasyAbp.EShop.Plugins.Booking; @@ -10,23 +15,48 @@ public class BookingDataSeedContributor : IDataSeedContributor, ITransientDepend { private readonly IGuidGenerator _guidGenerator; private readonly ICurrentTenant _currentTenant; + private readonly IGrantedStoreRepository _grantedStoreRepository; + private readonly ProductAssetManager _productAssetManager; + private readonly IProductAssetRepository _productAssetRepository; + private readonly ProductAssetCategoryManager _productAssetCategoryManager; + private readonly IProductAssetCategoryRepository _productAssetCategoryRepository; public BookingDataSeedContributor( - IGuidGenerator guidGenerator, ICurrentTenant currentTenant) + IGuidGenerator guidGenerator, + ICurrentTenant currentTenant, + IGrantedStoreRepository grantedStoreRepository, + ProductAssetManager productAssetManager, + IProductAssetRepository productAssetRepository, + ProductAssetCategoryManager productAssetCategoryManager, + IProductAssetCategoryRepository productAssetCategoryRepository) { _guidGenerator = guidGenerator; _currentTenant = currentTenant; + _grantedStoreRepository = grantedStoreRepository; + _productAssetManager = productAssetManager; + _productAssetRepository = productAssetRepository; + _productAssetCategoryManager = productAssetCategoryManager; + _productAssetCategoryRepository = productAssetCategoryRepository; } - public Task SeedAsync(DataSeedContext context) + [UnitOfWork] + public virtual async Task SeedAsync(DataSeedContext context) { - /* Instead of returning the Task.CompletedTask, you can insert your test data - * at this point! - */ - - using (_currentTenant.Change(context?.TenantId)) - { - return Task.CompletedTask; - } + using var change = _currentTenant.Change(context?.TenantId); + + await _grantedStoreRepository.InsertAsync(new GrantedStore(_guidGenerator.Create(), _currentTenant.Id, + BookingTestConsts.Store1Id, BookingTestConsts.Asset1Id, null, false)); + + await _grantedStoreRepository.InsertAsync(new GrantedStore(_guidGenerator.Create(), _currentTenant.Id, + BookingTestConsts.Store1Id, null, BookingTestConsts.AssetCategory1Id, false)); + + await _productAssetRepository.InsertAsync(await _productAssetManager.CreateAsync(BookingTestConsts.Store1Id, + BookingTestConsts.BookingProduct1Id, BookingTestConsts.BookingProduct1Sku1Id, BookingTestConsts.Asset1Id, + BookingTestConsts.PeriodScheme1Id, DateTime.Parse("1970-1-1"), null, 5m)); + + await _productAssetCategoryRepository.InsertAsync(await _productAssetCategoryManager.CreateAsync( + BookingTestConsts.Store1Id, BookingTestConsts.BookingProduct1Id, BookingTestConsts.BookingProduct1Sku1Id, + BookingTestConsts.AssetCategory1Id, BookingTestConsts.PeriodScheme1Id, DateTime.Parse("1970-1-1"), null, + 10m)); } -} +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestBaseModule.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestBaseModule.cs index 710f4cd7..847de8a4 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestBaseModule.cs +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestBaseModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using EasyAbp.EShop.Plugins.Booking.Options; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Authorization; using Volo.Abp.Autofac; @@ -13,12 +14,18 @@ namespace EasyAbp.EShop.Plugins.Booking; typeof(AbpTestBaseModule), typeof(AbpAuthorizationModule), typeof(EShopPluginsBookingDomainModule) - )] +)] public class BookingTestBaseModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAlwaysAllowAuthorization(); + + Configure(options => + { + options.BookingProductGroups.Add( + new BookingProductGroupDefinition(BookingTestConsts.BookingProductGroupName)); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -38,4 +45,4 @@ public class BookingTestBaseModule : AbpModule } }); } -} +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestConsts.cs b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestConsts.cs new file mode 100644 index 00000000..b8ed60bf --- /dev/null +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestConsts.cs @@ -0,0 +1,36 @@ +using System; + +namespace EasyAbp.EShop.Plugins.Booking; + +public static class BookingTestConsts +{ + public static string BookingProductGroupName { get; } = "CameraBooking"; + + public static Guid Store1Id { get; } = Guid.NewGuid(); + + public static Guid Order1Id { get; } = Guid.NewGuid(); + + public static Guid OrderLine1Id { get; } = Guid.NewGuid(); + + public static Guid OrderLine2Id { get; } = Guid.NewGuid(); + + public static Guid BookingProduct1Id { get; } = Guid.NewGuid(); + + public static Guid BookingProduct1Sku1Id { get; } = Guid.NewGuid(); + + public static Guid Asset1Id { get; } = Guid.NewGuid(); + + public static Guid AssetCategory1Id { get; } = Guid.NewGuid(); + + public static Guid PeriodScheme1Id { get; } = Guid.NewGuid(); + + public static Guid Period1Id { get; } = Guid.NewGuid(); + + public static DateTime BookingDate { get; } = DateTime.Today.AddDays(1); + + public static TimeSpan Period1StartingTime { get; } = TimeSpan.FromHours(8); // from 8:00 + + public static TimeSpan Period1Duration { get; } = TimeSpan.FromHours(2); // to 10:00 (8:00 + 2h) + + public static int Volume { get; } = 1; +} \ No newline at end of file diff --git a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj index 858b3cd6..ed753eec 100644 --- a/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj +++ b/plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj @@ -1,7 +1,5 @@ - - net6.0 EasyAbp.EShop.Plugins.Booking