Skip to content

Commit

Permalink
Merge pull request #3 from BeyondDimension/feature/markettrading
Browse files Browse the repository at this point in the history
✨ WTTS issues #338 除报价相关功能
  • Loading branch information
yingpanwang committed Aug 17, 2023
2 parents 18558e2 + f3f0fe0 commit 136a80d
Show file tree
Hide file tree
Showing 17 changed files with 1,375 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "BD.SteamClient.sln"
}
165 changes: 160 additions & 5 deletions src/BD.SteamClient.UnitTest/SteamAccountServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,172 @@
using static System.Net.Http.HttpClientUseCookiesWithProxyServiceImpl;

namespace BD.SteamClient.UnitTest;

public sealed class SteamAccountServiceTest
{
//IServiceProvider service;
SteamLoginState? globalState;

IServiceProvider service;

ISteamAccountService Client => service.GetRequiredService<ISteamAccountService>();

internal class TestRandomGetUserAgentService : IRandomGetUserAgentService
{
public string GetUserAgent()
{
return IRandomGetUserAgentService.Steam;
}
}

internal class TestAppSettings : IAppSettings, IOptionsMonitor<IAppSettings>
{
public string? WebProxyAddress { get; set; }

public int? WebProxyPort { get; set; }

public string? WebProxyUserName { get; set; }

public string? WebProxyPassword { get; set; }

public IAppSettings CurrentValue => this;

//ISteamAccountService Client => service.GetRequiredService<ISteamAccountService>();
public IAppSettings Get(string? name)
{
return this;
}

public IDisposable? OnChange(Action<IAppSettings, string?> listener)
{
return null;
}
}

[SetUp]
public void Setup()
{
//var services = new ServiceCollection();
//services.AddTransient<ISteamAccountService, SteamAccountServiceImpl>();
//service = services.BuildServiceProvider();
var services = new ServiceCollection();
services.AddTransient<ISteamAccountService, SteamAccountService>();
services.AddTransient<ISteamSessionService, SteamSessionServiceImpl>();
services.AddTransient<ISteamMarketService, SteamMarketService>();
services.AddTransient<IRandomGetUserAgentService, TestRandomGetUserAgentService>();
services.AddTransient<IOptionsMonitor<IAppSettings>, TestAppSettings>();

services.AddLogging();

service = services.BuildServiceProvider();

service.GetRequiredService<IRandomGetUserAgentService>();
service.GetRequiredService<IOptionsMonitor<IAppSettings>>();
service.GetRequiredService<ISteamAccountService>();
service.GetRequiredService<ISteamSessionService>();

if (globalState == null)
{

string path = $"{AppDomain.CurrentDomain.BaseDirectory}/state.json";

if (File.Exists(path))
{
using FileStream fs = new FileStream(path, FileMode.Open);

globalState = JsonSerializer.Deserialize<SteamLoginState>(fs);
}

// if (true)
// {
// globalState = new SteamLoginState()
// {
// Username = globalState!.Username,
// Password = globalState!.Password,
// };
// Client.DoLoginV2Async(globalState!).GetAwaiter().GetResult();
// Client.DoLoginV2Async(globalState!).GetAwaiter().GetResult();
// string x = JsonSerializer.Serialize(globalState);
// }
}
}

/// <summary>
/// 测试获取库存列表
/// </summary>
/// <param name="steamId"></param>
/// <param name="appId"></param>
/// <param name="contextId"></param>
/// <returns></returns>
[TestCase(76561199473732040UL, "730", "2")]
[Test]
public async Task TestGetInventories(ulong steamId, string appId, string contextId)
{
var resp = await Client.GetInventories(steamId, appId, contextId, 1);

Assert.That(resp.Success, Is.EqualTo(1));
}

[TestCase(null)]
[TestCase(new[] { 754, 730, 570 })]
[Test]
public async Task TestGetAndParseInventoryTradingHistory(int[]? appFilter)
{
if (globalState != null)
{
InventoryTradeHistoryRenderPageResponse.InventoryTradeHistoryCursor? cursor = null;

var page = await Client.GetInventoryTradeHistory(globalState!, appFilter, cursor);

Assert.That(page, Is.Not.Null);
Assert.That(page.Success, Is.True);

var parsedRows = Client.ParseInventoryTradeHistory(page.Html)
.ToBlockingEnumerable()
.ToList();

Assert.That(parsedRows, Is.Not.Null);
}
}

/// <summary>
/// 测试获取开发api key
/// </summary>
/// <returns></returns>
[Test]
public async Task TestGetApiKey()
{
if (globalState != null)
{
string? apiKey = await Client.GetApiKey(globalState!);

if (string.IsNullOrEmpty(apiKey))
{
apiKey = await Client.RegisterApiKey(globalState!);
}

Assert.That(apiKey, Is.Not.Null);
Assert.That(apiKey, Is.Not.EqualTo(string.Empty));
}
}

[Test]
public async Task TestGetSendGiftHistory()
{
if (globalState != null)
{
var history = await Client.GetSendGiftHisotries(globalState!);

Assert.That(history, Is.Not.Null);
}
}

[Test]
public Task TestGetLoginHistory()
{
if (globalState != null)
{
var result = Client.GetLoginHistory(globalState!);

Assert.That(result, Is.Not.Null);
}

return Task.CompletedTask;
}

//[Test]
Expand Down
97 changes: 97 additions & 0 deletions src/BD.SteamClient.UnitTest/SteamMarketServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using static System.Net.Http.HttpClientUseCookiesWithProxyServiceImpl;

namespace BD.SteamClient.UnitTest;

public class SteamMarketServiceTest
{
IServiceProvider service;

SteamLoginState? globalState;

ISteamAccountService AccountService => service.GetRequiredService<ISteamAccountService>();

ISteamMarketService SteamMarketService => service.GetRequiredService<ISteamMarketService>();

internal class TestRandomGetUserAgentService : IRandomGetUserAgentService
{
public string GetUserAgent()
{
return IRandomGetUserAgentService.Steam;
}
}

internal class TestAppSettings : IAppSettings, IOptionsMonitor<IAppSettings>
{
public string? WebProxyAddress { get; set; }

public int? WebProxyPort { get; set; }

public string? WebProxyUserName { get; set; }

public string? WebProxyPassword { get; set; }

public IAppSettings CurrentValue => this;

public IAppSettings Get(string? name)
{
return this;
}

public IDisposable? OnChange(Action<IAppSettings, string?> listener)
{
return null;
}
}

[SetUp]
public void Setup()
{
var services = new ServiceCollection();
services.AddTransient<ISteamAccountService, SteamAccountService>();
services.AddTransient<ISteamSessionService, SteamSessionServiceImpl>();
services.AddTransient<ISteamMarketService, SteamMarketService>();
services.AddTransient<IRandomGetUserAgentService, TestRandomGetUserAgentService>();
services.AddTransient<IOptionsMonitor<IAppSettings>, TestAppSettings>();

services.AddLogging();

service = services.BuildServiceProvider();

service.GetRequiredService<IRandomGetUserAgentService>();
service.GetRequiredService<IOptionsMonitor<IAppSettings>>();
service.GetRequiredService<ISteamAccountService>();
service.GetRequiredService<ISteamSessionService>();

if (globalState == null)
{
string path = $"{AppDomain.CurrentDomain.BaseDirectory}/state.json";

if (File.Exists(path))
{
using FileStream fs = new FileStream(path, FileMode.Open);

globalState = JsonSerializer.Deserialize<SteamLoginState>(fs);
}
}
}

[TestCase(2384364)]
[Test]
public async Task TestGetMarketItemOrdersHistogram(long marketItemNameId)
{
var histogram = await SteamMarketService
.GetMarketItemOrdersHistogram(2384364);

Assert.That(histogram.Success, Is.EqualTo(1));
}

[TestCase("730", "AK-47%20%7C%20Safari%20Mesh%20%28Field-Tested%29", 23)]
[Test]
public async Task TestGetMarketItemPriceOverview(string appId, string marketHashName, int currency)
{
var overview = await SteamMarketService
.GetMarketItemPriceOverview(appId, marketHashName, currency);

Assert.That(overview.Success, Is.True);
}
}
1 change: 1 addition & 0 deletions src/BD.SteamClient.UnitTest/SteamServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void TestVdfBenchmark()
TestContext.WriteLine($"ValveKeyValue (VDF) : {sw.ElapsedMilliseconds / numIterations}ms, {sw.ElapsedTicks / numIterations}ticks average");
}

[Ignore("unspport")]
[Test]
public void TestVdfValueEdit()
{
Expand Down
19 changes: 19 additions & 0 deletions src/BD.SteamClient/Enums/MarketTradingHisotryRowType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace BD.SteamClient;

public enum MarketTradingHisotryRowType
{
/// <summary>
/// 普通行
/// </summary>
Normal,

/// <summary>
/// 上架
/// </summary>
Publish,

/// <summary>
/// 下架
/// </summary>
UnPublish,
}
Loading

0 comments on commit 136a80d

Please sign in to comment.