Browse Source

Add UTs

pull/150/head
gdlcf88 4 years ago
parent
commit
a4aaeb3bc3
  1. 143
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingOrderCreationAuthorizationHandlersTests.cs
  2. 123
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Authorization/BookingPaymentCreationAuthorizationHandlersTests.cs
  3. 113
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingApplicationTestModule.cs
  4. 20
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/BookingProductGroupDefinitions/BookingProductGroupDefinitionTests.cs
  5. 4
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj
  6. 66
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/Orders/BookingOrderCreationTests.cs
  7. 2
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj
  8. 2
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj
  9. 2
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj
  10. 54
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingDataSeedContributor.cs
  11. 13
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestBaseModule.cs
  12. 36
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/BookingTestConsts.cs
  13. 2
      plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj

143
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<BookingOrderCreationAuthorizationHandler>();
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<IProductAssetRepository>();
var productAsset = await productAssetRepository.GetAsync(x =>
x.AssetId == BookingTestConsts.Asset1Id && x.ProductId == BookingTestConsts.BookingProduct1Id);
await productAssetRepository.DeleteAsync(productAsset, true);
var handler = ServiceProvider.GetRequiredService<BookingOrderCreationAuthorizationHandler>();
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<IProductAssetCategoryRepository>();
var productAsset = await productAssetCategoryRepository.GetAsync(x =>
x.AssetCategoryId == BookingTestConsts.AssetCategory1Id &&
x.ProductId == BookingTestConsts.BookingProduct1Id);
await productAssetCategoryRepository.DeleteAsync(productAsset, true);
var handler = ServiceProvider.GetRequiredService<BookingOrderCreationAuthorizationHandler>();
var context = await CreateAuthorizationHandlerContextAsync();
await handler.HandleAsync(context);
context.HasFailed.ShouldBeTrue();
await productAssetCategoryRepository.InsertAsync(productAsset, true);
}
private Task<AuthorizationHandlerContext> 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<ICurrentPrincipalAccessor>();
return Task.FromResult(new AuthorizationHandlerContext(
new[] { new OrderOperationAuthorizationRequirement(OrderOperation.Creation) },
currentPrincipalAccessor.Principal,
new OrderCreationResource
{
Input = new CreateOrderDto
{
StoreId = BookingTestConsts.Store1Id,
OrderLines = new List<CreateOrderLineDto>
{
orderLine1, orderLine2
}
},
ProductDictionary = new Dictionary<Guid, ProductDto>
{
{
BookingTestConsts.BookingProduct1Id,
new ProductDto
{
Id = BookingTestConsts.BookingProduct1Id,
StoreId = BookingTestConsts.Store1Id,
ProductGroupName = BookingTestConsts.BookingProductGroupName
}
}
}
}));
}
}

123
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<BookingPaymentCreationAuthorizationHandler>();
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<IProductAssetRepository>();
var productAsset = await productAssetRepository.GetAsync(x =>
x.AssetId == BookingTestConsts.Asset1Id && x.ProductId == BookingTestConsts.BookingProduct1Id);
await productAssetRepository.DeleteAsync(productAsset, true);
var handler = ServiceProvider.GetRequiredService<BookingPaymentCreationAuthorizationHandler>();
var context = await CreateAuthorizationHandlerContextAsync();
await handler.HandleAsync(context);
context.HasFailed.ShouldBeFalse();
await productAssetRepository.InsertAsync(productAsset, true);
}
private Task<AuthorizationHandlerContext> 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<ICurrentPrincipalAccessor>();
return Task.FromResult(new AuthorizationHandlerContext(
new[] { new PaymentOperationAuthorizationRequirement(PaymentOperation.Creation) },
currentPrincipalAccessor.Principal,
new PaymentCreationResource
{
Input = new CreatePaymentDto
{
PaymentMethod = "Free",
OrderIds = new List<Guid>
{
BookingTestConsts.Order1Id
}
},
Orders = new List<OrderDto>
{
new()
{
Id = BookingTestConsts.Order1Id,
OrderLines = new List<OrderLineDto>
{
orderLine1, orderLine2
}
}
}
}));
}
}

113
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<BookingOrderCreationAuthorizationHandler>();
context.Services.AddTransient<BookingPaymentCreationAuthorizationHandler>();
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var services = context.Services;
var periodSchemeAppService = Substitute.For<IPeriodSchemeAppService>();
services.AddTransient(_ => periodSchemeAppService);
periodSchemeAppService.GetAsync(BookingTestConsts.PeriodScheme1Id).Returns(new PeriodSchemeDto
{
Id = BookingTestConsts.PeriodScheme1Id,
Name = "PeriodScheme1",
IsDefault = true,
Periods = new List<PeriodDto>
{
new()
{
Id = BookingTestConsts.Period1Id,
StartingTime = BookingTestConsts.Period1StartingTime,
Duration = BookingTestConsts.Period1Duration
}
}
});
var assetOccupancyAppService = Substitute.For<IAssetOccupancyAppService>();
services.AddTransient(_ => assetOccupancyAppService);
assetOccupancyAppService.CheckBulkCreateAsync(null).ReturnsForAnyArgs(Task.CompletedTask);
var productAppService = Substitute.For<IProductAppService>();
services.AddTransient(_ => productAppService);
productAppService.GetAsync(BookingTestConsts.BookingProduct1Id).Returns(new ProductDto
{
Id = BookingTestConsts.BookingProduct1Id,
StoreId = BookingTestConsts.Store1Id,
ProductGroupName = BookingTestConsts.BookingProductGroupName,
ProductSkus = new List<ProductSkuDto>
{
new()
{
Id = BookingTestConsts.BookingProduct1Sku1Id,
AttributeOptionIds = new List<Guid>(),
Currency = "USD",
OrderMinQuantity = 1,
OrderMaxQuantity = 2
}
}
});
var assetAppService = Substitute.For<IAssetAppService>();
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<IAssetCategoryAppService>();
services.AddTransient(_ => assetCategoryAppService);
assetCategoryAppService.GetAsync(BookingTestConsts.AssetCategory1Id).Returns(new AssetCategoryDto
{
Id = BookingTestConsts.AssetCategory1Id,
DisplayName = "Cameras"
});
var productDetailAppService = Substitute.For<IProductDetailAppService>();
services.AddTransient(_ => productDetailAppService);
var orderRepository = Substitute.For<IOrderRepository>();
services.AddTransient(_ => orderRepository);
orderRepository.InsertAsync(null).ReturnsNullForAnyArgs();
}
}

20
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<IBookingProductGroupDefinitionAppService>();
var productGroupNames = (await definitionAppService.GetListAsync()).Items.Select(x => x.ProductGroupName);
productGroupNames.ShouldContain(BookingTestConsts.BookingProductGroupName);
}
}

4
plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Application.Tests/EasyAbp.EShop.Plugins.Booking.Application.Tests.csproj

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>EasyAbp.EShop.Plugins.Booking</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\EasyAbp.EShop.Orders.Booking.Application\EasyAbp.EShop.Orders.Booking.Application.csproj" />
<ProjectReference Include="..\..\src\EasyAbp.EShop.Payments.Booking.Application\EasyAbp.EShop.Payments.Booking.Application.csproj" />
<ProjectReference Include="..\..\src\EasyAbp.EShop.Plugins.Booking.Application\EasyAbp.EShop.Plugins.Booking.Application.csproj" />
<ProjectReference Include="..\EasyAbp.EShop.Plugins.Booking.Domain.Tests\EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />

66
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<IOrderAppService>();
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<CreateOrderLineDto>
{
orderLine1, orderLine2
}
});
order.ActualTotalPrice.ShouldBe(15m);
}
}

2
plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.Domain.Tests/EasyAbp.EShop.Plugins.Booking.Domain.Tests.csproj

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>EasyAbp.EShop.Plugins.Booking</RootNamespace>

2
plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests/EasyAbp.EShop.Plugins.Booking.EntityFrameworkCore.Tests.csproj

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>EasyAbp.EShop.Plugins.Booking</RootNamespace>

2
plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests/EasyAbp.EShop.Plugins.Booking.MongoDB.Tests.csproj

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>EasyAbp.EShop.Plugins.Booking</RootNamespace>

54
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));
}
}
}

13
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<EShopBookingOptions>(options =>
{
options.BookingProductGroups.Add(
new BookingProductGroupDefinition(BookingTestConsts.BookingProductGroupName));
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -38,4 +45,4 @@ public class BookingTestBaseModule : AbpModule
}
});
}
}
}

36
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;
}

2
plugins/Booking/test/EasyAbp.EShop.Plugins.Booking.TestBase/EasyAbp.EShop.Plugins.Booking.TestBase.csproj

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>EasyAbp.EShop.Plugins.Booking</RootNamespace>

Loading…
Cancel
Save