2017-10-11 11:46:39 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-10-11 11:46:39 +02:00
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-08 15:56:38 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Client.Operations;
|
2019-01-23 15:57:49 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Client;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.SystemComponents;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
2019-03-06 16:10:00 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Shell;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client.UnitTests.Operations
|
2017-10-11 11:46:39 +02:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2019-03-08 15:56:38 +01:00
|
|
|
|
public class ShellOperationTests
|
2017-10-11 11:46:39 +02:00
|
|
|
|
{
|
2019-03-08 15:56:38 +01:00
|
|
|
|
private Mock<IActionCenter> actionCenter;
|
|
|
|
|
private Mock<IEnumerable<IActionCenterActivator>> activators;
|
|
|
|
|
private ActionCenterSettings actionCenterSettings;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
private Mock<ILogger> loggerMock;
|
2019-03-08 15:56:38 +01:00
|
|
|
|
private TaskbarSettings taskbarSettings;
|
2019-01-09 11:17:43 +01:00
|
|
|
|
private Mock<INotificationInfo> aboutInfoMock;
|
|
|
|
|
private Mock<INotificationController> aboutControllerMock;
|
2018-02-28 09:45:29 +01:00
|
|
|
|
private Mock<INotificationInfo> logInfoMock;
|
|
|
|
|
private Mock<INotificationController> logControllerMock;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
private Mock<ISystemComponent<ISystemKeyboardLayoutControl>> keyboardLayoutMock;
|
|
|
|
|
private Mock<ISystemComponent<ISystemPowerSupplyControl>> powerSupplyMock;
|
2017-11-13 10:26:30 +01:00
|
|
|
|
private Mock<ISystemComponent<ISystemWirelessNetworkControl>> wirelessNetworkMock;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
private Mock<ISystemInfo> systemInfoMock;
|
|
|
|
|
private Mock<ITaskbar> taskbarMock;
|
|
|
|
|
private Mock<IUserInterfaceFactory> uiFactoryMock;
|
|
|
|
|
|
2019-03-08 15:56:38 +01:00
|
|
|
|
private ShellOperation sut;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2019-03-08 15:56:38 +01:00
|
|
|
|
actionCenter = new Mock<IActionCenter>();
|
|
|
|
|
activators = new Mock<IEnumerable<IActionCenterActivator>>();
|
|
|
|
|
actionCenterSettings = new ActionCenterSettings();
|
2017-10-11 11:46:39 +02:00
|
|
|
|
loggerMock = new Mock<ILogger>();
|
2019-01-09 11:17:43 +01:00
|
|
|
|
aboutInfoMock = new Mock<INotificationInfo>();
|
|
|
|
|
aboutControllerMock = new Mock<INotificationController>();
|
2018-02-28 09:45:29 +01:00
|
|
|
|
logInfoMock = new Mock<INotificationInfo>();
|
|
|
|
|
logControllerMock = new Mock<INotificationController>();
|
2017-10-11 11:46:39 +02:00
|
|
|
|
keyboardLayoutMock = new Mock<ISystemComponent<ISystemKeyboardLayoutControl>>();
|
|
|
|
|
powerSupplyMock = new Mock<ISystemComponent<ISystemPowerSupplyControl>>();
|
2017-11-13 10:26:30 +01:00
|
|
|
|
wirelessNetworkMock = new Mock<ISystemComponent<ISystemWirelessNetworkControl>>();
|
2017-10-11 11:46:39 +02:00
|
|
|
|
systemInfoMock = new Mock<ISystemInfo>();
|
|
|
|
|
taskbarMock = new Mock<ITaskbar>();
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings = new TaskbarSettings();
|
2017-10-11 11:46:39 +02:00
|
|
|
|
uiFactoryMock = new Mock<IUserInterfaceFactory>();
|
|
|
|
|
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings.AllowApplicationLog = true;
|
|
|
|
|
taskbarSettings.AllowKeyboardLayout = true;
|
|
|
|
|
taskbarSettings.AllowWirelessNetwork = true;
|
|
|
|
|
taskbarSettings.EnableTaskbar = true;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
systemInfoMock.SetupGet(s => s.HasBattery).Returns(true);
|
2019-03-08 15:56:38 +01:00
|
|
|
|
uiFactoryMock.Setup(u => u.CreateNotificationControl(It.IsAny<INotificationInfo>(), It.IsAny<Location>())).Returns(new Mock<INotificationControl>().Object);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
|
2019-03-08 15:56:38 +01:00
|
|
|
|
sut = new ShellOperation(
|
|
|
|
|
actionCenter.Object,
|
|
|
|
|
activators.Object,
|
|
|
|
|
actionCenterSettings,
|
2017-10-11 11:46:39 +02:00
|
|
|
|
loggerMock.Object,
|
2019-01-09 11:17:43 +01:00
|
|
|
|
aboutInfoMock.Object,
|
|
|
|
|
aboutControllerMock.Object,
|
2018-02-28 09:45:29 +01:00
|
|
|
|
logInfoMock.Object,
|
|
|
|
|
logControllerMock.Object,
|
2017-10-11 11:46:39 +02:00
|
|
|
|
keyboardLayoutMock.Object,
|
|
|
|
|
powerSupplyMock.Object,
|
2017-11-13 10:26:30 +01:00
|
|
|
|
wirelessNetworkMock.Object,
|
2017-10-11 11:46:39 +02:00
|
|
|
|
systemInfoMock.Object,
|
|
|
|
|
taskbarMock.Object,
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings,
|
2018-02-02 09:18:35 +01:00
|
|
|
|
uiFactoryMock.Object);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustPerformCorrectly()
|
|
|
|
|
{
|
|
|
|
|
sut.Perform();
|
|
|
|
|
|
2019-03-08 15:56:38 +01:00
|
|
|
|
keyboardLayoutMock.Verify(k => k.Initialize(), Times.Once);
|
|
|
|
|
powerSupplyMock.Verify(p => p.Initialize(), Times.Once);
|
|
|
|
|
wirelessNetworkMock.Verify(w => w.Initialize(), Times.Once);
|
2017-11-13 10:26:30 +01:00
|
|
|
|
taskbarMock.Verify(t => t.AddSystemControl(It.IsAny<ISystemControl>()), Times.Exactly(3));
|
2019-03-08 11:43:52 +01:00
|
|
|
|
taskbarMock.Verify(t => t.AddNotificationControl(It.IsAny<INotificationControl>()), Times.Exactly(2));
|
2017-10-11 11:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustRevertCorrectly()
|
|
|
|
|
{
|
|
|
|
|
sut.Revert();
|
|
|
|
|
|
2019-01-09 16:01:56 +01:00
|
|
|
|
aboutControllerMock.Verify(c => c.Terminate(), Times.Once);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
keyboardLayoutMock.Verify(k => k.Terminate(), Times.Once);
|
|
|
|
|
powerSupplyMock.Verify(p => p.Terminate(), Times.Once);
|
2017-11-13 10:26:30 +01:00
|
|
|
|
wirelessNetworkMock.Verify(w => w.Terminate(), Times.Once);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|