/* * 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.Logging; using SafeExamBrowser.Contracts.SystemComponents; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Contracts.UserInterface.Shell; namespace SafeExamBrowser.Client.UnitTests.Operations { [TestClass] public class ShellOperationTests { private Mock actionCenter; private Mock> activators; private ActionCenterSettings actionCenterSettings; private Mock loggerMock; private TaskbarSettings taskbarSettings; private Mock aboutInfoMock; private Mock aboutControllerMock; private Mock logInfoMock; private Mock logControllerMock; private Mock> keyboardLayoutMock; private Mock> powerSupplyMock; private Mock> wirelessNetworkMock; private Mock systemInfoMock; private Mock taskbarMock; private Mock uiFactoryMock; private ShellOperation sut; [TestInitialize] public void Initialize() { actionCenter = new Mock(); activators = new Mock>(); actionCenterSettings = new ActionCenterSettings(); loggerMock = new Mock(); aboutInfoMock = new Mock(); aboutControllerMock = new Mock(); logInfoMock = new Mock(); logControllerMock = new Mock(); keyboardLayoutMock = new Mock>(); powerSupplyMock = new Mock>(); wirelessNetworkMock = new Mock>(); systemInfoMock = new Mock(); taskbarMock = new Mock(); taskbarSettings = new TaskbarSettings(); uiFactoryMock = new Mock(); taskbarSettings.ShowApplicationLog = true; taskbarSettings.ShowKeyboardLayout = true; taskbarSettings.AllowWirelessNetwork = true; taskbarSettings.EnableTaskbar = true; systemInfoMock.SetupGet(s => s.HasBattery).Returns(true); uiFactoryMock.Setup(u => u.CreateNotificationControl(It.IsAny(), It.IsAny())).Returns(new Mock().Object); sut = new ShellOperation( actionCenter.Object, activators.Object, actionCenterSettings, loggerMock.Object, aboutInfoMock.Object, aboutControllerMock.Object, logInfoMock.Object, logControllerMock.Object, keyboardLayoutMock.Object, powerSupplyMock.Object, wirelessNetworkMock.Object, systemInfoMock.Object, taskbarMock.Object, taskbarSettings, uiFactoryMock.Object); } [TestMethod] public void MustPerformCorrectly() { sut.Perform(); keyboardLayoutMock.Verify(k => k.Initialize(), Times.Once); powerSupplyMock.Verify(p => p.Initialize(), Times.Once); wirelessNetworkMock.Verify(w => w.Initialize(), Times.Once); taskbarMock.Verify(t => t.AddSystemControl(It.IsAny()), Times.Exactly(3)); taskbarMock.Verify(t => t.AddNotificationControl(It.IsAny()), Times.Exactly(2)); } [TestMethod] public void MustRevertCorrectly() { sut.Revert(); aboutControllerMock.Verify(c => c.Terminate(), Times.Once); keyboardLayoutMock.Verify(k => k.Terminate(), Times.Once); powerSupplyMock.Verify(p => p.Terminate(), Times.Once); wirelessNetworkMock.Verify(w => w.Terminate(), Times.Once); } } }