Facepunch.Steamworks/Facepunch.Steamworks.Test/InventoryTest.cs

76 lines
1.6 KiB
C#
Raw Normal View History

2019-04-27 17:56:11 +03:00
using System;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Steamworks.Data;
namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class InventoryTest
{
[TestMethod]
2019-04-27 23:52:47 +03:00
public async Task LoadItemDefinitionsAsync()
{
var result = await SteamInventory.WaitForDefinitions( 5 );
Assert.IsTrue( result );
result = await SteamInventory.WaitForDefinitions( 5 );
Assert.IsTrue( result );
}
[TestMethod]
public async Task GetDefinitions()
2019-04-27 17:56:11 +03:00
{
2019-04-27 23:52:47 +03:00
await SteamInventory.WaitForDefinitions();
Assert.IsNotNull( SteamInventory.Definitions );
2019-04-27 17:56:11 +03:00
2019-04-27 23:52:47 +03:00
foreach ( var def in SteamInventory.Definitions )
2019-04-27 19:07:39 +03:00
{
2019-04-27 23:52:47 +03:00
Console.WriteLine( $"[{def.Id:0000000000}] {def.Name} [{def.Type}]" );
2019-04-27 19:07:39 +03:00
}
}
[TestMethod]
2019-04-27 23:52:47 +03:00
public async Task GetDefinitionsWithPrices()
2019-04-27 19:07:39 +03:00
{
2019-04-27 23:52:47 +03:00
var defs = await SteamInventory.GetDefinitionsWithPricesAsync();
2019-04-27 19:07:39 +03:00
2019-04-27 23:52:47 +03:00
foreach ( var def in defs )
2019-04-27 19:07:39 +03:00
{
2019-04-27 23:52:47 +03:00
Console.WriteLine( $"[{def.Id:0000000000}] {def.Name} [{def.LocalPriceFormatted}]" );
2019-04-27 19:07:39 +03:00
}
2019-04-27 17:56:11 +03:00
}
2019-04-29 13:05:55 +03:00
[TestMethod]
public async Task GetAllItems()
{
await SteamInventory.WaitForDefinitions();
var result = await SteamInventory.GetItems();
Assert.IsTrue( result.HasValue );
using ( result )
{
var items = result?.GetItems( true );
foreach ( var item in items )
{
2019-04-29 13:21:59 +03:00
Console.WriteLine( $"{item.Id} / {item.DefId} / {item.Quantity} / {item.Def.Name} " );
2019-04-29 13:05:55 +03:00
foreach ( var prop in item.Properties )
{
Console.WriteLine( $" {prop.Key} : {prop.Value}" );
}
}
}
}
2019-04-27 17:56:11 +03:00
}
}