180 lines
4.6 KiB
C#
180 lines
4.6 KiB
C#
using System;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using MConnectSDK;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MCC_UnitTest
|
|
{
|
|
[TestClass]
|
|
public class TestSuite
|
|
{
|
|
/// <summary>
|
|
/// Token x cancellazione thread
|
|
/// </summary>
|
|
private CancellationTokenSource _cts = new CancellationTokenSource();
|
|
/// <summary>
|
|
/// Istanze classe MaestroConnectClient
|
|
/// </summary>
|
|
protected MConnectClient MCC;
|
|
/// <summary>
|
|
/// Risposta BASE della classe di comunicazione
|
|
/// </summary>
|
|
protected Result reqStatus;
|
|
/// <summary>
|
|
/// File conf yaml
|
|
/// </summary>
|
|
protected string confFilePath = "mconnect.conf.yaml";
|
|
|
|
#region metodi interni
|
|
|
|
/// <summary>
|
|
/// Effettua test sui parametri restituiti
|
|
/// </summary>
|
|
private void fixDisplay()
|
|
{
|
|
#if false
|
|
// mostro init SOLO SE ho conf yaml...
|
|
btnInit.Enabled = txtConfFile.Text.Trim() != "";
|
|
// verifico SE ho inizializzato x cui POSSO mostrare alcuni buttons...
|
|
bool enableBtn = (MCC != null);
|
|
btnFlush.Enabled = enableBtn;
|
|
btnTryAuth.Enabled = enableBtn;
|
|
btnTryEnroll.Enabled = enableBtn;
|
|
btnGetClientStatus.Enabled = enableBtn;
|
|
btnGetOrgCode.Enabled = enableBtn;
|
|
btnGetUserList.Enabled = enableBtn;
|
|
btnTryUserLogin.Enabled = enableBtn;
|
|
btnGetUserCreatedList.Enabled = enableBtn;
|
|
btnImportUser.Enabled = enableBtn;
|
|
btnDeleteUserHMI.Enabled = enableBtn;
|
|
// controllo se visualizzare parametri di testing...
|
|
|
|
if (reqStatus != null)
|
|
{
|
|
// se NON enrolled --> abilita tryAuth...
|
|
btnTryAuth.Enabled = !reqStatus.IsAuth;
|
|
btnTryEnroll.Enabled = !reqStatus.IsHmiEnrolled;
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Task x INIT da file di conf
|
|
/// </summary>
|
|
/// <param name="confFilePath"></param>
|
|
/// <returns></returns>
|
|
private async Task doInitAsync(string confFilePath)
|
|
{
|
|
// attendo init...
|
|
await Task.Run(() =>
|
|
{
|
|
// NUOVA istanza da file di conf...
|
|
MCC = new MConnectClient();
|
|
|
|
// init async...
|
|
var taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// salvo il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
#if false
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("--------------------------------------------------");
|
|
sb.AppendLine("InitSDKAsync");
|
|
sb.AppendLine("--------------------------------------------------");
|
|
lblConsole.Text = sb.ToString();
|
|
refreshRequestStatus();
|
|
}), "");
|
|
#endif
|
|
});
|
|
// ora attendo get client...
|
|
await Task.Run(() =>
|
|
{
|
|
// init async...
|
|
var taskResult = MCC.GetClientStatusAsync();
|
|
|
|
// salvo il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
#if false
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("--------------------------------------------------");
|
|
sb.AppendLine("GetClientStatusAsync");
|
|
sb.AppendLine("--------------------------------------------------");
|
|
lblConsole.Text = sb.ToString();
|
|
refreshRequestStatus();
|
|
}), "");
|
|
#endif
|
|
});
|
|
// ora attendo get client...
|
|
await Task.Run(() =>
|
|
{
|
|
#if false
|
|
synchronizationContext.Post(new SendOrPostCallback(o =>
|
|
{
|
|
fixDisplay();
|
|
}), "");
|
|
#endif
|
|
});
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
[TestMethod]
|
|
public void Test_setup_01()
|
|
{
|
|
// reset x iniziare...
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// NUOVA istanza da file di conf...
|
|
MCC = new MConnectClient();
|
|
|
|
// test!
|
|
Assert.IsNotNull(MCC);
|
|
|
|
//// init async...
|
|
//var taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
//// salvo il risultato restituito...
|
|
//reqStatus = taskResult.Result;
|
|
|
|
//// test!
|
|
//Assert.IsNotNull(reqStatus);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Test_init_01()
|
|
{
|
|
// reset x iniziare...
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// NUOVA istanza da file di conf...
|
|
MCC = new MConnectClient();
|
|
|
|
// init async...
|
|
var taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// test!
|
|
Assert.IsNotNull(taskResult.Result);
|
|
|
|
|
|
//// salvo il risultato restituito...
|
|
//reqStatus = taskResult.Result;
|
|
|
|
//// test!
|
|
//Assert.IsNotNull(reqStatus);
|
|
}
|
|
}
|
|
}
|