Facepunch.Steamworks/Facepunch.Steamworks.Test/Client/FriendsTest.cs

174 lines
4.7 KiB
C#
Raw Normal View History

2016-09-30 14:59:03 +03:00
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
2016-09-30 15:49:11 +03:00
using System.Linq;
2019-04-15 18:43:55 +03:00
using System.Threading.Tasks;
2016-09-30 14:59:03 +03:00
2019-04-15 17:41:01 +03:00
namespace Steamworks
2016-09-30 14:59:03 +03:00
{
2016-10-25 12:29:35 +03:00
[DeploymentItem( "steam_api64.dll" )]
2016-09-30 14:59:03 +03:00
[TestClass]
2019-04-15 17:41:01 +03:00
public class FriendsTest
2016-09-30 14:59:03 +03:00
{
[TestMethod]
2019-04-15 17:41:01 +03:00
public void GetFriends()
2016-09-30 14:59:03 +03:00
{
2019-04-15 17:41:01 +03:00
foreach ( var friend in Friends.GetFriends() )
{
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory)}" );
2016-09-30 14:59:03 +03:00
2019-04-15 17:41:01 +03:00
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
}
2016-09-30 14:59:03 +03:00
}
2019-04-15 17:41:01 +03:00
[TestMethod]
public void GetBlocked()
{
foreach ( var friend in Friends.GetBlocked() )
{
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
}
}
[TestMethod]
public void GetPlayedWith()
{
foreach ( var friend in Friends.GetPlayedWith() )
{
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
}
}
2019-04-15 18:43:55 +03:00
[TestMethod]
public async Task LargeAvatar()
{
ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
var image = await Friends.GetLargeAvatarAsync( id );
if ( !image.HasValue )
return;
Console.WriteLine( $"image.Width {image.Value.Width}" );
Console.WriteLine( $"image.Height {image.Value.Height}" );
DrawImage( image.Value );
}
[TestMethod]
public async Task MediumAvatar()
{
ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
Console.WriteLine( $"Steam: http://steamcommunity.com/profiles/{id}" );
var image = await Friends.GetMediumAvatarAsync( id );
if ( !image.HasValue )
return;
Console.WriteLine( $"image.Width {image.Value.Width}" );
Console.WriteLine( $"image.Height {image.Value.Height}" );
DrawImage( image.Value );
}
[TestMethod]
public async Task SmallAvatar()
{
ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
var image = await Friends.GetSmallAvatarAsync( id );
if ( !image.HasValue )
return;
Console.WriteLine( $"image.Width {image.Value.Width}" );
Console.WriteLine( $"image.Height {image.Value.Height}" );
DrawImage( image.Value );
}
[TestMethod]
public async Task GetFriendsAvatars()
{
foreach ( var friend in Friends.GetFriends() )
{
Console.WriteLine( $"{friend.Id.Value}: {friend.Name}" );
var image = await friend.GetSmallAvatarAsync();
if ( image.HasValue )
{
DrawImage( image.Value );
}
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
}
}
2019-04-15 17:41:01 +03:00
/*
2016-09-30 14:59:03 +03:00
[TestMethod]
public void FriendListWithoutRefresh()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
2016-10-05 14:44:01 +03:00
Assert.IsTrue( client.IsValid );
2016-09-30 14:59:03 +03:00
foreach ( var friend in client.Friends.All )
{
Console.WriteLine( "{0}: {1} (Friend:{2}) (Blocked:{3})", friend.Id, friend.Name, friend.IsFriend, friend.IsBlocked );
}
}
}
2016-09-30 15:49:11 +03:00
[TestMethod]
public void CachedAvatar()
{
using (var client = new Facepunch.Steamworks.Client(252490))
{
Assert.IsTrue(client.IsValid);
2016-09-30 15:49:11 +03:00
var friend = client.Friends.All.First();
var image = client.Friends.GetCachedAvatar( Steamworks.Friends.AvatarSize.Medium, friend.Id );
if (image != null)
{
Assert.AreEqual(image.Width, 64);
Assert.AreEqual(image.Height, 64);
Assert.AreEqual(image.Data.Length, image.Width * image.Height * 4);
}
2016-09-30 15:49:11 +03:00
}
}
2019-04-15 18:43:55 +03:00
*/
public static void DrawImage( Image img )
2016-09-30 15:49:11 +03:00
{
var grad = " -:+#";
for ( int y = 0; y<img.Height; y++ )
{
var str = "";
for ( int x = 0; x < img.Width; x++ )
{
var p = img.GetPixel( x, y );
var brightness = 1 - ((float)(p.r + p.g + p.b) / (255.0f * 3.0f));
var c = (int) ((grad.Length) * brightness);
2018-02-15 15:32:01 +03:00
if ( c > 3 ) c = 3;
2016-09-30 15:49:11 +03:00
str += grad[c];
}
Console.WriteLine( str );
}
}
2019-04-15 18:43:55 +03:00
2019-04-15 17:41:01 +03:00
}
2016-09-30 14:59:03 +03:00
}