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;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
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;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
private Mock<ILogger> logger;
|
2019-03-08 15:56:38 +01:00
|
|
|
|
private TaskbarSettings taskbarSettings;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
private Mock<INotificationInfo> aboutInfo;
|
|
|
|
|
private Mock<INotificationController> aboutController;
|
|
|
|
|
private Mock<INotificationInfo> logInfo;
|
|
|
|
|
private Mock<INotificationController> logController;
|
|
|
|
|
private Mock<ISystemComponent<ISystemKeyboardLayoutControl>> keyboardLayout;
|
|
|
|
|
private Mock<ISystemComponent<ISystemPowerSupplyControl>> powerSupply;
|
|
|
|
|
private Mock<ISystemComponent<ISystemWirelessNetworkControl>> wirelessNetwork;
|
|
|
|
|
private Mock<ISystemInfo> systemInfo;
|
|
|
|
|
private Mock<ITaskbar> taskbar;
|
|
|
|
|
private Mock<IText> text;
|
|
|
|
|
private Mock<IUserInterfaceFactory> uiFactory;
|
2017-10-11 11:46:39 +02:00
|
|
|
|
|
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();
|
2019-03-15 11:38:59 +01:00
|
|
|
|
logger = new Mock<ILogger>();
|
|
|
|
|
aboutInfo = new Mock<INotificationInfo>();
|
|
|
|
|
aboutController = new Mock<INotificationController>();
|
|
|
|
|
logInfo = new Mock<INotificationInfo>();
|
|
|
|
|
logController = new Mock<INotificationController>();
|
|
|
|
|
keyboardLayout = new Mock<ISystemComponent<ISystemKeyboardLayoutControl>>();
|
|
|
|
|
powerSupply = new Mock<ISystemComponent<ISystemPowerSupplyControl>>();
|
|
|
|
|
wirelessNetwork = new Mock<ISystemComponent<ISystemWirelessNetworkControl>>();
|
|
|
|
|
systemInfo = new Mock<ISystemInfo>();
|
|
|
|
|
taskbar = new Mock<ITaskbar>();
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings = new TaskbarSettings();
|
2019-03-15 11:38:59 +01:00
|
|
|
|
text = new Mock<IText>();
|
|
|
|
|
uiFactory = new Mock<IUserInterfaceFactory>();
|
2017-10-11 11:46:39 +02:00
|
|
|
|
|
2019-03-12 16:18:27 +01:00
|
|
|
|
taskbarSettings.ShowApplicationLog = true;
|
|
|
|
|
taskbarSettings.ShowKeyboardLayout = true;
|
2019-03-15 09:44:17 +01:00
|
|
|
|
taskbarSettings.ShowWirelessNetwork = true;
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings.EnableTaskbar = true;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
systemInfo.SetupGet(s => s.HasBattery).Returns(true);
|
|
|
|
|
uiFactory.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,
|
2019-03-15 11:38:59 +01:00
|
|
|
|
logger.Object,
|
|
|
|
|
aboutInfo.Object,
|
|
|
|
|
aboutController.Object,
|
|
|
|
|
logInfo.Object,
|
|
|
|
|
logController.Object,
|
|
|
|
|
keyboardLayout.Object,
|
|
|
|
|
powerSupply.Object,
|
|
|
|
|
wirelessNetwork.Object,
|
|
|
|
|
systemInfo.Object,
|
|
|
|
|
taskbar.Object,
|
2019-03-08 15:56:38 +01:00
|
|
|
|
taskbarSettings,
|
2019-03-15 11:38:59 +01:00
|
|
|
|
text.Object,
|
|
|
|
|
uiFactory.Object);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustPerformCorrectly()
|
|
|
|
|
{
|
|
|
|
|
sut.Perform();
|
|
|
|
|
|
2019-03-15 11:38:59 +01:00
|
|
|
|
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<ISystemControl>()), Times.Exactly(3));
|
|
|
|
|
taskbar.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-03-15 11:38:59 +01:00
|
|
|
|
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);
|
2017-10-11 11:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|