build: 升级目标框架到net10.0并完善模板配置
1. 将Hua.Cli.Tests、项目共享库、模块项目等所有项目的TargetFramework从net8.0/net9.0升级到net10.0 2. 完善dotnet-tools.json、模板配置文件,添加必要的构建和发布配置 3. 新增微服务、网关、应用程序的启动脚本和基础配置文件 4. 补充产品管理模块的领域、应用、Web层基础代码和多语言资源
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ProductManagement.Application\ProductManagement.Application.csproj" />
|
||||
<ProjectReference Include="..\ProductManagement.Domain.Tests\ProductManagement.Domain.Tests.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Xunit;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public class ProductAppService_Tests : ProductManagementApplicationTestBase
|
||||
{
|
||||
private readonly IProductAppService _productAppService;
|
||||
private readonly IRepository<Product, Guid> _productRepository;
|
||||
private readonly ProductManagementTestData _testData;
|
||||
|
||||
public ProductAppService_Tests()
|
||||
{
|
||||
_productAppService = GetRequiredService<IProductAppService>();
|
||||
_productRepository = GetRequiredService<IRepository<Product, Guid>>();
|
||||
_testData = GetRequiredService<ProductManagementTestData>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetListPagedAsync()
|
||||
{
|
||||
var result = await _productAppService.GetListPagedAsync(new PagedAndSortedResultRequestDto());
|
||||
|
||||
result.Items.Count.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetListAsync()
|
||||
{
|
||||
var result = await _productAppService.GetListAsync();
|
||||
|
||||
result.Items.Count.ShouldBeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync()
|
||||
{
|
||||
var product = (await _productRepository.GetListAsync()).FirstOrDefault();
|
||||
|
||||
var result = await _productAppService.GetAsync(product.Id);
|
||||
|
||||
result.ShouldNotBeNull();
|
||||
result.Name.ShouldBe(_testData.ProductName1);
|
||||
result.Code.ShouldBe(_testData.ProductCode1);
|
||||
result.Price.ShouldBe(_testData.ProductPrice1);
|
||||
result.StockCount.ShouldBe(_testData.ProductStockCount1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync()
|
||||
{
|
||||
var result = await _productAppService.CreateAsync(new CreateProductDto()
|
||||
{
|
||||
Code = "Code",
|
||||
Name = "Name",
|
||||
Price = 15,
|
||||
StockCount = 14
|
||||
});
|
||||
|
||||
result.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync()
|
||||
{
|
||||
var product = (await _productRepository.GetListAsync()).FirstOrDefault();
|
||||
|
||||
var result = await _productAppService.UpdateAsync(product.Id, new UpdateProductDto()
|
||||
{
|
||||
Name = nameof(Product.Name),
|
||||
Price = 15,
|
||||
StockCount = 14
|
||||
});
|
||||
|
||||
result.ShouldNotBeNull();
|
||||
result.Name.ShouldBe(nameof(Product.Name));
|
||||
result.Price.ShouldBe(15);
|
||||
result.StockCount.ShouldBe(14);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync()
|
||||
{
|
||||
var product = (await _productRepository.GetListAsync()).LastOrDefault();
|
||||
|
||||
await _productAppService.DeleteAsync(product.Id);
|
||||
|
||||
var result = await _productRepository.FindAsync(product.Id);
|
||||
|
||||
result.ShouldBeNull();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using ProductManagement.EntityFrameworkCore;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public abstract class ProductManagementApplicationTestBase : ProductManagementTestBase<ProductManagementApplicationTestModule>
|
||||
{
|
||||
protected virtual void UsingDbContext(Action<IProductManagementDbContext> action)
|
||||
{
|
||||
using (var dbContext = GetRequiredService<IProductManagementDbContext>())
|
||||
{
|
||||
action.Invoke(dbContext);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual T UsingDbContext<T>(Func<IProductManagementDbContext, T> action)
|
||||
{
|
||||
using (var dbContext = GetRequiredService<IProductManagementDbContext>())
|
||||
{
|
||||
return action.Invoke(dbContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(ProductManagementApplicationModule),
|
||||
typeof(ProductManagementDomainTestModule)
|
||||
)]
|
||||
public class ProductManagementApplicationTestModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddAlwaysAllowAuthorization();
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProductManagement.EntityFrameworkCore.Tests\ProductManagement.EntityFrameworkCore.Tests.csproj" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public abstract class ProductManagementDomainTestBase : ProductManagementTestBase<ProductManagementDomainTestModule>
|
||||
{
|
||||
#region WithUnitOfWork
|
||||
|
||||
protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
await action();
|
||||
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
var result = await func();
|
||||
await uow.CompleteAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using ProductManagement.EntityFrameworkCore;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(ProductManagementEntityFrameworkCoreTestModule)
|
||||
)]
|
||||
public class ProductManagementDomainTestModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public class ProductManager_Tests : ProductManagementDomainTestBase
|
||||
{
|
||||
private readonly ProductManager _productManager;
|
||||
|
||||
public ProductManager_Tests()
|
||||
{
|
||||
_productManager = GetRequiredService<ProductManager>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Create_A_Valid_Product()
|
||||
{
|
||||
//Act
|
||||
var product = await WithUnitOfWorkAsync(
|
||||
async () =>
|
||||
{
|
||||
return await _productManager.CreateAsync("P000837212", "My Product 837212", stockCount: 42);
|
||||
}
|
||||
);
|
||||
|
||||
//Assert
|
||||
product.Code.ShouldBe("P000837212");
|
||||
product.Name.ShouldBe("My Product 837212");
|
||||
product.Price.ShouldBe(0.0f);
|
||||
product.StockCount.ShouldBe(42);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ProductManagement.EntityFrameworkCore\ProductManagement.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\ProductManagement.TestBase\ProductManagement.TestBase.csproj" />
|
||||
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore.Sqlite;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace ProductManagement.EntityFrameworkCore
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(ProductManagementTestBaseModule),
|
||||
typeof(ProductManagementEntityFrameworkCoreModule),
|
||||
typeof(AbpEntityFrameworkCoreSqliteModule)
|
||||
)]
|
||||
public class ProductManagementEntityFrameworkCoreTestModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var sqliteConnection = CreateDatabaseAndGetConnection();
|
||||
|
||||
Configure<AbpDbContextOptions>(options =>
|
||||
{
|
||||
options.Configure(abpDbContextConfigurationContext =>
|
||||
{
|
||||
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static SqliteConnection CreateDatabaseAndGetConnection()
|
||||
{
|
||||
var connection = new SqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
|
||||
new ProductManagementDbContext(
|
||||
new DbContextOptionsBuilder<ProductManagementDbContext>().UseSqlite(connection).Options
|
||||
).GetService<IRelationalDatabaseCreator>().CreateTables();
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Authorization" Version="9.0.0" />
|
||||
<PackageReference Include="Volo.Abp.TestBase" Version="9.0.0" />
|
||||
<ProjectReference Include="..\..\src\ProductManagement.Domain\ProductManagement.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="Shouldly" Version="3.0.2" />
|
||||
<PackageReference Include="xunit" Version="2.6.0" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Testing;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public abstract class ProductManagementTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
|
||||
{
|
||||
options.UseAutofac();
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Authorization;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpTestBaseModule),
|
||||
typeof(AbpAuthorizationModule),
|
||||
typeof(ProductManagementDomainModule)
|
||||
)]
|
||||
public class ProductManagementTestBaseModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddAlwaysAllowAuthorization();
|
||||
|
||||
Configure<AbpUnitOfWorkDefaultOptions>(options =>
|
||||
{
|
||||
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled;
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
SeedTestData(context);
|
||||
}
|
||||
|
||||
private static void SeedTestData(ApplicationInitializationContext context)
|
||||
{
|
||||
using (var scope = context.ServiceProvider.CreateScope())
|
||||
{
|
||||
scope.ServiceProvider
|
||||
.GetRequiredService<ProductManagementTestDataBuilder>()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public class ProductManagementTestData : ISingletonDependency
|
||||
{
|
||||
public string ProductCode1 { get; } = "ProductCode1";
|
||||
|
||||
public string ProductName1 { get; } = "ProductName1";
|
||||
|
||||
public float ProductPrice1 { get; } = 20;
|
||||
|
||||
public int ProductStockCount1 { get; } = 100;
|
||||
|
||||
public string ProductCode2 { get; } = "ProductCode2";
|
||||
|
||||
public string ProductName2 { get; } = "ProductName2";
|
||||
|
||||
public float ProductPrice2 { get; } = 30;
|
||||
|
||||
public int ProductStockCount2 { get; } = 110;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Threading;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace ProductManagement
|
||||
{
|
||||
public class ProductManagementTestDataBuilder : ITransientDependency
|
||||
{
|
||||
private ProductManagementTestData _testData;
|
||||
private readonly ProductManager _productManager;
|
||||
|
||||
public ProductManagementTestDataBuilder(
|
||||
ProductManagementTestData testData,
|
||||
ProductManager productManager)
|
||||
{
|
||||
_testData = testData;
|
||||
_productManager = productManager;
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
AsyncHelper.RunSync(BuildAsync);
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public virtual async Task BuildAsync()
|
||||
{
|
||||
await _productManager.CreateAsync(_testData.ProductCode1, _testData.ProductName1, _testData.ProductPrice1, _testData.ProductStockCount1);
|
||||
await _productManager.CreateAsync(_testData.ProductCode2, _testData.ProductName2, _testData.ProductPrice2, _testData.ProductStockCount2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user