mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 23:31:48 +01:00
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using Capnp.Rpc;
|
|
using NUnit.Framework;
|
|
using System;
|
|
|
|
namespace FabAccessAPI_Test
|
|
{
|
|
public class ConnectionTest
|
|
{
|
|
[Test, Repeat(10)]
|
|
public void IPv4()
|
|
{
|
|
UriBuilder builder = new UriBuilder();
|
|
builder.Host = "127.0.0.1";
|
|
builder.Port = 59661;
|
|
|
|
Uri uri = builder.Uri;
|
|
|
|
TcpRpcClient rpcClient = new TcpRpcClient();
|
|
|
|
rpcClient.Connect(uri.Host, uri.Port);
|
|
|
|
while (rpcClient.State == ConnectionState.Initializing);
|
|
|
|
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
|
|
|
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
|
|
|
rpcClient.Dispose();
|
|
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
|
}
|
|
|
|
[Test, Repeat(10)]
|
|
public void IPv6()
|
|
{
|
|
UriBuilder builder = new UriBuilder();
|
|
builder.Host = "[::1]";
|
|
builder.Port = 59661;
|
|
|
|
Uri uri = builder.Uri;
|
|
|
|
TcpRpcClient rpcClient = new TcpRpcClient();
|
|
|
|
rpcClient.Connect(uri.Host, uri.Port);
|
|
|
|
while (rpcClient.State == ConnectionState.Initializing) ;
|
|
|
|
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
|
|
|
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
|
|
|
rpcClient.Dispose();
|
|
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
|
}
|
|
|
|
[Test, Repeat(10)]
|
|
public void DoubleConnect()
|
|
{
|
|
TcpRpcClient rpcClient = new TcpRpcClient();
|
|
|
|
rpcClient.Connect("127.0.0.1", 59661);
|
|
|
|
while (rpcClient.State == ConnectionState.Initializing) ;
|
|
|
|
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
|
|
|
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
|
|
|
rpcClient.Dispose();
|
|
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
|
|
|
rpcClient = new TcpRpcClient();
|
|
|
|
rpcClient.Connect("127.0.0.1", 59661);
|
|
|
|
connection = new FabAccessAPI.Connection(rpcClient);
|
|
while (rpcClient.State == ConnectionState.Initializing) ;
|
|
|
|
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
|
|
|
rpcClient.Dispose();
|
|
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
|
}
|
|
}
|
|
}
|