/* * Copyright (c) 2018 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.Client.Operations; using SafeExamBrowser.Contracts.Core; 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; namespace SafeExamBrowser.Client.UnitTests.Operations { [TestClass] public class TaskbarOperationTests { private Mock loggerMock; private TaskbarSettings settings; private Mock logInfoMock; private Mock logControllerMock; private Mock> keyboardLayoutMock; private Mock> powerSupplyMock; private Mock> wirelessNetworkMock; private Mock systemInfoMock; private Mock taskbarMock; private Mock textMock; private Mock uiFactoryMock; private TaskbarOperation sut; [TestInitialize] public void Initialize() { loggerMock = new Mock(); logInfoMock = new Mock(); logControllerMock = new Mock(); keyboardLayoutMock = new Mock>(); powerSupplyMock = new Mock>(); wirelessNetworkMock = new Mock>(); systemInfoMock = new Mock(); taskbarMock = new Mock(); settings = new TaskbarSettings(); textMock = new Mock(); uiFactoryMock = new Mock(); 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, logInfoMock.Object, logControllerMock.Object, keyboardLayoutMock.Object, powerSupplyMock.Object, wirelessNetworkMock.Object, systemInfoMock.Object, taskbarMock.Object, settings, textMock.Object, uiFactoryMock.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); wirelessNetworkMock.Verify(w => w.Initialize(It.IsAny()), Times.Once); taskbarMock.Verify(t => t.AddSystemControl(It.IsAny()), Times.Exactly(3)); 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); wirelessNetworkMock.Verify(w => w.Terminate(), Times.Once); } } }