Accorpamento test con setup/cleanup

This commit is contained in:
Samuele E. Locatelli
2019-05-25 08:48:21 +02:00
parent b0d37fe3f1
commit 4a3eb1b919
+26 -132
View File
@@ -10,6 +10,8 @@ namespace MCC_UnitTest
[TestClass]
public class TestSuite
{
#region area oggetti globali
/// <summary>
/// Token x cancellazione thread
/// </summary>
@@ -27,35 +29,41 @@ namespace MCC_UnitTest
/// </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()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// assert
Assert.IsNotNull(MCC);
}
[TestMethod]
public void Test_initSDK_hasResult()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// assert
@@ -64,138 +72,24 @@ namespace MCC_UnitTest
[TestMethod]
public void Test_initSDK_throwNoConfig()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
Task<Result> taskResult = MCC.InitSDKAsync("", CancellationToken.None);
// assert is handled by the ExpectedException
}
[TestMethod]
public void Test_initSDK_callResultOk()
public void Test_initSDK_allPropertyOk()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
reqStatus = taskResult.Result;
// assert
// asserts
Assert.IsTrue(reqStatus.CallResultOk);
}
[TestMethod]
public void Test_initSDK_errorNull()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// init async...
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// converto il risultato restituito...
reqStatus = taskResult.Result;
// assert
Assert.IsNull(reqStatus.Error);
}
[TestMethod]
public void Test_initSDK_localOk()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// init async...
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// converto il risultato restituito...
reqStatus = taskResult.Result;
// assert
Assert.IsTrue(reqStatus.LocalStatusOk);
}
[TestMethod]
public void Test_initSDK_cloudOk()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// init async...
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// converto il risultato restituito...
reqStatus = taskResult.Result;
// assert
Assert.IsTrue(reqStatus.CloudStatusOk);
}
[TestMethod]
public void Test_initSDK_sourceNotNull()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// init async...
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// converto il risultato restituito...
reqStatus = taskResult.Result;
// assert
Assert.IsNotNull(reqStatus.Source);
}
[TestMethod]
public void Test_initSDK_payloadIsNull()
{
// arrange
if (_cts != null)
{
_cts.Cancel();
}
// act
MCC = new MConnectClient();
// init async...
Task<Result> taskResult = MCC.InitSDKAsync(confFilePath, CancellationToken.None);
// converto il risultato restituito...
reqStatus = taskResult.Result;
// assert
Assert.IsNull(reqStatus.Payload);
}