204 lines
4.6 KiB
C#
204 lines
4.6 KiB
C#
using System;
|
|
using Xunit;
|
|
using MConnectSDK;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MCC_xUnitTest
|
|
{
|
|
public class UnitTestSuite
|
|
{
|
|
#region area oggetti globali
|
|
|
|
/// <summary>
|
|
/// Token x cancellazione thread
|
|
/// </summary>
|
|
protected CancellationTokenSource _cts = new CancellationTokenSource();
|
|
/// <summary>
|
|
/// Istanza classe MaestroConnectClient
|
|
/// </summary>
|
|
public MConnectClient MCC;
|
|
/// <summary>
|
|
/// Risposta BASE della classe di comunicazione
|
|
/// </summary>
|
|
protected Result reqStatus;
|
|
/// <summary>
|
|
/// File conf yaml
|
|
/// </summary>
|
|
protected string confFilePath = "mconnect.conf.yaml";
|
|
|
|
/// <summary>
|
|
/// Restituisce un oggetto MCC inizializzato di base
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MConnectClient getNewMCC()
|
|
{
|
|
// arrange
|
|
if (_cts != null)
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
|
|
// act (COMMON)
|
|
MCC = new MConnectClient();
|
|
return MCC;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
[Fact]
|
|
[Trait("Category", "Init")]
|
|
public void Test_Create_MCC()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
|
|
// assert
|
|
Assert.NotNull(MCC);
|
|
}
|
|
|
|
[Fact]
|
|
[Trait("Category", "Init")]
|
|
public void Test_initSDK_hasResult()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// assert
|
|
Assert.NotNull(taskResult.Result);
|
|
}
|
|
|
|
[Fact]
|
|
[Trait("Category", "Init")]
|
|
public void Test_initSDK_throwNoConfig()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync("", CancellationToken.None);
|
|
|
|
// assert is handled by the ExpectedException
|
|
Action actual = () => taskResult.Result.ToString();
|
|
|
|
|
|
// assert
|
|
Assert.Throws<AggregateException>(actual);
|
|
}
|
|
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_callResultOk()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.True(reqStatus.CallResultOk);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_error()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.Null(reqStatus.Error);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_localOk()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.True(reqStatus.LocalStatusOk);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_cloudOk()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.True(reqStatus.CloudStatusOk);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_sourceOk()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.NotNull(reqStatus.Source);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "InitResult")]
|
|
public void Test_initSDK_payloadOk()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
reqStatus = taskResult.Result;
|
|
|
|
// asserts
|
|
Assert.Null(reqStatus.Payload);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Trait("Category", "OAuth")]
|
|
public void Test_isAuth()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
//MCC.forceRedisFlush();
|
|
// init async...
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// converto il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
// assert
|
|
Assert.True(reqStatus.IsAuth);
|
|
}
|
|
[Fact]
|
|
[Trait("Category", "OAuth")]
|
|
public void Test_isHmiEnrolled()
|
|
{
|
|
// act
|
|
MCC = getNewMCC();
|
|
//MCC.forceRedisFlush();
|
|
// init async...
|
|
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
|
|
|
|
// converto il risultato restituito...
|
|
reqStatus = taskResult.Result;
|
|
|
|
// assert
|
|
Assert.True(reqStatus.IsHmiEnrolled);
|
|
}
|
|
|
|
|
|
|
|
#region Test INFO UTENTI
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|