borepin/FabAccessAPI_Test/FabAccessAPITests.cs

67 lines
2.2 KiB
C#
Raw Normal View History

2020-12-19 21:04:17 +01:00
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 {
2020-12-21 13:44:29 +01:00
#region Log
private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
2020-12-19 21:04:17 +01:00
private static ILoggerFactory _loggerFactory;
2020-12-21 13:44:29 +01:00
private Connection _connection;
2020-12-19 21:04:17 +01:00
[OneTimeSetUp]
2020-12-21 13:44:29 +01:00
public void InitialSetup() {
2020-12-19 21:04:17 +01:00
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;
}
2020-12-21 13:44:29 +01:00
[SetUp]
public void Setup() {
var rpcClient = new TcpRpcClient();
2021-01-30 21:15:28 +01:00
rpcClient.Connect("[::1]", 59661);
2020-12-21 13:44:29 +01:00
_connection = new Connection(rpcClient);
}
[TearDown]
public void Teardown() {
_connection.RpcClient?.Dispose();
_connection = null;
}
2020-12-19 21:04:17 +01:00
[Test]
public void Connect() {
2020-12-21 13:44:29 +01:00
Assert.AreEqual(ConnectionState.Active, _connection.RpcClient.State);
}
2021-01-30 21:15:28 +01:00
2020-12-21 13:44:29 +01:00
[Test]
public async Task Authenticate() {
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
2020-12-19 21:04:17 +01:00
}
[Test]
public async Task Machines() {
2020-12-21 13:44:29 +01:00
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
var machines = await _connection.AccessMachines();
2020-12-19 21:04:17 +01:00
2020-12-21 13:44:29 +01:00
var testmachine = await machines.GetMachine("Testmachine");
Assert.NotNull(testmachine);
var minfo = await testmachine.GetMInfo();
Assert.NotNull(minfo);
2021-01-29 22:54:35 +01:00
_Log.Info($"Name: {minfo.Name}, Description: {minfo.Description}, State: {minfo.State}");
2020-12-19 21:04:17 +01:00
}
}
}