From 24c5ea3ba98f349bcb05fc3d34c5388e5a7f273d Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 16 Feb 2018 13:42:27 +0100 Subject: [PATCH] SEBWIN-219: Fixed broken unit tests. --- .../Operations/TaskbarOperationTests.cs | 12 ++--- .../ClientControllerTests.cs | 28 +++++++---- .../DelayedInitializationOperationTests.cs | 2 +- .../Operations/ConfigurationOperationTests.cs | 50 +++++++++---------- .../ServiceConnectionOperationTests.cs | 30 +++++------ 5 files changed, 64 insertions(+), 58 deletions(-) diff --git a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs index 700cfcbb..4db84267 100644 --- a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs @@ -23,7 +23,7 @@ namespace SafeExamBrowser.Client.UnitTests.Behaviour.Operations public class TaskbarOperationTests { private Mock loggerMock; - private Mock settingsMock; + private TaskbarSettings settings; private Mock> keyboardLayoutMock; private Mock> powerSupplyMock; private Mock> wirelessNetworkMock; @@ -38,7 +38,7 @@ namespace SafeExamBrowser.Client.UnitTests.Behaviour.Operations public void Initialize() { loggerMock = new Mock(); - settingsMock = new Mock(); + settings = new TaskbarSettings(); keyboardLayoutMock = new Mock>(); powerSupplyMock = new Mock>(); wirelessNetworkMock = new Mock>(); @@ -47,15 +47,15 @@ namespace SafeExamBrowser.Client.UnitTests.Behaviour.Operations textMock = new Mock(); uiFactoryMock = new Mock(); - settingsMock.SetupGet(s => s.AllowApplicationLog).Returns(true); - settingsMock.SetupGet(s => s.AllowKeyboardLayout).Returns(true); - settingsMock.SetupGet(s => s.AllowWirelessNetwork).Returns(true); + settings.AllowApplicationLog = true; + settings.AllowKeyboardLayout = true; + settings.AllowWirelessNetwork = true; systemInfoMock.SetupGet(s => s.HasBattery).Returns(true); uiFactoryMock.Setup(u => u.CreateNotification(It.IsAny())).Returns(new Mock().Object); sut = new TaskbarOperation( loggerMock.Object, - settingsMock.Object, + settings, keyboardLayoutMock.Object, powerSupplyMock.Object, wirelessNetworkMock.Object, diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index f07feb48..fe963b2a 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -9,7 +9,9 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Client.Behaviour; +using SafeExamBrowser.Contracts.Behaviour.Operations; +using SafeExamBrowser.Contracts.Communication; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; @@ -22,10 +24,12 @@ namespace SafeExamBrowser.Client.UnitTests private Mock displayMonitorMock; private Mock loggerMock; private Mock processMonitorMock; + private Mock operationSequenceMock; + private Mock runtimeProxyMock; private Mock taskbarMock; private Mock windowMonitorMock; - //private IClientController sut; + private ClientController sut; [TestInitialize] public void Initialize() @@ -33,19 +37,23 @@ namespace SafeExamBrowser.Client.UnitTests displayMonitorMock = new Mock(); loggerMock = new Mock(); processMonitorMock = new Mock(); + operationSequenceMock = new Mock(); + runtimeProxyMock = new Mock(); taskbarMock = new Mock(); windowMonitorMock= new Mock(); - // TODO + operationSequenceMock.Setup(o => o.TryPerform()).Returns(true); - //sut = new ClientController( - // displayMonitorMock.Object, - // loggerMock.Object, - // processMonitorMock.Object, - // taskbarMock.Object, - // windowMonitorMock.Object); + sut = new ClientController( + displayMonitorMock.Object, + loggerMock.Object, + operationSequenceMock.Object, + processMonitorMock.Object, + runtimeProxyMock.Object, + taskbarMock.Object, + windowMonitorMock.Object); - // sut.Start(); + sut.TryStart(); } [TestMethod] diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs index cb65cb9f..1b31c9ed 100644 --- a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs @@ -14,7 +14,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations public class DelayedInitializationOperationTests { [TestMethod] - public void Todo() + public void TODO() { Assert.Fail(); } diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs index 9117fba3..04ca2dd3 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs @@ -23,9 +23,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public class ConfigurationOperationTests { private Mock logger; - private Mock info; + private RuntimeInfo info; private Mock repository; - private Mock settings; + private Settings settings; private Mock text; private Mock uiFactory; private ConfigurationOperation sut; @@ -34,17 +34,17 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void Initialize() { logger = new Mock(); - info = new Mock(); + info = new RuntimeInfo(); repository = new Mock(); - settings = new Mock(); + settings = new Settings(); text = new Mock(); uiFactory = new Mock(); - info.SetupGet(i => i.AppDataFolder).Returns(@"C:\Not\Really\AppData"); - info.SetupGet(i => i.DefaultSettingsFileName).Returns("SettingsDummy.txt"); - info.SetupGet(i => i.ProgramDataFolder).Returns(@"C:\Not\Really\ProgramData"); - repository.Setup(r => r.LoadSettings(It.IsAny())).Returns(settings.Object); - repository.Setup(r => r.LoadDefaultSettings()).Returns(settings.Object); + info.AppDataFolder = @"C:\Not\Really\AppData"; + info.DefaultSettingsFileName = "SettingsDummy.txt"; + info.ProgramDataFolder = @"C:\Not\Really\ProgramData"; + repository.Setup(r => r.LoadSettings(It.IsAny())).Returns(settings); + repository.Setup(r => r.LoadDefaultSettings()).Returns(settings); } [TestMethod] @@ -52,11 +52,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { repository.Setup(r => r.LoadDefaultSettings()); - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, new string[] { }); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new string[] { }); sut.Perform(); @@ -68,7 +68,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { var path = @"an/invalid\path.'*%yolo/()"; - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, new [] { "blubb.exe", path }); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new [] { "blubb.exe", path }); sut.Perform(); } @@ -79,10 +79,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations var path = @"http://www.safeexambrowser.org/whatever.seb"; var location = Path.GetDirectoryName(GetType().Assembly.Location); - info.SetupGet(r => r.ProgramDataFolder).Returns(location); - info.SetupGet(r => r.AppDataFolder).Returns(location); + info.ProgramDataFolder = location; + info.AppDataFolder = location; - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, new[] { "blubb.exe", path }); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new[] { "blubb.exe", path }); sut.Perform(); @@ -94,10 +94,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { var location = Path.GetDirectoryName(GetType().Assembly.Location); - info.SetupGet(r => r.ProgramDataFolder).Returns(location); - info.SetupGet(r => r.AppDataFolder).Returns($@"{location}\WRONG"); + info.ProgramDataFolder = location; + info.AppDataFolder = $@"{location}\WRONG"; - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); @@ -109,9 +109,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { var location = Path.GetDirectoryName(GetType().Assembly.Location); - info.SetupGet(r => r.AppDataFolder).Returns(location); + info.AppDataFolder = location; - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); @@ -121,7 +121,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations [TestMethod] public void MustFallbackToDefaultsAsLastPrio() { - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); @@ -131,12 +131,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations [TestMethod] public void MustAbortIfWishedByUser() { - var location = Path.GetDirectoryName(GetType().Assembly.Location); - - info.SetupGet(r => r.ProgramDataFolder).Returns(location); + info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location); uiFactory.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.Yes); - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); @@ -148,7 +146,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { uiFactory.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); - sut = new ConfigurationOperation(repository.Object, logger.Object, info.Object, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); sut.Perform(); diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs index ea143ad6..05768eff 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs @@ -45,12 +45,12 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustConnectToService() { service.Setup(s => s.Connect(null)).Returns(true); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); service.Setup(s => s.Connect(null)).Returns(true); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); @@ -61,22 +61,22 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustNotFailIfServiceNotAvailable() { service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); service.Setup(s => s.Connect(null)).Throws(); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); service.Setup(s => s.Connect(null)).Throws(); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); } @@ -85,7 +85,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustAbortIfServiceMandatoryAndNotAvailable() { service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); @@ -96,7 +96,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustNotAbortIfServiceOptionalAndNotAvailable() { service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); @@ -108,13 +108,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustDisconnectWhenReverting() { service.Setup(s => s.Connect(null)).Returns(true); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); sut.Revert(); service.Setup(s => s.Connect(null)).Returns(true); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); sut.Revert(); @@ -127,7 +127,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { service.Setup(s => s.Connect(null)).Returns(true); service.Setup(s => s.Disconnect()).Throws(); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); sut.Revert(); @@ -139,25 +139,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustNotDisconnnectIfNotAvailable() { service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); sut.Revert(); service.Setup(s => s.Connect(null)).Returns(false); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); sut.Revert(); service.Setup(s => s.Connect(null)).Throws(); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Mandatory); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Mandatory }); sut.Perform(); sut.Revert(); service.Setup(s => s.Connect(null)).Throws(); - configuration.SetupGet(s => s.CurrentSettings.ServicePolicy).Returns(ServicePolicy.Optional); + configuration.SetupGet(s => s.CurrentSettings).Returns(new Settings { ServicePolicy = ServicePolicy.Optional }); sut.Perform(); sut.Revert();