|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Senparc.CO2NET;
|
|
|
|
|
using Senparc.CO2NET.RegisterServices;
|
|
|
|
|
using Senparc.Weixin.Entities;
|
|
|
|
|
using Senparc.Weixin.RegisterServices;
|
|
|
|
|
using Senparc.WeixinTests;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Senparc.Weixin.TenPayV3.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class BaseTenPayTest
|
|
|
|
|
{
|
|
|
|
|
protected static IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
protected static SenparcSetting _senparcSetting;
|
|
|
|
|
protected static SenparcWeixinSetting _senparcWeixinSetting;
|
|
|
|
|
|
|
|
|
|
public BaseTenPayTest()
|
|
|
|
|
{
|
|
|
|
|
//Senparc.Weixin.Config.UseSandBoxPay = true;
|
|
|
|
|
RegisterStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected void RegisterStart()
|
|
|
|
|
{
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);//֧<><D6A7> GB2312
|
|
|
|
|
|
|
|
|
|
//ע<>Ὺʼ
|
|
|
|
|
RegisterService register;
|
|
|
|
|
|
|
|
|
|
//ע<><D7A2> CON2ET ȫ<><C8AB>
|
|
|
|
|
var senparcSetting = new SenparcSetting() { IsDebug = true };
|
|
|
|
|
|
|
|
|
|
var mockEnv = new Mock<IHostEnvironment>();
|
|
|
|
|
|
|
|
|
|
mockEnv.Setup(z => z.ContentRootPath).Returns(() => UnitTestHelper.RootPath);
|
|
|
|
|
register = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object, senparcSetting);
|
|
|
|
|
|
|
|
|
|
RegisterServiceCollection();
|
|
|
|
|
|
|
|
|
|
register.UseSenparcGlobal(false);
|
|
|
|
|
|
|
|
|
|
//ע<><D7A2><EFBFBD><CEA2>
|
|
|
|
|
//var senparcWeixinSetting = new SenparcWeixinSetting(true);
|
|
|
|
|
register.UseSenparcWeixin(_senparcWeixinSetting, senparcSetting).RegisterTenpayApiV3(_senparcWeixinSetting, "<><CEA2> V3");
|
|
|
|
|
register.ChangeDefaultCacheNamespace("Senparc.Weixin Test Cache");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ע<><D7A2> IServiceCollection <20><> MemoryCache
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void RegisterServiceCollection()
|
|
|
|
|
{
|
|
|
|
|
var serviceCollection = new ServiceCollection();
|
|
|
|
|
var configBuilder = new ConfigurationBuilder();
|
|
|
|
|
|
|
|
|
|
var appSettingsTestFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, UnitTestHelper.RootPath, "appsettings.Test.json"));
|
|
|
|
|
var appSettingsFileExisted = File.Exists(appSettingsTestFilePath);
|
|
|
|
|
|
|
|
|
|
if (appSettingsFileExisted)
|
|
|
|
|
{
|
|
|
|
|
configBuilder.AddJsonFile("appsettings.Test.json", false, false);//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ܰ<EFBFBD><DCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(appSettingsTestFilePath.Replace(".Test", "")))
|
|
|
|
|
{
|
|
|
|
|
configBuilder.AddJsonFile("appsettings.json", false, false);//Ĭ<><C4AC>ʹ<EFBFBD><CAB9> appsettings.json
|
|
|
|
|
appSettingsFileExisted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var config = configBuilder.Build();
|
|
|
|
|
|
|
|
|
|
_senparcSetting = new SenparcSetting() { IsDebug = true };
|
|
|
|
|
_senparcWeixinSetting = new SenparcWeixinSetting() { IsDebug = true };
|
|
|
|
|
|
|
|
|
|
if (appSettingsFileExisted)
|
|
|
|
|
{
|
|
|
|
|
config.GetSection("SenparcSetting").Bind(_senparcSetting);
|
|
|
|
|
config.GetSection("SenparcWeixinSetting").Bind(_senparcWeixinSetting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serviceCollection.AddMemoryCache();//ʹ<><CAB9><EFBFBD>ڴ滺<DAB4><E6BBBA>
|
|
|
|
|
|
|
|
|
|
//<2F>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> AddSenparcGlobalServices()<29><>ע<EFBFBD>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD>ִ<EFBFBD><D6B4>
|
|
|
|
|
serviceCollection.AddSenparcWeixinServices(config);
|
|
|
|
|
|
|
|
|
|
_serviceProvider = serviceCollection.BuildServiceProvider();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|