pull file
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
This commit is contained in:
23
test/AppServiceTest/AppServiceTest.csproj
Normal file
23
test/AppServiceTest/AppServiceTest.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
22
test/AppServiceTest/DailyTask/DonateCoinsTest.cs
Normal file
22
test/AppServiceTest/DailyTask/DonateCoinsTest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Application.Contracts;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
|
||||
namespace AppServiceTest.DailyTask
|
||||
{
|
||||
public class DonateCoinsTest
|
||||
{
|
||||
public DonateCoinsTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var appService = scope.ServiceProvider.GetRequiredService<IDailyTaskAppService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
test/AppServiceTest/Usings.cs
Normal file
2
test/AppServiceTest/Usings.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
global using Ray.BiliBiliTool.Console;
|
||||
global using Xunit;
|
||||
34
test/AppServiceTest/VipServiceTest.cs
Normal file
34
test/AppServiceTest/VipServiceTest.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.VipTask;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Application.Contracts;
|
||||
using Ray.BiliBiliTool.DomainService.Dtos;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
|
||||
namespace AppServiceTest;
|
||||
|
||||
public class VipServiceTest
|
||||
{
|
||||
public VipServiceTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteV2Test()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IVipBigPointApi>();
|
||||
var res = await api.CompleteV2(new ReceiveOrCompleteTaskRequest("dress-view"), null);
|
||||
Assert.True(res.Code == 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReceiveV2Test()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IVipBigPointApi>();
|
||||
var res = await api.ReceiveV2(new ReceiveOrCompleteTaskRequest("ogvwatchnew"), null);
|
||||
Assert.True(res.Code == 0);
|
||||
}
|
||||
}
|
||||
23
test/BiliAgentTest/BiliAgentTest.csproj
Normal file
23
test/BiliAgentTest/BiliAgentTest.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>a6e5b261-0fe9-49e1-82e1-02349db119b4</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
37
test/BiliAgentTest/LiveTraceApiTest.cs
Normal file
37
test/BiliAgentTest/LiveTraceApiTest.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ray.BiliBiliTool.Agent;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Live;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.BiliBiliTool.Infrastructure.Cookie;
|
||||
using Xunit;
|
||||
|
||||
namespace BiliAgentTest
|
||||
{
|
||||
public class LiveTraceApiTest
|
||||
{
|
||||
public LiveTraceApiTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebHeartBeat_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveTraceApi>();
|
||||
|
||||
var request = new WebHeartBeatRequest(63666, 60);
|
||||
|
||||
var re = api.WebHeartBeat(request, null).Result;
|
||||
|
||||
Assert.Equal(0, re.Code);
|
||||
Assert.Equal("0", re.Message);
|
||||
Assert.Equal(60, re.Data.Next_interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
test/BiliAgentTest/VideoApiTest.cs
Normal file
64
test/BiliAgentTest/VideoApiTest.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ray.BiliBiliTool.Agent;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.BiliBiliTool.Infrastructure.Cookie;
|
||||
using Xunit;
|
||||
|
||||
namespace BiliAgentTest;
|
||||
|
||||
public class VideoApiTest
|
||||
{
|
||||
public VideoApiTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLiveWalletStatus_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IVideoApi>();
|
||||
|
||||
var req = new GetAlreadyDonatedCoinsRequest(248097491);
|
||||
BiliApiResponse<DonatedCoinsForVideo>? re = api.GetDonatedCoinsForVideo(req, null).Result;
|
||||
|
||||
if (ck.Count > 0)
|
||||
{
|
||||
Assert.True(re.Code == 0 && re.Data.Multiply >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(re.Code != 0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBangumiTest()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IVideoApi>();
|
||||
var req = await api.GetBangumiBySsid(46508, null);
|
||||
|
||||
Assert.Equal(0, req.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRandomVideoOfRanking()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IVideoWithoutCookieApi>();
|
||||
var req = await api.GetRegionRankingVideosV2();
|
||||
|
||||
Assert.Equal(0, req.Code);
|
||||
}
|
||||
}
|
||||
21
test/ConfigTest/ConfigTest.csproj
Normal file
21
test/ConfigTest/ConfigTest.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
35
test/ConfigTest/TestDefaultValue.cs
Normal file
35
test/ConfigTest/TestDefaultValue.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ray.BiliBiliTool.Config;
|
||||
using Ray.BiliBiliTool.Config.Options;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Xunit;
|
||||
|
||||
namespace ConfigTest
|
||||
{
|
||||
public class TestDefaultValue
|
||||
{
|
||||
public TestDefaultValue()
|
||||
{
|
||||
Program.CreateHost(null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var options = scope.ServiceProvider.GetRequiredService<
|
||||
IOptionsMonitor<DailyTaskOptions>
|
||||
>();
|
||||
var re = options.CurrentValue.NumberOfCoins;
|
||||
Debug.WriteLine(re);
|
||||
}
|
||||
}
|
||||
}
|
||||
175
test/ConfigTest/UnitTest1.cs
Normal file
175
test/ConfigTest/UnitTest1.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ray.BiliBiliTool.Agent;
|
||||
using Ray.BiliBiliTool.Config;
|
||||
using Ray.BiliBiliTool.Config.Options;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Xunit;
|
||||
|
||||
namespace ConfigTest
|
||||
{
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void WebProxyTest()
|
||||
{
|
||||
Program.CreateHost(new string[] { });
|
||||
string proxyAddress = Global.ConfigurationRoot["Security:WebProxy"];
|
||||
|
||||
if (!proxyAddress.IsNullOrEmpty())
|
||||
{
|
||||
WebProxy webProxy = new WebProxy();
|
||||
|
||||
//user:password@host:port http proxy only .Tested with tinyproxy-1.11.0-rc1
|
||||
if (proxyAddress.Contains("@"))
|
||||
{
|
||||
string userPass = proxyAddress.Split("@")[0];
|
||||
string address = proxyAddress.Split("@")[1];
|
||||
|
||||
string proxyUser = userPass.Split(":")[0];
|
||||
string proxyPass = userPass.Split(":")[1];
|
||||
|
||||
webProxy.Address = new Uri("http://" + address);
|
||||
webProxy.Credentials = new NetworkCredential(proxyUser, proxyPass);
|
||||
}
|
||||
else
|
||||
{
|
||||
webProxy.Address = new Uri(proxyAddress);
|
||||
}
|
||||
|
||||
HttpClient.DefaultProxy = webProxy;
|
||||
|
||||
HttpClient httpClient = new HttpClient();
|
||||
var response = httpClient.GetAsync("http://api.ipify.org/");
|
||||
var resultIp = response.Result.Content.ReadAsStringAsync().Result;
|
||||
Debug.WriteLine(String.Format("<22><>ǰIP<49><50> {0}", resultIp));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
Program.CreateHost(new string[] { });
|
||||
|
||||
string s = Global.ConfigurationRoot["BiliBiliCookie:UserId"];
|
||||
Debug.WriteLine(s);
|
||||
|
||||
string logLevel = Global.ConfigurationRoot[
|
||||
"Serilog:WriteTo:0:Args:restrictedToMinimumLevel"
|
||||
];
|
||||
Debug.WriteLine(logLevel);
|
||||
|
||||
var cookie = Global.ServiceProviderRoot.GetRequiredService<BiliCookie>();
|
||||
|
||||
Debug.WriteLine(
|
||||
JsonSerializer.Serialize(cookie, new JsonSerializerOptions { WriteIndented = true })
|
||||
);
|
||||
Assert.True(!string.IsNullOrWhiteSpace(cookie.UserId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Key<65>ķָ<C4B7><D6B8><EFBFBD>
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestEnvKeyDelimiter()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("Ray_BiliBiliCookie__UserId", "123");
|
||||
Program.CreateHost(null);
|
||||
|
||||
string result = Global.ConfigurationRoot["BiliBiliCookie:UserId"];
|
||||
|
||||
Assert.Equal("123", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadPrefixConfigByEnvWithNoError()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("Ray_BiliBiliCookie", "UserId: 123");
|
||||
Program.CreateHost(new string[] { });
|
||||
|
||||
string result = Global.ConfigurationRoot["BiliBiliCookie"];
|
||||
|
||||
Assert.Equal("UserId: 123", result);
|
||||
Environment.SetEnvironmentVariable("Ray_BiliBiliCookie", null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadPrefixConfigByEnvWhenValueIsNullWithNoError2()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("Ray_BiliBiliCookie", null);
|
||||
Program.CreateHost(new string[] { });
|
||||
|
||||
string result = Global.ConfigurationRoot["BiliBiliCookie"];
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CoverConfigByEnvWithNoError()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production");
|
||||
Program.CreateHost(new string[] { });
|
||||
|
||||
string result = Global.ConfigurationRoot["IsPrd"];
|
||||
|
||||
Assert.Equal("True", result);
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ֵ
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestSetConfiguration()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { });
|
||||
|
||||
var options = Global.ServiceProviderRoot.GetRequiredService<
|
||||
IOptionsMonitor<BiliBiliCookieOptions>
|
||||
>();
|
||||
Debug.WriteLine(options.CurrentValue.ToJsonStr());
|
||||
|
||||
//<2F>ֶ<EFBFBD><D6B6><EFBFBD>ֵ
|
||||
//RayConfiguration.Root["BiliBiliCookie:UserId"] = "123456";
|
||||
//options.CurrentValue.UserId = "123456";
|
||||
|
||||
Debug.WriteLine(
|
||||
$"<22><>Configuration<6F><6E>ȡ<EFBFBD><C8A1>{Global.ConfigurationRoot["BiliBiliCookie:UserId"]}"
|
||||
);
|
||||
|
||||
Debug.WriteLine($"<22><><EFBFBD><EFBFBD>options<6E><73>ȡ<EFBFBD><C8A1>{options.CurrentValue.ToJsonStr()}");
|
||||
|
||||
var optionsNew = Global.ServiceProviderRoot.GetRequiredService<
|
||||
IOptionsMonitor<BiliBiliCookieOptions>
|
||||
>();
|
||||
Debug.WriteLine($"<22><><EFBFBD><EFBFBD>options<6E><73>ȡ<EFBFBD><C8A1>{optionsNew.CurrentValue.ToJsonStr()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ֵ
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestHostDefaults()
|
||||
{
|
||||
Debug.WriteLine(Environment.GetEnvironmentVariable(HostDefaults.EnvironmentKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test()
|
||||
{
|
||||
var s = "0123456";
|
||||
|
||||
var s1 = s[..2];
|
||||
|
||||
var s2 = s[4..];
|
||||
}
|
||||
}
|
||||
}
|
||||
14
test/DomainServiceTest/ArticleDomainServiceTest.cs
Normal file
14
test/DomainServiceTest/ArticleDomainServiceTest.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace DomainServiceTest;
|
||||
|
||||
public class ArticleDomainServiceTest
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public ArticleDomainServiceTest(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
}
|
||||
52
test/DomainServiceTest/CalculateUpgradeTimeTest.cs
Normal file
52
test/DomainServiceTest/CalculateUpgradeTimeTest.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
|
||||
namespace DomainServiceTest;
|
||||
|
||||
public class CalculateUpgradeTimeTest
|
||||
{
|
||||
public CalculateUpgradeTimeTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCalculateUpgradeTime()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var accountDomainService =
|
||||
scope.ServiceProvider.GetRequiredService<IAccountDomainService>();
|
||||
int needDay = accountDomainService.CalculateUpgradeTime(
|
||||
new UserInfo
|
||||
{
|
||||
Money = 7,
|
||||
Level_info = new LevelInfo()
|
||||
{
|
||||
Current_level = 5,
|
||||
Current_exp = 100,
|
||||
Next_exp = 200,
|
||||
},
|
||||
Uname = "uname",
|
||||
Wallet = new(),
|
||||
Wbi_img = new() { img_url = "", sub_url = "" },
|
||||
}
|
||||
);
|
||||
int needDay2 = accountDomainService.CalculateUpgradeTime(
|
||||
new UserInfo()
|
||||
{
|
||||
Money = 7,
|
||||
Level_info = new LevelInfo()
|
||||
{
|
||||
Current_level = 5,
|
||||
Current_exp = 1000,
|
||||
Next_exp = 2000,
|
||||
},
|
||||
Uname = "uname",
|
||||
Wallet = new(),
|
||||
Wbi_img = new() { img_url = "", sub_url = "" },
|
||||
}
|
||||
);
|
||||
|
||||
Assert.Equal(1, needDay);
|
||||
Assert.Equal(37, needDay2);
|
||||
}
|
||||
}
|
||||
23
test/DomainServiceTest/DomainServiceTest.csproj
Normal file
23
test/DomainServiceTest/DomainServiceTest.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
9
test/DomainServiceTest/DonateCoinDomainServiceTest.cs
Normal file
9
test/DomainServiceTest/DonateCoinDomainServiceTest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DomainServiceTest;
|
||||
|
||||
public class DonateCoinDomainServiceTest
|
||||
{
|
||||
public DonateCoinDomainServiceTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
}
|
||||
5
test/DomainServiceTest/Usings.cs
Normal file
5
test/DomainServiceTest/Usings.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Ray.BiliBiliTool.Console;
|
||||
global using Ray.BiliBiliTool.DomainService.Interfaces;
|
||||
global using Ray.BiliBiliTool.Infrastructure;
|
||||
global using Xunit;
|
||||
33
test/DomainServiceTest/VideoDomainServiceTest.cs
Normal file
33
test/DomainServiceTest/VideoDomainServiceTest.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Ray.BiliBiliTool.Infrastructure.Helpers;
|
||||
using Ray.Infrastructure.Helpers;
|
||||
|
||||
namespace DomainServiceTest
|
||||
{
|
||||
public class VideoDomainServiceTest
|
||||
{
|
||||
public VideoDomainServiceTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetVideoCountOfUp_Test()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var config = Global.ConfigurationRoot;
|
||||
var domainService = scope.ServiceProvider.GetRequiredService<IVideoDomainService>();
|
||||
|
||||
await domainService.GetVideoCountOfUp(1585227649, null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRandomVideoOfUp_Test()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var config = Global.ConfigurationRoot;
|
||||
var domainService = scope.ServiceProvider.GetRequiredService<IVideoDomainService>();
|
||||
|
||||
await domainService.GetRandomVideoOfUp(1585227649, 1, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
test/InfrastructureTest/InfrastructureTest.csproj
Normal file
21
test/InfrastructureTest/InfrastructureTest.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
1
test/InfrastructureTest/Usings.cs
Normal file
1
test/InfrastructureTest/Usings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
21
test/InfrastructureTest/WbiHelperTest.cs
Normal file
21
test/InfrastructureTest/WbiHelperTest.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace InfrastructureTest
|
||||
{
|
||||
public class WbiHelperTest
|
||||
{
|
||||
[Fact]
|
||||
public void Replace_Test()
|
||||
{
|
||||
string input = "<22><><EFBFBD><EFBFBD>һ<EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>!@#$%^&*(')<29><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>";
|
||||
string pattern = "[!'()*]";
|
||||
string replacement = "";
|
||||
|
||||
string output = Regex.Replace(input, pattern, replacement);
|
||||
Debug.WriteLine(output);
|
||||
|
||||
Assert.Equal("<22><><EFBFBD><EFBFBD>һ<EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>@#$%^&<26><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>", output);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
test/LogTest/LogConstants.cs
Normal file
13
test/LogTest/LogConstants.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class LogConstants
|
||||
{
|
||||
public static string Msg =
|
||||
"ℹ 版本号:\"1.1.0\"\r\nℹ 开源地址:\"https://github.com/RayWangQvQ/BiliBiliTool\"\r\nℹ 当前环境:\"Development\" \r\n\r\nℹ -----开始每日任务-----\r\n\r\nℹ ---开始【\"登录\"】---\r\nℹ 登录成功,用户名: \"在*楼\"\r\nℹ 硬币余额: 666.5\r\nℹ 距离升级到Lv6还有: 258天\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"观看、分享视频\"】---\r\nℹ 获取随机视频:\"【周深&李克勤】“勤深深”组合《突如其来的爱情》日语+粤语无缝切换天作之合!\"\r\nℹ 今天已经观看过了,不需要再看啦\r\nℹ 视频分享成功\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"投币\"】---\r\nℹ 今日已投0枚硬币,目标是投5枚,还需再投5枚\r\nℹ 投币前余额为 : 666.5\r\nℹ 为“\"【本宫吐槽】变态赛高:传说中的神番《永生之酒》,究竟神在哪里?\"”投币成功\r\nℹ 为“\"鲲鹏计算引领多样性计算新时代【思维+】\"”投币成功\r\nℹ 为“\"【瞎看什么】激突!王者告诉你爸爸的爸爸叫什么!\"”投币成功\r\nℹ 为“\"带着18个妹子去广东吃吃吃,没想到却把她们苦哭了!\"”投币成功\r\nℹ 为“\"沙盘推演:红25军长征记(第一阶段)激战独树镇 徐海东血战庾家河 年龄最小的长征队伍\"”投币成功\r\nℹ 投币任务完成,余额为: 661.5\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"漫画签到\"】---\r\nℹ 完成漫画签到\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"直播中心签到\"】---\r\nℹ 直播签到成功,本次签到获得\"3000点用户经验,2根辣条\",\"\"\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"直播中心银瓜子兑换硬币\"】---\r\nℹ 银瓜子兑换硬币失败,原因:\"银瓜子余额不足\"\r\nℹ 当前银瓜子余额: 564\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"每月领取大会员福利\"】---\r\nℹ 目标领取日期为1号,今天是29号,跳过领取任务\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"每月领取大会员漫画权益\"】---\r\nℹ 目标领取日期为1号,今天是29号,跳过领取任务\r\nℹ ---结束---\r\n\r\nℹ ---开始【\"每月为自己充电\"】---\r\nℹ 目标充电日期为31号,今天是29号,跳过充电任务\r\nℹ ---结束---\r\n\r\nℹ -----全部任务已执行结束-----\r\n\r\nℹ 开始推送\r\n";
|
||||
|
||||
public static string Msg2 =
|
||||
$"1{Environment.NewLine}2{Environment.NewLine}{Environment.NewLine}3";
|
||||
}
|
||||
}
|
||||
22
test/LogTest/LogTest.csproj
Normal file
22
test/LogTest/LogTest.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>5bc79f80-380e-4bcf-9c0b-30e98db3b935</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
41
test/LogTest/TestCoolPush.cs
Normal file
41
test/LogTest/TestCoolPush.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.CoolPushBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestCoolPush
|
||||
{
|
||||
private string _key;
|
||||
|
||||
public TestCoolPush()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_key = Global.ConfigurationRoot["Serilog:WriteTo:7:Args:sKey"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test2()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_key))
|
||||
{
|
||||
Debug.WriteLine("CoolPush key not configured, skipping test");
|
||||
return;
|
||||
}
|
||||
|
||||
var client = new CoolPushApiClient(_key);
|
||||
string msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
test/LogTest/TestDingTalk.cs
Normal file
43
test/LogTest/TestDingTalk.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.DingTalkBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestDingTalk
|
||||
{
|
||||
private string _key;
|
||||
|
||||
public TestDingTalk()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(["ENVIRONMENT=Development"]);
|
||||
|
||||
// 添加空值检查
|
||||
if (Global.ConfigurationRoot != null)
|
||||
{
|
||||
_key = Global.ConfigurationRoot["Serilog:WriteTo:5:Args:webHookUrl"];
|
||||
}
|
||||
else
|
||||
{
|
||||
_key = "test_key"; // 默认测试值
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test2()
|
||||
{
|
||||
var client = new DingTalkApiClient(_key);
|
||||
|
||||
var title = "这是标题";
|
||||
var msg = LogConstants.Msg2 + "开始推送";
|
||||
|
||||
var result = await client.PushMessageAsync(msg, title);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
test/LogTest/TestMicrosoftTeams.cs
Normal file
38
test/LogTest/TestMicrosoftTeams.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.MicrosoftTeamsBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestMicrosoftTeams
|
||||
{
|
||||
private string _webhook;
|
||||
|
||||
public TestMicrosoftTeams()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_webhook = Global.ConfigurationRoot["Serilog:WriteTo:10:Args:webhook"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test()
|
||||
{
|
||||
var client = new MicrosoftTeamsApiClient(webhook: _webhook);
|
||||
|
||||
var msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
|
||||
Assert.True(result.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
test/LogTest/TestPushPlus.cs
Normal file
40
test/LogTest/TestPushPlus.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.PushPlusBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestPushPlus
|
||||
{
|
||||
private string _token;
|
||||
private string _channel;
|
||||
private string _webhook;
|
||||
|
||||
public TestPushPlus()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_token = Global.ConfigurationRoot["Serilog:WriteTo:9:Args:token"];
|
||||
_channel = Global.ConfigurationRoot["Serilog:WriteTo:9:Args:channel"];
|
||||
_webhook = Global.ConfigurationRoot["Serilog:WriteTo:9:Args:webhook"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test2()
|
||||
{
|
||||
var client = new PushPlusApiClient(_token, channel: _channel, webhook: _webhook);
|
||||
|
||||
var msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
test/LogTest/TestServerChan.cs
Normal file
57
test/LogTest/TestServerChan.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.ServerChanBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestServerChan
|
||||
{
|
||||
private string _scKey;
|
||||
private string _turboScKey;
|
||||
|
||||
public TestServerChan()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_scKey = Global.ConfigurationRoot["Serilog:WriteTo:6:Args:scKey"];
|
||||
_turboScKey = Global.ConfigurationRoot["Serilog:WriteTo:6:Args:turboScKey"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test()
|
||||
{
|
||||
var client = new ServerChanApiClient(_scKey);
|
||||
|
||||
string msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
|
||||
/*
|
||||
* server酱的换行有问题,一个newline换不了,要两个
|
||||
*/
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestTurbo()
|
||||
{
|
||||
var client = new ServerChanTurboApiClient(_turboScKey);
|
||||
|
||||
string msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg, "测试");
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
|
||||
/*
|
||||
* server酱的换行有问题,一个newline换不了,要两个
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
40
test/LogTest/TestTelegram.cs
Normal file
40
test/LogTest/TestTelegram.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.TelegramBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestTelegram
|
||||
{
|
||||
private string _botToken;
|
||||
private string _chatId;
|
||||
|
||||
public TestTelegram()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(["ENVIRONMENT=Development"]);
|
||||
|
||||
_botToken = Global.ConfigurationRoot?["Serilog:WriteTo:3:Args:botToken"];
|
||||
_chatId = Global.ConfigurationRoot?["Serilog:WriteTo:3:Args:chatId"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test2()
|
||||
{
|
||||
var client = new TelegramApiClient(_botToken, _chatId);
|
||||
|
||||
string msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg, "标题");
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
|
||||
/*
|
||||
* 如果指定markdown,星号会导致推送失败
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
37
test/LogTest/TestWorkWeiXin.cs
Normal file
37
test/LogTest/TestWorkWeiXin.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.WorkWeiXinBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestWorkWeiXin
|
||||
{
|
||||
private string _key;
|
||||
|
||||
public TestWorkWeiXin()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_key = Global.ConfigurationRoot["Serilog:WriteTo:4:Args:webHookUrl"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test2()
|
||||
{
|
||||
var client = new WorkWeiXinApiClient(_key, WorkWeiXinMsgType.text);
|
||||
|
||||
//string msg = LogConstants.Msg;
|
||||
string msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
test/LogTest/TestWorkWeiXinApp.cs
Normal file
43
test/LogTest/TestWorkWeiXinApp.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.Serilog.Sinks.WorkWeiXinAppBatched;
|
||||
using Xunit;
|
||||
|
||||
namespace LogTest
|
||||
{
|
||||
public class TestWorkWeiXinApp
|
||||
{
|
||||
private string _agentId;
|
||||
private string _secret;
|
||||
private string _corpId;
|
||||
private string _toUser;
|
||||
|
||||
public TestWorkWeiXinApp()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
Program.CreateHost(new string[] { "ENVIRONMENT=Development" });
|
||||
|
||||
_agentId = Global.ConfigurationRoot["Serilog:WriteTo:11:Args:agentId"];
|
||||
_secret = Global.ConfigurationRoot["Serilog:WriteTo:11:Args:secret"];
|
||||
_corpId = Global.ConfigurationRoot["Serilog:WriteTo:11:Args:corpId"];
|
||||
|
||||
_toUser = Global.ConfigurationRoot["Serilog:WriteTo:11:Args:toUser"];
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test()
|
||||
{
|
||||
var client = new WorkWeiXinAppApiClient(_corpId, _agentId, _secret, _toUser);
|
||||
|
||||
var msg = LogConstants.Msg2;
|
||||
|
||||
var result = await client.PushMessageAsync(msg);
|
||||
Debug.WriteLine(result.Content.ReadAsStringAsync().Result);
|
||||
|
||||
Assert.True(result.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class AccountApiTests
|
||||
{
|
||||
private readonly IAccountApi _api;
|
||||
|
||||
public AccountApiTests()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_api = host.Services.GetRequiredService<IAccountApi>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetCoinBalance_Normal_GetCoinBalance()
|
||||
{
|
||||
// Act
|
||||
BiliApiResponse<CoinBalance> re = await _api.GetCoinBalanceAsync(null);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Money.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
149
test/Ray.BiliBiliTool.Agent.FunctionalTests/ArticleApiTests.cs
Normal file
149
test/Ray.BiliBiliTool.Agent.FunctionalTests/ArticleApiTests.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Article;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Services;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class ArticleApiTests
|
||||
{
|
||||
private readonly IArticleApi _api;
|
||||
|
||||
private readonly BiliCookie _ck;
|
||||
private readonly IWbiService _wbiService;
|
||||
|
||||
public ArticleApiTests()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_wbiService = host.Services.GetRequiredService<IWbiService>();
|
||||
_api = host.Services.GetRequiredService<IArticleApi>();
|
||||
}
|
||||
|
||||
#region SearchUpArticlesByUpIdAsync
|
||||
|
||||
[Fact]
|
||||
public async Task SearchUpArticlesByUpIdAsync_InputId_GetResultSuccess()
|
||||
{
|
||||
// Arrange
|
||||
var mid = 1585227649;
|
||||
var req = new SearchArticlesByUpIdDto() { mid = mid };
|
||||
await _wbiService.SetWridAsync(req, null);
|
||||
|
||||
// Act
|
||||
BiliApiResponse<SearchUpArticlesResponse> re = await _api.SearchUpArticlesByUpIdAsync(req);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SearchArticleInfoAsync
|
||||
|
||||
[Fact]
|
||||
public async Task SearchArticleInfoAsync_ValidId_GetResultSuccess()
|
||||
{
|
||||
// Arrange
|
||||
var cvid = 34150576;
|
||||
|
||||
// Act
|
||||
var re = await _api.SearchArticleInfoAsync(cvid);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Mid.Should().BeGreaterThan(0);
|
||||
re.Data.Like.Should().BeGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SearchArticleInfoAsync_InvalidId_NoResult()
|
||||
{
|
||||
// Arrange
|
||||
var cvid = 123;
|
||||
|
||||
// Act
|
||||
var re = await _api.SearchArticleInfoAsync(cvid);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(-404);
|
||||
re.Data.Should().BeNull();
|
||||
re.Message.Should().BeEquivalentTo("啥都木有");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region AddCoinForArticleAsync
|
||||
|
||||
[Fact]
|
||||
public async Task AddCoinForArticleAsync_CoinSelf_Fail()
|
||||
{
|
||||
// Arrange
|
||||
var selfCvId = 34150576; //todo
|
||||
var req = new AddCoinForArticleRequest(selfCvId, long.Parse(_ck.UserId), _ck.BiliJct);
|
||||
|
||||
// Act
|
||||
BiliBiliAgent.Dtos.BiliApiResponse re = await _api.AddCoinForArticleAsync(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(34002);
|
||||
re.Message.Should().BeEquivalentTo("up主不能自己投币");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddCoinForArticleAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
var cvId = 34049005; //todo
|
||||
var upId = 25150765; //todo
|
||||
var req = new AddCoinForArticleRequest(cvId, upId, _ck.BiliJct);
|
||||
|
||||
// Act
|
||||
BiliBiliAgent.Dtos.BiliApiResponse re = await _api.AddCoinForArticleAsync(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should()
|
||||
.BeOneOf(
|
||||
0, // 成功
|
||||
34005 // 超过投币上限啦~
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region LikeAsync
|
||||
|
||||
[Fact]
|
||||
public async Task LikeAsync_AlreadyLike_GetResultSuccess()
|
||||
{
|
||||
// Arrange
|
||||
var cvid = 34150576;
|
||||
|
||||
// Act
|
||||
var re = await _api.LikeAsync(cvid, _ck.BiliJct, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should()
|
||||
.BeOneOf(
|
||||
new List<int>
|
||||
{
|
||||
0,
|
||||
65006, //已赞过
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
55
test/Ray.BiliBiliTool.Agent.FunctionalTests/ChargeApiTest.cs
Normal file
55
test/Ray.BiliBiliTool.Agent.FunctionalTests/ChargeApiTest.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class ChargeApiTest
|
||||
{
|
||||
private readonly IChargeApi _target;
|
||||
|
||||
private readonly BiliCookie _ck;
|
||||
|
||||
public ChargeApiTest()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_target = host.Services.GetRequiredService<IChargeApi>();
|
||||
}
|
||||
|
||||
#region ChargeV2Async
|
||||
|
||||
[Fact]
|
||||
public async void ChargeV2Async_SendRequest_NotEnough()
|
||||
{
|
||||
// Arrange
|
||||
var upId = 220893216;
|
||||
var req = new ChargeRequest(2, upId, _ck.BiliJct);
|
||||
|
||||
// Act
|
||||
BiliApiResponse<ChargeV2Response> re = await _target.ChargeV2Async(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Status.Should()
|
||||
.BeOneOf(
|
||||
-4, //bp.to.battery http failed, invalid args, errNo=800409904: B <20><><EFBFBD><EFBFBD><EFBFBD><EEB2BB>
|
||||
4
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ChargeCommentAsync
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class DailyTaskApiTests
|
||||
{
|
||||
private readonly IDailyTaskApi _api;
|
||||
|
||||
private readonly BiliCookie _ck;
|
||||
|
||||
public DailyTaskApiTests()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_api = host.Services.GetRequiredService<IDailyTaskApi>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDailyTaskRewardInfo_Normal_Success()
|
||||
{
|
||||
// Act
|
||||
BiliApiResponse<DailyTaskInfo> re = await _api.GetDailyTaskRewardInfoAsync(null);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDonateCoinExp_Normal_Success()
|
||||
{
|
||||
// Act
|
||||
BiliApiResponse<int> re = await _api.GetDonateCoinExpAsync(null);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Should().BeGreaterThanOrEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReceiveVipPrivilege_Normal_Success()
|
||||
{
|
||||
// Act
|
||||
BiliApiResponse re = await _api.ReceiveVipPrivilegeAsync(
|
||||
(int)VipPrivilegeType.BCoinCoupon,
|
||||
_ck.BiliJct,
|
||||
null
|
||||
);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Assert
|
||||
re.Code.Should()
|
||||
.BeOneOf(
|
||||
0,
|
||||
73319, //todo: sort out meannings
|
||||
69801 //你已领取过该权益
|
||||
);
|
||||
}
|
||||
}
|
||||
41
test/Ray.BiliBiliTool.Agent.FunctionalTests/HomeApiTests.cs
Normal file
41
test/Ray.BiliBiliTool.Agent.FunctionalTests/HomeApiTests.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class HomeApiTests
|
||||
{
|
||||
private readonly IHomeApi _api;
|
||||
|
||||
private readonly BiliCookie _ck;
|
||||
|
||||
public HomeApiTests()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_api = host.Services.GetRequiredService<IHomeApi>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetHomePageAsync_Normal_Success()
|
||||
{
|
||||
// Act
|
||||
HttpResponseMessage re = await _api.GetHomePageAsync(_ck.ToString());
|
||||
|
||||
// Arrange
|
||||
var page = await re.Content.ReadAsStringAsync();
|
||||
|
||||
// Assert
|
||||
re.IsSuccessStatusCode.Should().BeTrue();
|
||||
page.Should().Contain("<title>哔哩哔哩 (゜-゜)つロ 干杯~-bilibili</title>");
|
||||
}
|
||||
}
|
||||
172
test/Ray.BiliBiliTool.Agent.FunctionalTests/LiveApiTest.cs
Normal file
172
test/Ray.BiliBiliTool.Agent.FunctionalTests/LiveApiTest.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ray.BiliBiliTool.Agent;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Live;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Services;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Ray.BiliBiliTool.Infrastructure;
|
||||
using Ray.BiliBiliTool.Infrastructure.Cookie;
|
||||
using Xunit;
|
||||
|
||||
namespace BiliAgentTest
|
||||
{
|
||||
public class LiveApiTest
|
||||
{
|
||||
public LiveApiTest()
|
||||
{
|
||||
Program.CreateHost(new[] { "--ENVIRONMENT=Development" }); //ĬÈÏPrd»·¾³£¬ÕâÀïÖ¸¶¨ÎªDevºó£¬¿ÉÒÔ¶ÁÈ¡µ½Óû§»úÃÜÅäÖÃ
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Obsolete]
|
||||
public void GetExchangeSilverStatus_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
|
||||
BiliApiResponse<ExchangeSilverStatusResponse> re = api.GetExchangeSilverStatus(
|
||||
null
|
||||
).Result;
|
||||
|
||||
if (ck.Count > 0)
|
||||
{
|
||||
Assert.True(re.Code == 0 && re.Message == "0");
|
||||
Assert.True(re.Data.Silver >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(re.Code != 0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Silver2Coin_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
var biliCookie = scope.ServiceProvider.GetRequiredService<BiliCookie>();
|
||||
|
||||
Silver2CoinRequest request = new(biliCookie.BiliJct);
|
||||
|
||||
BiliApiResponse<Silver2CoinResponse> re = api.Silver2Coin(request, null).Result;
|
||||
|
||||
if (re.Code == 0)
|
||||
{
|
||||
Assert.True(re.Data.Coin == 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(re.Message));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetLiveWalletStatus_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
|
||||
BiliApiResponse<LiveWalletStatusResponse> re = api.GetLiveWalletStatus(null).Result;
|
||||
|
||||
if (ck.Count > 0)
|
||||
{
|
||||
Assert.True(re.Code == 0 && re.Data.Silver_2_coin_left >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(re.Code != 0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMedalWall_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
|
||||
BiliApiResponse<MedalWallResponse> re = api.GetMedalWall("919174", null).Result;
|
||||
|
||||
Assert.NotEmpty(re.Data.List);
|
||||
|
||||
var md = re.Data.List[0];
|
||||
Assert.NotNull(md);
|
||||
Assert.False(String.IsNullOrEmpty(md.Link));
|
||||
Assert.False(String.IsNullOrEmpty(md.Target_name));
|
||||
Assert.NotNull(md.Medal_info);
|
||||
Assert.False(String.IsNullOrEmpty(md.Medal_info.Medal_name));
|
||||
Assert.True(md.Medal_info.Medal_id > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WearMedalWall_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
var biliCookie = scope.ServiceProvider.GetRequiredService<BiliCookie>();
|
||||
|
||||
// 猫雷粉丝牌
|
||||
var request = new WearMedalWallRequest(biliCookie.BiliJct, 365421); //todo
|
||||
|
||||
BiliApiResponse re = api.WearMedalWall(request, null).Result;
|
||||
|
||||
Assert.True(re.Code == 0);
|
||||
re.Code.Should().BeOneOf(0, 1500005);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSpaceInfo_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<IUpInfoApi>();
|
||||
|
||||
var wbiService = scope.ServiceProvider.GetRequiredService<IWbiService>();
|
||||
|
||||
var req = new GetSpaceInfoDto() { mid = 919174L };
|
||||
|
||||
BiliApiResponse<GetSpaceInfoResponse> re = api.GetSpaceInfo(
|
||||
req,
|
||||
ck.GetCookie(0).ToString()
|
||||
).Result;
|
||||
|
||||
Assert.True(re.Code == 0);
|
||||
Assert.NotNull(re.Data);
|
||||
Assert.Equal(919174, re.Data.Mid);
|
||||
Assert.NotNull(re.Data.Live_room);
|
||||
Assert.Equal(3115258, re.Data.Live_room.Roomid);
|
||||
Assert.False(String.IsNullOrEmpty(re.Data.Name));
|
||||
Assert.False(String.IsNullOrEmpty(re.Data.Live_room.Title));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SendLiveDanmuku_Normal_Success()
|
||||
{
|
||||
using var scope = Global.ServiceProviderRoot.CreateScope();
|
||||
|
||||
var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory<BiliCookie>>();
|
||||
var api = scope.ServiceProvider.GetRequiredService<ILiveApi>();
|
||||
var biliCookie = scope.ServiceProvider.GetRequiredService<BiliCookie>();
|
||||
|
||||
var request = new SendLiveDanmukuRequest(biliCookie.BiliJct, 63666, "63666");
|
||||
|
||||
BiliApiResponse re = api.SendLiveDanmuku(request, null).Result;
|
||||
|
||||
Assert.True(re.Code == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ray.BiliBiliTool.Console\Ray.BiliBiliTool.Console.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,108 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Mall;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.VipTask;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class VipBigPointApiTest
|
||||
{
|
||||
private readonly IVipBigPointApi _api;
|
||||
|
||||
private readonly ITestOutputHelper _output;
|
||||
private readonly BiliCookie _ck;
|
||||
|
||||
public VipBigPointApiTest(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_api = host.Services.GetRequiredService<IVipBigPointApi>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTaskListAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
BiliApiResponse<VipBigPointCombine> re = await _api.GetCombineAsync(null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.Should().NotBeNull();
|
||||
re.Data.Task_info.Modules.Should().HaveCountGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SignAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
var req = new SignRequest() { csrf = _ck.BiliJct };
|
||||
|
||||
// Act
|
||||
BiliApiResponse re = await _api.SignAsync(req, null);
|
||||
_output.WriteLine(re.ToJsonStr());
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Message.Should().BeEquivalentTo("success");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetVouchersInfoAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
var re = await _api.GetVouchersInfoAsync(null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Data.List.Should().Contain(x => x.Type == 9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetVipExperienceAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
var req = new VipExperienceRequest() { csrf = _ck.BiliJct };
|
||||
|
||||
// Act
|
||||
BiliApiResponse re = await _api.ObtainVipExperienceAsync(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should()
|
||||
.BeOneOf(
|
||||
new List<int>
|
||||
{
|
||||
0,
|
||||
6034005, //任务未完成
|
||||
69198, //用户经验已经领取
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
var req = new ReceiveOrCompleteTaskRequest("dress-view");
|
||||
|
||||
// Act
|
||||
var re = await _api.CompleteAsync(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.ViewMall;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class VipMallApiTests
|
||||
{
|
||||
private readonly IVipMallApi _api;
|
||||
|
||||
private readonly BiliCookie _ck;
|
||||
|
||||
public VipMallApiTests()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_ck = host.Services.GetRequiredService<BiliCookie>();
|
||||
_api = host.Services.GetRequiredService<IVipMallApi>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ViewVipMallAsync_Normal_Success()
|
||||
{
|
||||
// Arrange
|
||||
var req = new ViewVipMallRequest() { Csrf = _ck.BiliJct };
|
||||
|
||||
// Act
|
||||
BiliApiResponse re = await _api.ViewVipMallAsync(req, null);
|
||||
|
||||
// Assert
|
||||
re.Code.Should().Be(0);
|
||||
re.Message.Should().BeEquivalentTo("SUCCESS");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Video;
|
||||
using Ray.BiliBiliTool.Agent.BiliBiliAgent.Services;
|
||||
using Ray.BiliBiliTool.Console;
|
||||
|
||||
namespace Ray.BiliBiliTool.Agent.FunctionalTests;
|
||||
|
||||
public class WbiServiceTest
|
||||
{
|
||||
private readonly IWbiService _target;
|
||||
|
||||
public WbiServiceTest()
|
||||
{
|
||||
var envs = new List<string>
|
||||
{
|
||||
"--ENVIRONMENT=Development",
|
||||
//"HTTP_PROXY=localhost:8888",
|
||||
//"HTTPS_PROXY=localhost:8888"
|
||||
};
|
||||
IHost host = Program.CreateHost(envs.ToArray());
|
||||
_target = host.Services.GetRequiredService<IWbiService>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SetWridAsync_SendRequest_SetWridSuccess()
|
||||
{
|
||||
// Arrange
|
||||
var upId = 1585227649;
|
||||
var req = new SearchVideosByUpIdDto()
|
||||
{
|
||||
mid = upId,
|
||||
ps = 30,
|
||||
tid = 0,
|
||||
pn = 1,
|
||||
keyword = "",
|
||||
order = "pubdate",
|
||||
platform = "web",
|
||||
web_location = 1550101,
|
||||
order_avoided = "true",
|
||||
};
|
||||
|
||||
// Act
|
||||
await _target.SetWridAsync(req, null);
|
||||
|
||||
// Assert
|
||||
req.w_rid.Should().NotBeNullOrWhiteSpace();
|
||||
req.wts.Should().NotBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncWbi_InputParams_GetCorrectWbiResult()
|
||||
{
|
||||
// Arrange
|
||||
var wbiDto = new WbiImg()
|
||||
{
|
||||
img_url = "https://i0.hdslb.com/bfs/wbi/653657f524a547ac981ded72ea172057.png",
|
||||
sub_url = "https://i0.hdslb.com/bfs/wbi/6e4909c702f846728e64f6007736a338.png",
|
||||
};
|
||||
var dic = new Dictionary<string, string>()
|
||||
{
|
||||
{ "foo", "114" },
|
||||
{ "bar", "514" },
|
||||
{ "baz", "1919810" },
|
||||
};
|
||||
var timeSpan = 1684746387;
|
||||
var expectResult = "d3cbd2a2316089117134038bf4caf442";
|
||||
|
||||
// Act
|
||||
var re = _target.EncWbi(dic, wbiDto.ImgKey, wbiDto.SubKey, timeSpan);
|
||||
|
||||
// Assert
|
||||
re.w_rid.Should().BeEquivalentTo(expectResult);
|
||||
re.wts.Should().Be(timeSpan);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user