2017-10-11 09:18:55 +02:00
|
|
|
|
/*
|
2023-03-08 00:30:20 +01:00
|
|
|
|
* Copyright (c) 2023 ETH Zürich, Educational Development and Technology (LET)
|
2017-10-11 09:18:55 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-18 23:41:00 +01:00
|
|
|
|
using System.IO.Packaging;
|
2017-10-11 09:18:55 +02:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
2018-01-18 08:16:20 +01:00
|
|
|
|
using SafeExamBrowser.Client.Notifications;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
2017-10-11 09:18:55 +02:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Client.UnitTests.Notifications
|
2017-10-11 09:18:55 +02:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class AboutNotificationControllerTests
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private Mock<AppConfig> appConfig;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
private Mock<IText> text;
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private Mock<IUserInterfaceFactory> uiFactory;
|
2017-10-11 09:18:55 +02:00
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig = new Mock<AppConfig>();
|
2021-03-18 23:12:07 +01:00
|
|
|
|
text = new Mock<IText>();
|
2018-06-29 09:50:20 +02:00
|
|
|
|
uiFactory = new Mock<IUserInterfaceFactory>();
|
2021-03-18 23:41:00 +01:00
|
|
|
|
|
|
|
|
|
// Ensure that the pack scheme is known before executing the unit tests, see https://stackoverflow.com/a/6005606
|
|
|
|
|
_ = PackUriHelper.UriSchemePack;
|
2017-10-11 09:18:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCloseWindowWhenTerminating()
|
|
|
|
|
{
|
|
|
|
|
var window = new Mock<IWindow>();
|
2021-03-18 23:12:07 +01:00
|
|
|
|
var sut = new AboutNotification(appConfig.Object, text.Object, uiFactory.Object);
|
2017-10-11 09:18:55 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object);
|
2019-09-04 14:11:19 +02:00
|
|
|
|
|
|
|
|
|
sut.Activate();
|
2017-10-11 09:18:55 +02:00
|
|
|
|
sut.Terminate();
|
|
|
|
|
|
|
|
|
|
window.Verify(w => w.Close());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustOpenOnlyOneWindow()
|
|
|
|
|
{
|
|
|
|
|
var window = new Mock<IWindow>();
|
2021-03-18 23:12:07 +01:00
|
|
|
|
var sut = new AboutNotification(appConfig.Object, text.Object, uiFactory.Object);
|
2017-10-11 09:18:55 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
uiFactory.Setup(u => u.CreateAboutWindow(It.IsAny<AppConfig>())).Returns(window.Object);
|
2019-09-04 14:11:19 +02:00
|
|
|
|
|
|
|
|
|
sut.Activate();
|
|
|
|
|
sut.Activate();
|
|
|
|
|
sut.Activate();
|
|
|
|
|
sut.Activate();
|
|
|
|
|
sut.Activate();
|
2017-10-11 09:18:55 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
uiFactory.Verify(u => u.CreateAboutWindow(It.IsAny<AppConfig>()), Times.Once);
|
2017-10-11 09:18:55 +02:00
|
|
|
|
window.Verify(u => u.Show(), Times.Once);
|
|
|
|
|
window.Verify(u => u.BringToForeground(), Times.Exactly(4));
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-04 16:06:05 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailToTerminateIfNotStarted()
|
|
|
|
|
{
|
2021-03-18 23:12:07 +01:00
|
|
|
|
var sut = new AboutNotification(appConfig.Object, text.Object, uiFactory.Object);
|
2019-04-04 16:06:05 +02:00
|
|
|
|
|
|
|
|
|
sut.Terminate();
|
|
|
|
|
}
|
2017-10-11 09:18:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|