2019-04-16 19:22:56 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-04-17 15:20:32 +03:00
|
|
|
|
using Steamworks.Data;
|
2019-04-16 19:22:56 +03:00
|
|
|
|
|
|
|
|
|
namespace Steamworks
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
[DeploymentItem( "steam_api64.dll" )]
|
2020-02-19 15:29:07 +03:00
|
|
|
|
[DeploymentItem( "steam_api.dll" )]
|
|
|
|
|
public class UserStatsTest
|
2019-04-16 19:22:56 +03:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2019-05-01 13:47:50 +03:00
|
|
|
|
public async Task AchievementList()
|
2019-04-16 19:22:56 +03:00
|
|
|
|
{
|
|
|
|
|
foreach ( var a in SteamUserStats.Achievements )
|
|
|
|
|
{
|
2019-04-16 22:57:17 +03:00
|
|
|
|
Console.WriteLine( $"{a.Identifier}" );
|
2019-04-16 19:22:56 +03:00
|
|
|
|
Console.WriteLine( $" a.State: {a.State}" );
|
|
|
|
|
Console.WriteLine( $" a.UnlockTime: {a.UnlockTime}" );
|
2019-04-16 22:57:17 +03:00
|
|
|
|
Console.WriteLine( $" a.Name: {a.Name}" );
|
|
|
|
|
Console.WriteLine( $" a.Description: {a.Description}" );
|
2019-04-16 23:16:43 +03:00
|
|
|
|
Console.WriteLine( $" a.GlobalUnlocked: {a.GlobalUnlocked}" );
|
2019-04-16 19:22:56 +03:00
|
|
|
|
|
2019-05-01 13:47:50 +03:00
|
|
|
|
var icon = await a.GetIconAsync();
|
2019-04-16 19:22:56 +03:00
|
|
|
|
|
|
|
|
|
Console.WriteLine( $" a.Icon: {icon}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 23:22:46 +03:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task PlayerCountAsync()
|
|
|
|
|
{
|
|
|
|
|
var players = await SteamUserStats.PlayerCountAsync();
|
|
|
|
|
Assert.AreNotEqual( players, -1 );
|
|
|
|
|
Console.WriteLine( $"players: {players}" );
|
|
|
|
|
}
|
2019-04-26 20:22:44 +03:00
|
|
|
|
|
2019-04-17 10:26:31 +03:00
|
|
|
|
public async Task StoreStats()
|
|
|
|
|
{
|
|
|
|
|
var result = Result.NotSettled;
|
|
|
|
|
|
|
|
|
|
SteamUserStats.OnUserStatsStored += ( r ) =>
|
|
|
|
|
{
|
|
|
|
|
result = r;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SteamUserStats.StoreStats();
|
|
|
|
|
|
|
|
|
|
while ( result == Result.NotSettled )
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay( 10 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual( result, Result.OK );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 11:31:28 +03:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task CreateLeaderboard()
|
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindOrCreateLeaderboardAsync( "Testleaderboard", Data.LeaderboardSort.Ascending, Data.LeaderboardDisplay.Numeric );
|
2019-04-17 11:31:28 +03:00
|
|
|
|
|
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task FindLeaderboard()
|
2019-04-17 12:34:47 +03:00
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task SubmitScore()
|
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var result = await leaderboard.Value.SubmitScoreAsync( 576 );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Assert.IsTrue( result.HasValue );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"result.Changed: {result?.Changed}" );
|
|
|
|
|
Console.WriteLine( $"result.OldGlobalRank: {result?.OldGlobalRank}" );
|
|
|
|
|
Console.WriteLine( $"result.NewGlobalRank: {result?.NewGlobalRank}" );
|
|
|
|
|
Console.WriteLine( $"result.RankChange: {result?.RankChange}" );
|
|
|
|
|
Console.WriteLine( $"result.Score: {result?.Score}" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task ReplaceScore()
|
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
|
|
|
|
|
var result = await leaderboard.Value.ReplaceScore( 576 );
|
|
|
|
|
Assert.IsTrue( result.HasValue );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"result.Changed: {result?.Changed}" );
|
|
|
|
|
Console.WriteLine( $"result.OldGlobalRank: {result?.OldGlobalRank}" );
|
|
|
|
|
Console.WriteLine( $"result.NewGlobalRank: {result?.NewGlobalRank}" );
|
|
|
|
|
Console.WriteLine( $"result.RankChange: {result?.RankChange}" );
|
|
|
|
|
Console.WriteLine( $"result.Score: {result?.Score}" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetScoresFromFriends()
|
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var friendScores = await leaderboard.Value.GetScoresFromFriendsAsync();
|
2019-04-17 12:34:47 +03:00
|
|
|
|
|
|
|
|
|
foreach ( var e in friendScores )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetScoresAroundUserAsync()
|
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
|
2019-05-01 10:45:11 +03:00
|
|
|
|
for ( int i = 1; i < 10; i++ )
|
2019-04-17 12:34:47 +03:00
|
|
|
|
{
|
2019-05-01 10:45:11 +03:00
|
|
|
|
// Get entries around user
|
|
|
|
|
var relativeScores = await leaderboard.Value.GetScoresAroundUserAsync( -i, i );
|
|
|
|
|
Assert.IsNotNull( relativeScores );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"" );
|
|
|
|
|
Console.WriteLine( $"Relative Scores:" );
|
|
|
|
|
foreach ( var e in relativeScores )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" );
|
|
|
|
|
}
|
2019-04-17 12:34:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetScoresAsync()
|
2019-04-17 11:31:28 +03:00
|
|
|
|
{
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var leaderboard = await SteamUserStats.FindLeaderboardAsync( "Testleaderboard" );
|
2019-04-17 11:31:28 +03:00
|
|
|
|
Assert.IsTrue( leaderboard.HasValue );
|
|
|
|
|
|
|
|
|
|
// Get top 20 global scores
|
2019-04-17 12:34:47 +03:00
|
|
|
|
var globalsScores = await leaderboard.Value.GetScoresAsync( 20 );
|
2019-04-17 11:31:28 +03:00
|
|
|
|
Assert.IsNotNull( globalsScores );
|
|
|
|
|
|
2019-04-17 12:34:47 +03:00
|
|
|
|
Console.WriteLine( $"" );
|
|
|
|
|
Console.WriteLine( $"Global Scores:" );
|
2019-04-17 11:31:28 +03:00
|
|
|
|
foreach ( var e in globalsScores )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 15:20:32 +03:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void GetStatInt()
|
|
|
|
|
{
|
2019-04-27 18:12:16 +03:00
|
|
|
|
var deaths = new Stat( "deaths" );
|
|
|
|
|
Console.WriteLine( $"{deaths.Name} {deaths.GetInt()} times" );
|
|
|
|
|
Console.WriteLine( $"{deaths.Name} {deaths.GetFloat()} times" );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
|
2019-04-27 18:12:16 +03:00
|
|
|
|
Assert.AreNotEqual( 0, deaths.GetInt() );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetStatGlobalInt()
|
|
|
|
|
{
|
2019-04-27 18:12:16 +03:00
|
|
|
|
var deaths = new Stat( "deaths" );
|
2019-05-27 12:54:30 +03:00
|
|
|
|
await deaths.GetGlobalIntDaysAsync( 5 );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
|
2019-04-27 18:12:16 +03:00
|
|
|
|
var totalStartups = deaths.GetGlobalInt();
|
2019-04-17 15:20:32 +03:00
|
|
|
|
Assert.AreNotEqual( 0, totalStartups );
|
2019-04-27 18:12:16 +03:00
|
|
|
|
Console.WriteLine( $"Rust has had {totalStartups} deaths" );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetStatGlobalHistoryInt()
|
|
|
|
|
{
|
2019-04-27 18:12:16 +03:00
|
|
|
|
var deaths = new Stat( "deaths" );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
|
2019-05-27 12:54:30 +03:00
|
|
|
|
var history = await deaths.GetGlobalIntDaysAsync( 10 );
|
2019-04-17 15:33:38 +03:00
|
|
|
|
Assert.AreNotEqual( 0, history.Length );
|
2019-04-17 15:20:32 +03:00
|
|
|
|
|
2019-04-17 15:33:38 +03:00
|
|
|
|
for ( int i=0; i< history.Length; i++ )
|
2019-04-17 15:20:32 +03:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{i} : {history[i]}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-16 23:22:46 +03:00
|
|
|
|
|
2019-04-16 19:22:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|