184 lines
3.7 KiB
C#
184 lines
3.7 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
|
|
{
|
|
|
|
#region area oggetti globali
|
|
/// <summary>
|
|
/// Token x cancellazione thread
|
|
/// </summary>
|
|
private CancellationTokenSource _cts = new CancellationTokenSource();
|
|
/// <summary>
|
|
/// Istanza 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";
|
|
|
|
[TestInitialize]
|
|
public void Initialize()
|
|
{
|
|
// arrange
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// act (COMMON)
|
|
MCC = new MConnectClient();
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void Cleanup()
|
|
{
|
|
MCC = null;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region BASE ed INIT
|
|
|
|
[TestMethod]
|
|
[Timeout(5000)] // Milliseconds
|
|
public void Test_Create_MCC()
|
|
{
|
|
// assert
|
|
Assert.IsNotNull(MCC);
|
|
}
|
|
[TestMethod]
|
|
public void Test_initSDK_hasResult()
|
|
{
|
|
// act
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// assert
|
|
Assert.IsNotNull(taskResult.Result);
|
|
}
|
|
[TestMethod]
|
|
public void Test_initSDK_throwNoConfig()
|
|
{
|
|
// act
|
|
Task<Result> taskResult = MCC.InitSDKAsync("", CancellationToken.None);
|
|
|
|
// assert is handled by the ExpectedException
|
|
}
|
|
[TestMethod]
|
|
public void Test_initSDK_allPropertyOk()
|
|
{
|
|
// act
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.IsTrue(reqStatus.CallResultOk);
|
|
Assert.IsNull(reqStatus.Error);
|
|
Assert.IsTrue(reqStatus.LocalStatusOk);
|
|
Assert.IsTrue(reqStatus.CloudStatusOk);
|
|
Assert.IsNotNull(reqStatus.Source);
|
|
Assert.IsNull(reqStatus.Payload);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Test reset REDIS
|
|
#if false
|
|
|
|
[TestMethod]
|
|
public void Test_RedisReset()
|
|
{
|
|
// arrange
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// act
|
|
//MCC.forceRedisFlush();
|
|
//MCC = null;
|
|
MCC = new MConnectClient();
|
|
|
|
// init async...
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// converto il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
// assert
|
|
Assert.IsTrue(reqStatus.IsAuth);
|
|
}
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
#region Test AUTH + ENROLL
|
|
|
|
[TestMethod]
|
|
public void Test_isAuth()
|
|
{
|
|
// arrange
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// act
|
|
//MCC.forceRedisFlush();
|
|
//MCC = null;
|
|
MCC = new MConnectClient();
|
|
|
|
// init async...
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// converto il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
// assert
|
|
Assert.IsTrue(reqStatus.IsAuth);
|
|
}
|
|
[TestMethod]
|
|
public void Test_isHmiEnrolled()
|
|
{
|
|
// arrange
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// act
|
|
//MCC.forceRedisFlush();
|
|
//MCC = null;
|
|
MCC = new MConnectClient();
|
|
|
|
// init async...
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// converto il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
// assert
|
|
Assert.IsTrue(reqStatus.IsHmiEnrolled);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Test INFO UTENTI
|
|
|
|
#endregion
|
|
}
|
|
}
|