Facepunch.Steamworks/Facepunch.Steamworks.Test/UgcQuery.cs

132 lines
3.5 KiB
C#
Raw Normal View History

2019-04-17 18:41:06 +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" )]
2020-02-19 15:29:07 +03:00
[DeploymentItem( "steam_api.dll" )]
public class UgcQueryTests
2019-04-17 18:41:06 +03:00
{
[TestMethod]
public async Task QueryAll()
{
2019-04-26 15:46:12 +03:00
var q = Ugc.Query.All;
2019-04-17 18:41:06 +03:00
var result = await q.GetPageAsync( 1 );
Assert.IsNotNull( result );
Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
Console.WriteLine( $"TotalCount: {result?.TotalCount}" );
}
2019-04-26 14:22:27 +03:00
[TestMethod]
public async Task QueryWithTags()
{
2019-04-26 15:46:12 +03:00
var q = Ugc.Query.All
2019-05-08 13:12:39 +03:00
.WithTag( "Version3" )
.WithTag( "Hunting Bow" )
2019-04-26 14:22:27 +03:00
.MatchAllTags();
var result = await q.GetPageAsync( 1 );
Assert.IsNotNull( result );
2019-05-08 13:12:39 +03:00
Assert.IsTrue( result?.ResultCount > 0 );
2019-04-26 14:22:27 +03:00
Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
Console.WriteLine( $"TotalCount: {result?.TotalCount}" );
foreach ( var entry in result.Value.Entries )
{
2019-05-08 13:12:39 +03:00
Assert.IsTrue( entry.HasTag( "Version3" ), "Has Tag Version3" );
Assert.IsTrue( entry.HasTag( "Hunting Bow" ), "Has Tag HuntingBow" );
2019-04-26 14:22:27 +03:00
}
}
2019-04-17 18:41:06 +03:00
[TestMethod]
public async Task QueryAllFromFriends()
{
2019-04-26 15:46:12 +03:00
var q = Ugc.Query.All
2019-04-17 18:41:06 +03:00
.CreatedByFriends();
var result = await q.GetPageAsync( 1 );
Assert.IsNotNull( result );
Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
Console.WriteLine( $"TotalCount: {result?.TotalCount}" );
foreach ( var entry in result.Value.Entries )
{
Console.WriteLine( $" {entry.Title}" );
}
}
2019-04-26 15:46:12 +03:00
[TestMethod]
public async Task QueryUserOwn()
{
var q = Ugc.Query.All
2019-05-13 11:21:20 +03:00
.WhereUserPublished();
2019-04-26 15:46:12 +03:00
var result = await q.GetPageAsync( 1 );
Assert.IsNotNull( result );
Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
Console.WriteLine( $"TotalCount: {result?.TotalCount}" );
foreach ( var entry in result.Value.Entries )
{
Console.WriteLine( $" {entry.Title}" );
}
}
[TestMethod]
2019-05-08 13:12:39 +03:00
public async Task QueryGarry()
2019-04-26 15:46:12 +03:00
{
var q = Ugc.Query.All
2019-05-13 11:21:20 +03:00
.WhereUserPublished( 76561197960279927 );
2019-04-26 15:46:12 +03:00
var result = await q.GetPageAsync( 1 );
Assert.IsNotNull( result );
2019-05-08 13:12:39 +03:00
Assert.IsTrue( result?.ResultCount > 0 );
2019-04-26 15:46:12 +03:00
Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
Console.WriteLine( $"TotalCount: {result?.TotalCount}" );
foreach ( var entry in result.Value.Entries )
{
Console.WriteLine( $" {entry.Title}" );
}
}
2019-05-08 11:40:42 +03:00
[TestMethod]
public async Task QuerySpecificFile()
{
2019-05-08 13:18:56 +03:00
var item = await SteamUGC.QueryFileAsync( 1734427277 );
2019-05-08 11:40:42 +03:00
Assert.IsTrue( item.HasValue );
Assert.IsNotNull( item.Value.Title );
Console.WriteLine( $"Title: {item?.Title}" );
Console.WriteLine( $"Desc: {item?.Description}" );
Console.WriteLine( $"Tags: {string.Join( ",", item?.Tags )}" );
Console.WriteLine( $"Author: {item?.Owner.Name} [{item?.Owner.Id}]" );
Console.WriteLine( $"PreviewImageUrl: {item?.PreviewImageUrl}" );
Console.WriteLine( $"NumComments: {item?.NumComments}" );
Console.WriteLine( $"Url: {item?.Url}" );
Console.WriteLine( $"Directory: {item?.Directory}" );
Console.WriteLine( $"IsInstalled: {item?.IsInstalled}" );
Console.WriteLine( $"IsAcceptedForUse: {item?.IsAcceptedForUse}" );
Console.WriteLine( $"IsPublic: {item?.IsPublic}" );
Console.WriteLine( $"Created: {item?.Created}" );
Console.WriteLine( $"Updated: {item?.Updated}" );
Console.WriteLine( $"Score: {item?.Score}" );
}
2019-04-17 18:41:06 +03:00
}
}