diff --git a/src/BPA.SaaS.Stock.Api.Bootstrap/BPA.SaaS.Stock.Api.Bootstrap.csproj b/src/BPA.SaaS.Stock.Api.Bootstrap/BPA.SaaS.Stock.Api.Bootstrap.csproj index daefc51..f60b6d8 100644 --- a/src/BPA.SaaS.Stock.Api.Bootstrap/BPA.SaaS.Stock.Api.Bootstrap.csproj +++ b/src/BPA.SaaS.Stock.Api.Bootstrap/BPA.SaaS.Stock.Api.Bootstrap.csproj @@ -7,6 +7,7 @@ + diff --git a/src/BPA.SaaS.Stock.Api.Bootstrap/SetupBootstrap.cs b/src/BPA.SaaS.Stock.Api.Bootstrap/SetupBootstrap.cs index e96ef28..063c427 100644 --- a/src/BPA.SaaS.Stock.Api.Bootstrap/SetupBootstrap.cs +++ b/src/BPA.SaaS.Stock.Api.Bootstrap/SetupBootstrap.cs @@ -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().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; } diff --git a/src/BPA.SaaS.Stock.Api.Bootstrap/SetupServiceSDK.cs b/src/BPA.SaaS.Stock.Api.Bootstrap/SetupServiceSDK.cs index b6f08a3..96f6a8f 100644 --- a/src/BPA.SaaS.Stock.Api.Bootstrap/SetupServiceSDK.cs +++ b/src/BPA.SaaS.Stock.Api.Bootstrap/SetupServiceSDK.cs @@ -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(_ => "http://[IP]:[port]"); + services.AddApiSDK(_ => "http://localhost:5047"); // 开发集群环境内 // services.UseApiSDK(_ => "http://serviceName"); break; diff --git a/src/BPA.SaaS.Stock.Api.DTO/BPA.SaaS.Stock.Api.DTO.csproj b/src/BPA.SaaS.Stock.Api.DTO/BPA.SaaS.Stock.Api.DTO.csproj index ecdc789..03a6264 100644 --- a/src/BPA.SaaS.Stock.Api.DTO/BPA.SaaS.Stock.Api.DTO.csproj +++ b/src/BPA.SaaS.Stock.Api.DTO/BPA.SaaS.Stock.Api.DTO.csproj @@ -1,10 +1,10 @@ - + net6.0 enable enable - 1.0.1 + 1.0.2 diff --git a/src/BPA.SaaS.Stock.Api.SDK/BPA.SaaS.Stock.Api.SDK.csproj b/src/BPA.SaaS.Stock.Api.SDK/BPA.SaaS.Stock.Api.SDK.csproj index 619e007..f2da8bf 100644 --- a/src/BPA.SaaS.Stock.Api.SDK/BPA.SaaS.Stock.Api.SDK.csproj +++ b/src/BPA.SaaS.Stock.Api.SDK/BPA.SaaS.Stock.Api.SDK.csproj @@ -1,14 +1,17 @@  - - net6.0 - enable - enable - - - - - - - + + net6.0 + enable + enable + 1.0.1 + + + + + + + + + \ No newline at end of file diff --git a/src/BPA.SaaS.Stock.Api.SDK/IProductCodeServiceApi.cs b/src/BPA.SaaS.Stock.Api.SDK/IProductCodeServiceApi.cs new file mode 100644 index 0000000..1e5d2a0 --- /dev/null +++ b/src/BPA.SaaS.Stock.Api.SDK/IProductCodeServiceApi.cs @@ -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 +{ + /// + /// 获取产品Code列表 + /// + /// + /// + /// + [Post("/api/productcode/getproductlist")] + Task> GetProductList(ProductCodeListQuery dto, [Authorize] string authToken); +} \ No newline at end of file diff --git a/src/BPA.SaaS.Stock.Api.UnitTest/AuthBasicToken.cs b/src/BPA.SaaS.Stock.Api.UnitTest/AuthBasicToken.cs new file mode 100644 index 0000000..ff1d498 --- /dev/null +++ b/src/BPA.SaaS.Stock.Api.UnitTest/AuthBasicToken.cs @@ -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(); + } + + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/src/BPA.SaaS.Stock.Api.UnitTest/BPA.SaaS.Stock.Api.UnitTest.csproj b/src/BPA.SaaS.Stock.Api.UnitTest/BPA.SaaS.Stock.Api.UnitTest.csproj index e1015fb..be441ad 100644 --- a/src/BPA.SaaS.Stock.Api.UnitTest/BPA.SaaS.Stock.Api.UnitTest.csproj +++ b/src/BPA.SaaS.Stock.Api.UnitTest/BPA.SaaS.Stock.Api.UnitTest.csproj @@ -1,7 +1,21 @@ - - -net6.0 -enable -enable - + + + net6.0 + enable + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/BPA.SaaS.Stock.Api.UnitTest/BaseUnitTest.cs b/src/BPA.SaaS.Stock.Api.UnitTest/BaseUnitTest.cs new file mode 100644 index 0000000..62ba3aa --- /dev/null +++ b/src/BPA.SaaS.Stock.Api.UnitTest/BaseUnitTest.cs @@ -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 +{ + /// + /// 测试基类 + /// + 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(); + services.AddBPAMiddlewareServices(new[] {"null arg"}); + services.AddSingleton(); + 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(); + } + + /// + /// 从容器中获取对象 + /// + /// + /// + protected static T GetService() where T : notnull => lifetimeScope.Resolve(); + } +} \ No newline at end of file diff --git a/src/BPA.SaaS.Stock.Api.UnitTest/Products/ProductCodeServiceTests.cs b/src/BPA.SaaS.Stock.Api.UnitTest/Products/ProductCodeServiceTests.cs new file mode 100644 index 0000000..ff55198 --- /dev/null +++ b/src/BPA.SaaS.Stock.Api.UnitTest/Products/ProductCodeServiceTests.cs @@ -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(); + _authBasicToken = GetService(); + } + + [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); + } +} \ No newline at end of file