From 604dad2a287a9a2d6799d1a065c74c9e2720dde8 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Tue, 12 Feb 2019 14:17:56 +0100 Subject: [PATCH] SEBWIN-296: Implemented unit test for client configuration operation. --- .../Operations/ConfigurationOperationTests.cs | 36 +++++++++++++++++-- .../Operations/ConfigurationOperation.cs | 28 +++++---------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs index d8c88eb7..2836f5c5 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs @@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; +using SafeExamBrowser.Contracts.Communication.Data; using SafeExamBrowser.Contracts.Communication.Proxies; using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Logging; namespace SafeExamBrowser.Client.UnitTests.Operations @@ -34,9 +38,37 @@ namespace SafeExamBrowser.Client.UnitTests.Operations } [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(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); } } } diff --git a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs index 97aa08a2..2a15b38c 100644 --- a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs +++ b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; using SafeExamBrowser.Contracts.Communication.Proxies; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Core.OperationModel; @@ -37,26 +36,17 @@ namespace SafeExamBrowser.Client.Operations logger.Info("Initializing application configuration..."); 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.SessionId = config.SessionId; - configuration.Settings = config.Settings; + configuration.AppConfig = config.AppConfig; + configuration.SessionId = config.SessionId; + configuration.Settings = config.Settings; - logger.Info("Successfully retrieved the application configuration from the runtime."); - logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}"); - logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}"); - 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; - } + logger.Info("Successfully retrieved the application configuration from the runtime."); + logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}"); + logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}"); + logger.Info($" -> Session-ID: {configuration.SessionId}"); return OperationResult.Success; }