@@ -7,6 +7,7 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.0" /> | |||
<PackageReference Include="BPA.SaaS.Basic.Api.SDK" Version="1.0.1" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" /> | |||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> | |||
@@ -9,6 +9,8 @@ using BPA.Component.LogClient.Extensions; | |||
using BPA.Component.SDKCommon; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.SaaS.Stock.Api.Model; | |||
using BPA.SaaS.Stock.Api.Repository.Product; | |||
using BPA.SaaS.Stock.Api.Service.Product; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | |||
using Microsoft.AspNetCore.Http; | |||
@@ -91,15 +93,15 @@ public static class SetupBootstrap | |||
// 注入DB | |||
builder.RegisterType<StockDbSugarClient>().InstancePerLifetimeScope(); | |||
// // 服务层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeService).Assembly) | |||
// .Where(t => t.Name.EndsWith("Service")) | |||
// .AsImplementedInterfaces(); | |||
// | |||
// // 仓储层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeRepository).Assembly) | |||
// .Where(t => t.Name.EndsWith("Repository")) | |||
// .AsImplementedInterfaces(); | |||
// 服务层 | |||
builder.RegisterAssemblyTypes(typeof(ProductService).Assembly) | |||
.Where(t => t.Name.EndsWith("Service")) | |||
.AsImplementedInterfaces(); | |||
// 仓储层 | |||
builder.RegisterAssemblyTypes(typeof(ProductRepository).Assembly) | |||
.Where(t => t.Name.EndsWith("Repository")) | |||
.AsImplementedInterfaces(); | |||
return builder; | |||
} | |||
@@ -1,5 +1,6 @@ | |||
using BPA.Component.DTOCommon.Langs; | |||
using BPA.Component.SDKCommon; | |||
using BPA.SaaS.Basic.Api.SDK; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
@@ -28,7 +29,7 @@ public static class SetupServiceSDK | |||
{ | |||
case "Development": | |||
// 开发本地连集群 | |||
// services.AddApiSDK<WebApi2SDK>(_ => "http://[IP]:[port]"); | |||
services.AddApiSDK<BasicWebApiSDK>(_ => "http://localhost:5047"); | |||
// 开发集群环境内 | |||
// services.UseApiSDK<WebApi2SDK>(_ => "http://serviceName"); | |||
break; | |||
@@ -1,10 +1,10 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<VersionPrefix>1.0.1</VersionPrefix> | |||
<VersionPrefix>1.0.2</VersionPrefix> | |||
<PackageReleaseNotes /> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
@@ -1,14 +1,17 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.SaaS.Stock.Api.DTO" Version="1.0.1" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<VersionPrefix>1.0.1</VersionPrefix> | |||
<PackageReleaseNotes /> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.SaaS.Basic.Api.SDK" Version="1.0.1" /> | |||
<PackageReference Include="BPA.SaaS.Stock.Api.DTO" Version="1.0.2" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.SDKCommon" Version="1.0.3" /> | |||
<PackageReference Include="Nuget.Tools.V2" Version="1.1.7" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,18 @@ | |||
using BPA.Component.DTOCommon.BaseDTOs; | |||
using BPA.SaaS.Stock.Api.DTO; | |||
using BPA.SaaS.Stock.Api.DTO.Product; | |||
using Refit; | |||
namespace BPA.SaaS.Stock.Api.SDK; | |||
public interface IProductCodeServiceApi | |||
{ | |||
/// <summary> | |||
/// 获取产品Code列表 | |||
/// </summary> | |||
/// <param name="dto"></param> | |||
/// <param name="authToken"></param> | |||
/// <returns></returns> | |||
[Post("/api/productcode/getproductlist")] | |||
Task<BaseResultPage<ProductCodeDto>> GetProductList(ProductCodeListQuery dto, [Authorize] string authToken); | |||
} |
@@ -0,0 +1,41 @@ | |||
using BPA.Component.WebApiExtensions.SimpleJWT; | |||
using BPA.SaaS.Basic.Api.DTO; | |||
using BPA.SaaS.Basic.Api.DTO.InnerEnum; | |||
using BPA.SaaS.Basic.Api.SDK; | |||
namespace BPA.SaaS.Stock.Api.UnitTest; | |||
public class AuthBasicToken : BaseUnitTest | |||
{ | |||
private readonly BasicWebApiSDK _basicWebApiSDK; | |||
public AuthBasicToken() | |||
{ | |||
_basicWebApiSDK = GetService<BasicWebApiSDK>(); | |||
} | |||
public async Task<ClaimInfo> GetClaimInfo(string userName, string password) | |||
{ | |||
var result = await _basicWebApiSDK.AuthServiceApi.LoginAsync(EnumLoginType.FranchiseeUsers, new LoginInput | |||
{ | |||
Account = userName, | |||
Password = password, | |||
Name = "", | |||
RoleId = "", | |||
}); | |||
if (!result.IsOK) throw new Exception("登录失败"); | |||
var jsonToken = JWTEncryption.ReadJwtToken(result.Data.token); | |||
return new ClaimInfo | |||
{ | |||
UserId = jsonToken.Claims.First(f => f.Type == "UserId").Value, | |||
Account = jsonToken.Claims.First(f => f.Type == "Account").Value, | |||
Name = jsonToken.Claims.First(f => f.Type == "Name").Value, | |||
SuperAdmin = jsonToken.Claims.First(f => f.Type == "SuperAdmin").Value == "1", | |||
LoginType = Convert.ToInt32(jsonToken.Claims.First(f => f.Type == "LoginType").Value), | |||
GroupId = jsonToken.Claims.First(f => f.Type == "GroupId").Value, | |||
OrgId = jsonToken.Claims.FirstOrDefault(f => f.Type == "OrgId")?.Value | |||
}; | |||
} | |||
} |
@@ -1,7 +1,21 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.SaaS.Basic.Api.SDK" Version="1.0.1" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | |||
<PackageReference Include="MSTest.TestFramework" Version="2.2.9" /> | |||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.9" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.SaaS.Stock.Api.Bootstrap\BPA.SaaS.Stock.Api.Bootstrap.csproj" /> | |||
<ProjectReference Include="..\BPA.SaaS.Stock.Api.Service\BPA.SaaS.Stock.Api.Service.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,54 @@ | |||
using Autofac; | |||
using Autofac.Extensions.DependencyInjection; | |||
using BPA.Component.ApolloClient; | |||
using BPA.SaaS.Stock.Api.Bootstrap; | |||
using BPA.SaaS.Stock.Api.Model; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.Stock.Api.UnitTest | |||
{ | |||
/// <summary> | |||
/// 测试基类 | |||
/// </summary> | |||
public class BaseUnitTest | |||
{ | |||
#pragma warning disable CS8618 | |||
private static ILifetimeScope lifetimeScope; | |||
#pragma warning restore CS8618 | |||
public BaseUnitTest() | |||
{ | |||
var builder = new ConfigurationBuilder(); | |||
builder.AddEnvironmentVariables(); | |||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development"); | |||
Environment.SetEnvironmentVariable("APOLLO_META_SERVER_URL", "http://10.2.1.21:28080"); | |||
Environment.SetEnvironmentVariable("APOLLO_COMMON_NAMESPACE", "DEV.Common"); | |||
Environment.SetEnvironmentVariable("APP_NAME", "BPA.SaaS.Basic.Api"); | |||
var configuration = builder.Build(); | |||
configuration.SetupConfiguration(); | |||
var services = new ServiceCollection(); | |||
services.AddApollo<StockApiConfig>(); | |||
services.AddBPAMiddlewareServices(new[] {"null arg"}); | |||
services.AddSingleton<AuthBasicToken>(); | |||
services.AddServiceSDK(configuration); | |||
var factory = new AutofacServiceProviderFactory(); | |||
var containerBuild = factory.CreateBuilder(services); | |||
containerBuild.SetupConfigureContainer(); | |||
containerBuild.RegisterBuildCallback(scope => lifetimeScope = scope); | |||
var serviceProvider = factory.CreateServiceProvider(containerBuild); | |||
serviceProvider.PreHeatRun(); | |||
// var db = serviceProvider.CreateScope().ServiceProvider.GetService<BasicDbSugarClient>(); | |||
} | |||
/// <summary> | |||
/// 从容器中获取对象 | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <returns></returns> | |||
protected static T GetService<T>() where T : notnull => lifetimeScope.Resolve<T>(); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
using BPA.Component.WebApiExtensions; | |||
using BPA.SaaS.Stock.Api.DTO; | |||
using BPA.SaaS.Stock.Api.IService.Product; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
namespace BPA.SaaS.Stock.Api.UnitTest.Products; | |||
[TestClass] | |||
public class ProductCodeServiceTests : BaseUnitTest | |||
{ | |||
private readonly IProductCodeService _productCode; | |||
private readonly AuthBasicToken _authBasicToken; | |||
public ProductCodeServiceTests() | |||
{ | |||
_productCode = GetService<IProductCodeService>(); | |||
_authBasicToken = GetService<AuthBasicToken>(); | |||
} | |||
[TestMethod] | |||
public void TestRemoteAuthToken() | |||
{ | |||
var claimInfo = _authBasicToken.GetClaimInfo("admin", "admin").Result; // 远程获取登录凭证 | |||
Assert.IsTrue(claimInfo != null); | |||
} | |||
[TestMethod] | |||
public void TestGetProductList() | |||
{ | |||
var list = _productCode.GetProductList(new ProductCodeListQuery {PageSize = 100, Current = 0}).Result; | |||
Assert.IsTrue(list.IsOK); | |||
Assert.IsTrue(list.Data.Rows.Count >= 0); | |||
} | |||
} |