From 91a8e4d6e4ab2f8a0921f570579869b74d431945 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 11 Oct 2017 11:46:39 +0200 Subject: [PATCH] SEBWIN-183: Implemented unit tests for startup-/shutdown-operations. --- .../Operations/BrowserOperationTests.cs | 72 +++++++++++++++ .../Operations/ClipboardOperationTests.cs | 56 ++++++++++++ .../DisplayMonitorOperationTests.cs | 73 +++++++++++++++ .../Operations/I18nOperationTests.cs | 48 ++++++++++ .../KeyboardInterceptorOperationTests.cs | 59 ++++++++++++ .../MouseInterceptorOperationTests.cs | 59 ++++++++++++ .../ProcessMonitorOperationTests.cs | 68 ++++++++++++++ .../RuntimeControllerOperationTests.cs | 56 ++++++++++++ .../Operations/TaskbarOperationTests.cs | 89 +++++++++++++++++++ .../Operations/WindowMonitorOperationTests.cs | 68 ++++++++++++++ .../SafeExamBrowser.Core.UnitTests.csproj | 10 +++ 11 files changed, 658 insertions(+) create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/BrowserOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClipboardOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DisplayMonitorOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/I18nOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/KeyboardInterceptorOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/MouseInterceptorOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ProcessMonitorOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/WindowMonitorOperationTests.cs diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/BrowserOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/BrowserOperationTests.cs new file mode 100644 index 00000000..3f102f85 --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/BrowserOperationTests.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class BrowserOperationTests + { + private Mock controllerMock; + private Mock appInfoMock; + private Mock loggerMock; + private Mock splashScreenMock; + private Mock taskbarMock; + private Mock uiFactoryMock; + + private BrowserOperation sut; + + [TestInitialize] + public void Initialize() + { + controllerMock = new Mock(); + appInfoMock = new Mock(); + loggerMock = new Mock(); + splashScreenMock = new Mock(); + taskbarMock = new Mock(); + uiFactoryMock = new Mock(); + + sut = new BrowserOperation(controllerMock.Object, appInfoMock.Object, loggerMock.Object, taskbarMock.Object, uiFactoryMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPeformCorrectly() + { + var order = 0; + + controllerMock.Setup(c => c.Initialize()).Callback(() => Assert.AreEqual(++order, 1)); + controllerMock.Setup(c => c.RegisterApplicationButton(It.IsAny())).Callback(() => Assert.AreEqual(++order, 2)); + taskbarMock.Setup(t => t.AddApplication(It.IsAny())).Callback(() => Assert.AreEqual(++order, 3)); + + sut.Perform(); + + controllerMock.Verify(c => c.Initialize(), Times.Once); + controllerMock.Verify(c => c.RegisterApplicationButton(It.IsAny()), Times.Once); + taskbarMock.Verify(t => t.AddApplication(It.IsAny()), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + controllerMock.Verify(c => c.Terminate(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClipboardOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClipboardOperationTests.cs new file mode 100644 index 00000000..ada2a7aa --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClipboardOperationTests.cs @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.WindowsApi; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class ClipboardOperationTests + { + private Mock loggerMock; + private Mock nativeMethodsMock; + private Mock splashScreenMock; + + private ClipboardOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + nativeMethodsMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new ClipboardOperation(loggerMock.Object, nativeMethodsMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + nativeMethodsMock.Verify(n => n.EmptyClipboard(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + nativeMethodsMock.Verify(n => n.EmptyClipboard(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DisplayMonitorOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DisplayMonitorOperationTests.cs new file mode 100644 index 00000000..ae6f4d3a --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DisplayMonitorOperationTests.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class DisplayMonitorOperationTests + { + private Mock displayMonitorMock; + private Mock loggerMock; + private Mock splashScreenMock; + private Mock taskbarMock; + + private DisplayMonitorOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + displayMonitorMock = new Mock(); + splashScreenMock = new Mock(); + taskbarMock = new Mock(); + + sut = new DisplayMonitorOperation(displayMonitorMock.Object, loggerMock.Object, taskbarMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + var order = 0; + + displayMonitorMock.Setup(d => d.PreventSleepMode()).Callback(() => Assert.AreEqual(++order, 1)); + displayMonitorMock.Setup(d => d.InitializePrimaryDisplay(It.IsAny())).Callback(() => Assert.AreEqual(++order, 2)); + displayMonitorMock.Setup(d => d.StartMonitoringDisplayChanges()).Callback(() => Assert.AreEqual(++order, 3)); + + sut.Perform(); + + displayMonitorMock.Verify(d => d.PreventSleepMode(), Times.Once); + displayMonitorMock.Verify(d => d.InitializePrimaryDisplay(It.IsAny()), Times.Once); + displayMonitorMock.Verify(d => d.StartMonitoringDisplayChanges(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + var order = 0; + + displayMonitorMock.Setup(d => d.StopMonitoringDisplayChanges()).Callback(() => Assert.AreEqual(++order, 1)); + displayMonitorMock.Setup(d => d.ResetPrimaryDisplay()).Callback(() => Assert.AreEqual(++order, 2)); + + sut.Revert(); + + displayMonitorMock.Verify(d => d.StopMonitoringDisplayChanges(), Times.Once); + displayMonitorMock.Verify(d => d.ResetPrimaryDisplay(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/I18nOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/I18nOperationTests.cs new file mode 100644 index 00000000..e0225152 --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/I18nOperationTests.cs @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class I18nOperationTests + { + private Mock loggerMock; + private Mock splashScreenMock; + private Mock textMock; + + private I18nOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + splashScreenMock = new Mock(); + textMock = new Mock(); + + sut = new I18nOperation(loggerMock.Object, textMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + textMock.Verify(t => t.Initialize(It.IsAny()), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/KeyboardInterceptorOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/KeyboardInterceptorOperationTests.cs new file mode 100644 index 00000000..326e8c05 --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/KeyboardInterceptorOperationTests.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.WindowsApi; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class KeyboardInterceptorOperationTests + { + private Mock keyboardInterceptorMock; + private Mock loggerMock; + private Mock nativeMethodsMock; + private Mock splashScreenMock; + + private KeyboardInterceptorOperation sut; + + [TestInitialize] + public void Initialize() + { + keyboardInterceptorMock = new Mock(); + loggerMock = new Mock(); + nativeMethodsMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new KeyboardInterceptorOperation(keyboardInterceptorMock.Object, loggerMock.Object, nativeMethodsMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + nativeMethodsMock.Verify(n => n.RegisterKeyboardHook(It.IsAny()), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + nativeMethodsMock.Verify(n => n.DeregisterKeyboardHook(It.IsAny()), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/MouseInterceptorOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/MouseInterceptorOperationTests.cs new file mode 100644 index 00000000..7b8a795d --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/MouseInterceptorOperationTests.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.WindowsApi; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class MouseInterceptorOperationTests + { + private Mock mouseInterceptorMock; + private Mock loggerMock; + private Mock nativeMethodsMock; + private Mock splashScreenMock; + + private MouseInterceptorOperation sut; + + [TestInitialize] + public void Initialize() + { + mouseInterceptorMock = new Mock(); + loggerMock = new Mock(); + nativeMethodsMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new MouseInterceptorOperation(loggerMock.Object, mouseInterceptorMock.Object, nativeMethodsMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + nativeMethodsMock.Verify(n => n.RegisterMouseHook(It.IsAny()), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + nativeMethodsMock.Verify(n => n.DeregisterMouseHook(It.IsAny()), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ProcessMonitorOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ProcessMonitorOperationTests.cs new file mode 100644 index 00000000..2cb12c3f --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ProcessMonitorOperationTests.cs @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class ProcessMonitorOperationTests + { + private Mock loggerMock; + private Mock processMonitorMock; + private Mock splashScreenMock; + + private ProcessMonitorOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + processMonitorMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new ProcessMonitorOperation(loggerMock.Object, processMonitorMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + var order = 0; + + processMonitorMock.Setup(p => p.CloseExplorerShell()).Callback(() => Assert.AreEqual(++order, 1)); + processMonitorMock.Setup(p => p.StartMonitoringExplorer()).Callback(() => Assert.AreEqual(++order, 2)); + + sut.Perform(); + + processMonitorMock.Verify(p => p.CloseExplorerShell(), Times.Once); + processMonitorMock.Verify(p => p.StartMonitoringExplorer(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + var order = 0; + + processMonitorMock.Setup(p => p.StopMonitoringExplorer()).Callback(() => Assert.AreEqual(++order, 1)); + processMonitorMock.Setup(p => p.StartExplorerShell()).Callback(() => Assert.AreEqual(++order, 2)); + + sut.Revert(); + + processMonitorMock.Verify(p => p.StopMonitoringExplorer(), Times.Once); + processMonitorMock.Verify(p => p.StartExplorerShell(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs new file mode 100644 index 00000000..6781e5f0 --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class RuntimeControllerOperationTests + { + private Mock loggerMock; + private Mock runtimeControllerMock; + private Mock splashScreenMock; + + private RuntimeControllerOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + runtimeControllerMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new RuntimeControllerOperation(runtimeControllerMock.Object, loggerMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + runtimeControllerMock.Verify(r => r.Start(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + runtimeControllerMock.Verify(r => r.Stop(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs new file mode 100644 index 00000000..0fb4c23b --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/TaskbarOperationTests.cs @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.SystemComponents; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class TaskbarOperationTests + { + private Mock loggerMock; + private Mock settingsMock; + private Mock splashScreenMock; + private Mock> keyboardLayoutMock; + private Mock> powerSupplyMock; + private Mock systemInfoMock; + private Mock taskbarMock; + private Mock textMock; + private Mock uiFactoryMock; + + private TaskbarOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + settingsMock = new Mock(); + splashScreenMock = new Mock(); + keyboardLayoutMock = new Mock>(); + powerSupplyMock = new Mock>(); + systemInfoMock = new Mock(); + taskbarMock = new Mock(); + textMock = new Mock(); + uiFactoryMock = new Mock(); + + settingsMock.SetupGet(s => s.AllowApplicationLog).Returns(true); + settingsMock.SetupGet(s => s.AllowKeyboardLayout).Returns(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, + keyboardLayoutMock.Object, + powerSupplyMock.Object, + systemInfoMock.Object, + taskbarMock.Object, + textMock.Object, + uiFactoryMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + keyboardLayoutMock.Verify(k => k.Initialize(It.IsAny()), Times.Once); + powerSupplyMock.Verify(p => p.Initialize(It.IsAny()), Times.Once); + taskbarMock.Verify(t => t.AddSystemControl(It.IsAny()), Times.Exactly(2)); + taskbarMock.Verify(t => t.AddNotification(It.IsAny()), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + keyboardLayoutMock.Verify(k => k.Terminate(), Times.Once); + powerSupplyMock.Verify(p => p.Terminate(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/WindowMonitorOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/WindowMonitorOperationTests.cs new file mode 100644 index 00000000..e5577c99 --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/WindowMonitorOperationTests.cs @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class WindowMonitorOperationTests + { + private Mock loggerMock; + private Mock splashScreenMock; + private Mock windowMonitorMock; + + private WindowMonitorOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + splashScreenMock = new Mock(); + windowMonitorMock = new Mock(); + + sut = new WindowMonitorOperation(loggerMock.Object, windowMonitorMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + var order = 0; + + windowMonitorMock.Setup(w => w.HideAllWindows()).Callback(() => Assert.AreEqual(++order, 1)); + windowMonitorMock.Setup(w => w.StartMonitoringWindows()).Callback(() => Assert.AreEqual(++order, 2)); + + sut.Perform(); + + windowMonitorMock.Verify(w => w.HideAllWindows(), Times.Once); + windowMonitorMock.Verify(w => w.StartMonitoringWindows(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + var order = 0; + + windowMonitorMock.Setup(w => w.StopMonitoringWindows()).Callback(() => Assert.AreEqual(++order, 1)); + windowMonitorMock.Setup(w => w.RestoreHiddenWindows()).Callback(() => Assert.AreEqual(++order, 2)); + + sut.Revert(); + + windowMonitorMock.Verify(w => w.StopMonitoringWindows(), Times.Once); + windowMonitorMock.Verify(w => w.RestoreHiddenWindows(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj index e358bb1b..78947157 100644 --- a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj +++ b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj @@ -72,6 +72,16 @@ + + + + + + + + + +