SEBWIN-296: Implemented unit test for client configuration operation.
This commit is contained in:
parent
0ccb10ca88
commit
604dad2a28
2 changed files with 43 additions and 21 deletions
|
@ -6,11 +6,15 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
using SafeExamBrowser.Client.Operations;
|
using SafeExamBrowser.Client.Operations;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Data;
|
||||||
using SafeExamBrowser.Contracts.Communication.Proxies;
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||||
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
|
|
||||||
namespace SafeExamBrowser.Client.UnitTests.Operations
|
namespace SafeExamBrowser.Client.UnitTests.Operations
|
||||||
|
@ -34,9 +38,37 @@ namespace SafeExamBrowser.Client.UnitTests.Operations
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TODO()
|
public void MustCorrectlySetConfiguration()
|
||||||
{
|
{
|
||||||
Assert.Fail();
|
var response = new ConfigurationResponse
|
||||||
|
{
|
||||||
|
Configuration = new ClientConfiguration
|
||||||
|
{
|
||||||
|
AppConfig = new AppConfig(),
|
||||||
|
SessionId = Guid.NewGuid(),
|
||||||
|
Settings = new Settings()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
runtime.Setup(r => r.GetConfiguration()).Returns(new CommunicationResult<ConfigurationResponse>(true, response));
|
||||||
|
|
||||||
|
var result = sut.Perform();
|
||||||
|
|
||||||
|
Assert.AreSame(configuration.AppConfig, response.Configuration.AppConfig);
|
||||||
|
Assert.AreEqual(configuration.SessionId, response.Configuration.SessionId);
|
||||||
|
Assert.AreSame(configuration.Settings, response.Configuration.Settings);
|
||||||
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustDoNothingOnRevert()
|
||||||
|
{
|
||||||
|
var result = sut.Revert();
|
||||||
|
|
||||||
|
logger.VerifyNoOtherCalls();
|
||||||
|
runtime.VerifyNoOtherCalls();
|
||||||
|
|
||||||
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using SafeExamBrowser.Contracts.Communication.Proxies;
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
using SafeExamBrowser.Contracts.Core.OperationModel;
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
|
@ -37,26 +36,17 @@ namespace SafeExamBrowser.Client.Operations
|
||||||
logger.Info("Initializing application configuration...");
|
logger.Info("Initializing application configuration...");
|
||||||
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeConfiguration);
|
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeConfiguration);
|
||||||
|
|
||||||
try
|
var communication = runtime.GetConfiguration();
|
||||||
{
|
var config = communication.Value.Configuration;
|
||||||
var communication = runtime.GetConfiguration();
|
|
||||||
var config = communication.Value.Configuration;
|
|
||||||
|
|
||||||
configuration.AppConfig = config.AppConfig;
|
configuration.AppConfig = config.AppConfig;
|
||||||
configuration.SessionId = config.SessionId;
|
configuration.SessionId = config.SessionId;
|
||||||
configuration.Settings = config.Settings;
|
configuration.Settings = config.Settings;
|
||||||
|
|
||||||
logger.Info("Successfully retrieved the application configuration from the runtime.");
|
logger.Info("Successfully retrieved the application configuration from the runtime.");
|
||||||
logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}");
|
logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}");
|
||||||
logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}");
|
logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}");
|
||||||
logger.Info($" -> Session-ID: {configuration.SessionId}");
|
logger.Info($" -> Session-ID: {configuration.SessionId}");
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
logger.Error("An unexpected error occurred while trying to retrieve the application configuration!", e);
|
|
||||||
|
|
||||||
return OperationResult.Failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OperationResult.Success;
|
return OperationResult.Success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue