mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-24 10:49:51 +08:00
optimization request http
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using NUnit.Framework;
|
||||
using System.Application.Services;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Application
|
||||
{
|
||||
[TestFixture]
|
||||
public class HttpTest
|
||||
{
|
||||
[Test]
|
||||
public void GetImage()
|
||||
{
|
||||
const string api_base = "https://localhost:5001/";
|
||||
var images = new[] {
|
||||
"images/icons/company.png",
|
||||
"images/icons/GitHub-Mark-120px-plus.png",
|
||||
"images/icons/icon.png",
|
||||
"images/company.png",
|
||||
"images/icons/company.png",
|
||||
"images/icons/GitHub-Mark-120px-plus.png",
|
||||
"images/icons/logo.png",
|
||||
"images/company.png",
|
||||
"images/icons/icon.png",
|
||||
"images/icons/icon.png",
|
||||
"images/icons/steam.png" };
|
||||
|
||||
var tasks = images.Select(Handle).ToArray();
|
||||
Task.WaitAll(tasks);
|
||||
TestContext.WriteLine("OK");
|
||||
|
||||
static async Task Handle(string requestUri)
|
||||
{
|
||||
var tid = Thread.CurrentThread.ManagedThreadId;
|
||||
var result = await IHttpService.Instance.GetImageAsync(
|
||||
api_base + requestUri, ImageChannelType.SteamAvatars);
|
||||
var tid2 = Thread.CurrentThread.ManagedThreadId;
|
||||
TestContext.WriteLine($"({tid}-{tid2})requestUri: {requestUri}, length: {result?.Length}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using System.Logging;
|
||||
|
||||
namespace System.Application
|
||||
{
|
||||
[SetUpFixture]
|
||||
public class SetupFixture
|
||||
{
|
||||
public static bool DIInit { get; set; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
// TODO: Add code here that is run before
|
||||
// all tests in the assembly are run
|
||||
if (!DIInit)
|
||||
{
|
||||
DI.Init(ConfigureServices);
|
||||
|
||||
var path = AppContext.BaseDirectory;
|
||||
var path1 = Path.Combine(path, "AppData");
|
||||
IOPath.DirCreateByNotExists(path1);
|
||||
var path2 = Path.Combine(path, "Cache");
|
||||
IOPath.DirCreateByNotExists(path2);
|
||||
string GetAppDataDirectory() => path1;
|
||||
string GetCacheDirectory() => path2;
|
||||
IOPath.InitFileSystem(GetAppDataDirectory, GetCacheDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
// TODO: Add code here that is run after
|
||||
// all tests in the assembly have been run
|
||||
}
|
||||
|
||||
static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddLogging(l => l.AddProvider(NUnitLoggerProvider.Instance));
|
||||
services.Configure<LoggerFilterOptions>(o =>
|
||||
{
|
||||
o.MinLevel = LogLevel.Trace;
|
||||
});
|
||||
services.TryAddHttpPlatformHelper();
|
||||
services.AddHttpService();
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>System.Application</RootNamespace>
|
||||
<DefineConstants>UnitTest;$(DefineConstants)</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\System.Common.CoreLib\Properties\AssemblyInfo.cs">
|
||||
<Link>Properties\AssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\System.Common.UnitTest\Logging\NUnitLogger.cs">
|
||||
<Link>Logging\NUnitLogger.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\System.Common.UnitTest\Logging\NUnitLoggerProvider.cs">
|
||||
<Link>Logging\NUnitLoggerProvider.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\System.Application.SteamTools.Client\System.Application.SteamTools.Client.csproj" />
|
||||
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.13.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user