2018-01-18 15:14:05 +01:00
|
|
|
|
/*
|
|
|
|
|
* 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.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-01-19 09:23:09 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.MessageBox;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Runtime.Behaviour.Operations;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ConfigurationOperationTests
|
|
|
|
|
{
|
|
|
|
|
private Mock<ILogger> logger;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
private Mock<IMessageBox> messageBox;
|
2018-02-16 13:42:27 +01:00
|
|
|
|
private RuntimeInfo info;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
private Mock<IConfigurationRepository> repository;
|
2018-02-16 13:42:27 +01:00
|
|
|
|
private Settings settings;
|
2018-01-19 09:23:09 +01:00
|
|
|
|
private Mock<IText> text;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
private ConfigurationOperation sut;
|
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2018-02-16 13:42:27 +01:00
|
|
|
|
info = new RuntimeInfo();
|
2018-03-14 12:07:20 +01:00
|
|
|
|
logger = new Mock<ILogger>();
|
|
|
|
|
messageBox = new Mock<IMessageBox>();
|
2018-02-06 15:12:11 +01:00
|
|
|
|
repository = new Mock<IConfigurationRepository>();
|
2018-02-16 13:42:27 +01:00
|
|
|
|
settings = new Settings();
|
2018-01-19 09:23:09 +01:00
|
|
|
|
text = new Mock<IText>();
|
|
|
|
|
|
2018-02-16 13:42:27 +01:00
|
|
|
|
info.AppDataFolder = @"C:\Not\Really\AppData";
|
|
|
|
|
info.DefaultSettingsFileName = "SettingsDummy.txt";
|
|
|
|
|
info.ProgramDataFolder = @"C:\Not\Really\ProgramData";
|
2018-06-21 07:56:25 +02:00
|
|
|
|
// TODO
|
|
|
|
|
//repository.Setup(r => r.LoadSettings(It.IsAny<Uri>())).Returns(settings);
|
|
|
|
|
//repository.Setup(r => r.LoadDefaultSettings()).Returns(settings);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailWithoutCommandLineArgs()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//repository.Setup(r => r.LoadDefaultSettings());
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new string[] { });
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2));
|
|
|
|
|
Assert.Fail();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailWithInvalidUri()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var path = @"an/invalid\path.'*%yolo/()";
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new [] { "blubb.exe", path });
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
|
|
|
|
Assert.Fail();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseCommandLineArgumentAs1stPrio()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var path = @"http://www.safeexambrowser.org/whatever.seb";
|
|
|
|
|
//var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//info.ProgramDataFolder = location;
|
|
|
|
|
//info.AppDataFolder = location;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path });
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
Assert.Fail();
|
|
|
|
|
//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(path)))), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseProgramDataAs2ndPrio()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//info.ProgramDataFolder = location;
|
|
|
|
|
//info.AppDataFolder = $@"{location}\WRONG";
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
Assert.Fail();
|
|
|
|
|
//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustUseAppDataAs3rdPrio()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//info.AppDataFolder = location;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
Assert.Fail();
|
|
|
|
|
//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustFallbackToDefaultsAsLastPrio()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//sut.Perform();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
|
|
|
|
|
Assert.Fail();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustAbortIfWishedByUser()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location);
|
|
|
|
|
//messageBox.Setup(u => u.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.Yes);
|
|
|
|
|
|
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var result = sut.Perform();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//Assert.AreEqual(OperationResult.Aborted, result);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
Assert.Fail();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotAbortIfNotWishedByUser()
|
|
|
|
|
{
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//messageBox.Setup(u => u.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.No);
|
|
|
|
|
|
|
|
|
|
//sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//var result = sut.Perform();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
//Assert.AreEqual(OperationResult.Success, result);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-06-21 09:14:14 +02:00
|
|
|
|
Assert.Fail();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
}
|
2018-01-18 15:14:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|