/* * Copyright (c) 2019 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 System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; using SafeExamBrowser.Contracts.Client; 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.Shell; using SafeExamBrowser.Contracts.WindowsApi; namespace SafeExamBrowser.Client.UnitTests.Operations { [TestClass] public class ShellOperationTests { private Mock actionCenter; private Mock> activators; private ActionCenterSettings actionCenterSettings; private Mock logger; private TaskbarSettings taskbarSettings; private Mock terminationActivator; private Mock aboutInfo; private Mock aboutController; private Mock logInfo; private Mock logController; private Mock> keyboardLayout; private Mock> powerSupply; private Mock> wirelessNetwork; private Mock systemInfo; private Mock taskbar; private Mock text; private Mock uiFactory; private ShellOperation sut; [TestInitialize] public void Initialize() { actionCenter = new Mock(); activators = new Mock>(); actionCenterSettings = new ActionCenterSettings(); logger = new Mock(); aboutInfo = new Mock(); aboutController = new Mock(); logInfo = new Mock(); logController = new Mock(); keyboardLayout = new Mock>(); powerSupply = new Mock>(); wirelessNetwork = new Mock>(); systemInfo = new Mock(); taskbar = new Mock(); taskbarSettings = new TaskbarSettings(); terminationActivator = new Mock(); text = new Mock(); uiFactory = new Mock(); taskbarSettings.ShowApplicationLog = true; taskbarSettings.ShowKeyboardLayout = true; taskbarSettings.ShowWirelessNetwork = true; taskbarSettings.EnableTaskbar = true; systemInfo.SetupGet(s => s.HasBattery).Returns(true); uiFactory.Setup(u => u.CreateNotificationControl(It.IsAny(), It.IsAny())).Returns(new Mock().Object); sut = new ShellOperation( actionCenter.Object, activators.Object, actionCenterSettings, logger.Object, aboutInfo.Object, aboutController.Object, logInfo.Object, logController.Object, keyboardLayout.Object, powerSupply.Object, wirelessNetwork.Object, systemInfo.Object, taskbar.Object, taskbarSettings, terminationActivator.Object, text.Object, uiFactory.Object); } [TestMethod] public void MustPerformCorrectly() { sut.Perform(); keyboardLayout.Verify(k => k.Initialize(), Times.Once); powerSupply.Verify(p => p.Initialize(), Times.Once); wirelessNetwork.Verify(w => w.Initialize(), Times.Once); taskbar.Verify(t => t.AddSystemControl(It.IsAny()), Times.Exactly(3)); taskbar.Verify(t => t.AddNotificationControl(It.IsAny()), Times.Exactly(2)); } [TestMethod] public void MustRevertCorrectly() { sut.Revert(); aboutController.Verify(c => c.Terminate(), Times.Once); keyboardLayout.Verify(k => k.Terminate(), Times.Once); powerSupply.Verify(p => p.Terminate(), Times.Once); wirelessNetwork.Verify(w => w.Terminate(), Times.Once); } } }