mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 07:11:56 +01:00
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using FabAccessAPI;
|
|
using Capnp;
|
|
using Capnp.Rpc;
|
|
using log4net.Config;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace FabAccessAPI_Test {
|
|
public class Tests {
|
|
#region Log
|
|
private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
|
|
private static ILoggerFactory _loggerFactory;
|
|
private Connection _connection;
|
|
|
|
[OneTimeSetUp]
|
|
public void InitialSetup() {
|
|
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
|
|
_loggerFactory = LoggerFactory.Create(builder => {
|
|
builder
|
|
.AddFilter("Microsoft", LogLevel.Warning)
|
|
.AddFilter("System", LogLevel.Warning);
|
|
});
|
|
_loggerFactory.AddLog4Net();
|
|
Logging.LoggerFactory = _loggerFactory;
|
|
}
|
|
|
|
[SetUp]
|
|
public void Setup() {
|
|
var rpcClient = new TcpRpcClient();
|
|
rpcClient.Connect("127.0.0.1", 59661);
|
|
_connection = new Connection(rpcClient);
|
|
}
|
|
|
|
[TearDown]
|
|
public void Teardown() {
|
|
_connection.RpcClient?.Dispose();
|
|
_connection = null;
|
|
}
|
|
|
|
[Test]
|
|
public void Connect() {
|
|
Assert.AreEqual(ConnectionState.Active, _connection.RpcClient.State);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Authenticate() {
|
|
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Machines() {
|
|
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
|
|
var machines = await _connection.AccessMachines();
|
|
|
|
var testmachine = await machines.GetMachine("Testmachine");
|
|
Assert.NotNull(testmachine);
|
|
var minfo = await testmachine.GetMInfo();
|
|
Assert.NotNull(minfo);
|
|
_Log.Info($"Name: {minfo.Name}, Description: {minfo.Description}, State: {minfo.State.ToString()}");
|
|
}
|
|
}
|
|
} |