添加项目文件。
This commit is contained in:
35
Hua.DDNS.Test/AppJobTest.cs
Normal file
35
Hua.DDNS.Test/AppJobTest.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Hua.DDNS.Jobs;
|
||||
using Hua.DDNS.Test.Start;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
|
||||
namespace Hua.DDNS.Test
|
||||
{
|
||||
public class AppJobTest
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("appsetting.Ali.json")]
|
||||
[InlineData("appsetting.Tencent.json")]
|
||||
public void UpdateDNS(string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile(configPath, true)
|
||||
.AddEnvironmentVariables()// <20>ѻ<EFBFBD><D1BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD>ŵ<EFBFBD> Configuraiton<6F><6E><EFBFBD><EFBFBD>
|
||||
.Build();
|
||||
|
||||
var sc = DIConfig.ConfigureServices(config);
|
||||
var job = sc.GetService<AppJob>();
|
||||
|
||||
job?.Execute(null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.False(false, $"<22><><EFBFBD><EFBFBD><EFBFBD>쳣:{e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Hua.DDNS.Test/Hua.DDNS.Test.csproj
Normal file
37
Hua.DDNS.Test/Hua.DDNS.Test.csproj
Normal file
@@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hua.DDNS\Hua.DDNS.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.Ali.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.Tencent.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
48
Hua.DDNS.Test/Start/DIConfig.cs
Normal file
48
Hua.DDNS.Test/Start/DIConfig.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hua.DDNS.Common.Config;
|
||||
using Hua.DDNS.Common.Http;
|
||||
using Hua.DDNS.Common;
|
||||
using Hua.DDNS.Jobs;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace Hua.DDNS.Test.Start
|
||||
{
|
||||
public class DIConfig
|
||||
{
|
||||
public static IServiceProvider ConfigureServices(IConfiguration configuration)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File(
|
||||
Path.Combine("Log\\log-.log"),
|
||||
rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IConfiguration>(configuration);
|
||||
services.AddLogging(loggingBuilder =>
|
||||
{
|
||||
loggingBuilder.AddConfiguration(configuration.GetSection("Logging")); //配置logging的一些东西
|
||||
// 下面的这行需要 Microsoft.Extensions.Logging.Console
|
||||
loggingBuilder.AddConsole(); //加多个 每一个Ilooger下面就会有多个provider
|
||||
});
|
||||
|
||||
// 注入了一个默认的ILogger
|
||||
services.AddSingleton<SettingProvider>();
|
||||
//services.AddSingleton<SyncECMFileProvider>();
|
||||
services.AddSingleton<Url>();
|
||||
services.AddSingleton<SqlHelper>();
|
||||
services.AddTransient<IHttpHelper, HttpHelper>();
|
||||
services.AddTransient<AppJob>();
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Hua.DDNS.Test/Usings.cs
Normal file
1
Hua.DDNS.Test/Usings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
32
Hua.DDNS.Test/appsettings.Ali.json
Normal file
32
Hua.DDNS.Test/appsettings.Ali.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"pgConnection": "Host=127.0.0.1;Port=5432;Database=Worker;Username=Worker;Password=123456;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"App": {
|
||||
"AppJob": {
|
||||
"Corn": "* * * * * ?" //https://cron.qqe2.com/
|
||||
},
|
||||
|
||||
"Domain": {
|
||||
"Platform": "Ali",
|
||||
// 阿里云的 Access Id
|
||||
"Id": "AliId",
|
||||
// 阿里云的 Access Key
|
||||
"Key": "AliKey",
|
||||
// 主域名
|
||||
"domain": "demoDomain.cn",
|
||||
// 子域名前缀
|
||||
"subDomainArray": [ "bjb", "git" ],
|
||||
// 记录类型
|
||||
"type": "A",
|
||||
//间隔时间 秒
|
||||
"time": "30"
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Hua.DDNS.Test/appsettings.Tencent.json
Normal file
32
Hua.DDNS.Test/appsettings.Tencent.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"pgConnection": "Host=127.0.0.1;Port=5432;Database=Worker;Username=Worker;Password=123456;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"App": {
|
||||
"AppJob": {
|
||||
"Corn": "* * * * * ?" //https://cron.qqe2.com/
|
||||
},
|
||||
|
||||
"Domain": {
|
||||
"Platform": "Tencent",
|
||||
// 阿里云的 Access Id
|
||||
"Id": "Id",
|
||||
// 阿里云的 Access Key
|
||||
"Key": "Key",
|
||||
// 主域名
|
||||
"domain": "demoDomain.cn",
|
||||
// 子域名前缀
|
||||
"subDomainArray": [ "bjb", "git" ],
|
||||
// 记录类型
|
||||
"type": "A",
|
||||
//间隔时间 秒
|
||||
"time": "30"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user