Facepunch.Steamworks/Facepunch.Steamworks.Test/ServerlistTest.cs

146 lines
3.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2018-03-21 16:11:25 +03:00
using System.Net;
using System.Text;
using System.Threading;
2019-04-15 16:07:31 +03:00
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
2019-04-15 16:07:31 +03:00
namespace Steamworks
{
[TestClass]
2016-10-25 12:29:35 +03:00
[DeploymentItem( "steam_api64.dll" )]
2019-04-15 16:07:31 +03:00
public partial class ServerListTest
{
2018-03-21 16:11:25 +03:00
[TestMethod]
public void IpAddressConversions()
{
var ipstr = "185.38.150.40";
var ip = IPAddress.Parse( ipstr );
2019-04-16 13:45:44 +03:00
var ip_int = Utility.IpToInt32( ip );
2018-03-21 16:11:25 +03:00
2019-04-16 13:45:44 +03:00
var ip_back = Utility.Int32ToIp( ip_int );
2018-03-21 16:11:25 +03:00
Console.WriteLine( "ipstr: " + ipstr );
Console.WriteLine( "ip: " + ip );
Console.WriteLine( "ip int: " + ip_int );
Console.WriteLine( "ip_back: " + ip_back );
}
[TestMethod]
2019-04-15 16:07:31 +03:00
public async Task ServerListInternetInterupted()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.Internet() )
2019-04-15 16:07:31 +03:00
{
var task = list.RunQueryAsync();
await Task.Delay( 1000 );
Console.WriteLine( $"Querying.." );
list.Cancel();
foreach ( var s in list.Responsive )
{
Console.WriteLine( $"{s.Address} {s.Name}" );
}
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
Console.WriteLine( $"task.IsCompleted {task.IsCompleted}" );
}
}
[TestMethod]
public async Task ServerListInternet()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.Internet() )
2019-04-15 16:07:31 +03:00
{
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
}
}
[TestMethod]
public async Task ServerListLan()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.LocalNetwork() )
2019-04-15 16:07:31 +03:00
{
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
}
}
[TestMethod]
public async Task ServerListFavourites()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.Favourites() )
2019-04-15 16:07:31 +03:00
{
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
}
}
[TestMethod]
public async Task ServerListFriends()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.Friends() )
2019-04-15 16:07:31 +03:00
{
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
}
}
[TestMethod]
public async Task ServerListHistory()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.History() )
2019-04-15 16:07:31 +03:00
{
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
}
}
[TestMethod]
public async Task FilterByMap()
{
2019-04-16 16:51:37 +03:00
using ( var list = new ServerList.Internet() )
2019-04-15 16:07:31 +03:00
{
list.AddFilter( "map", "de_dust" );
var success = await list.RunQueryAsync();
Console.WriteLine( $"success {success}" );
Console.WriteLine( $"Found {list.Responsive.Count} Responsive Servers" );
Console.WriteLine( $"Found {list.Unresponsive.Count} Unresponsive Servers" );
foreach ( var server in list.Responsive )
{
Assert.AreEqual( server.Map.ToLower(), "de_dust" );
Console.WriteLine( $"[{server.Map}] - {server.Name}" );
}
}
}
}
}