/* * 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; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface.MessageBox; using SafeExamBrowser.Runtime.Behaviour.Operations; namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { [TestClass] public class ConfigurationOperationTests { private Mock logger; private Mock messageBox; private RuntimeInfo info; private Mock repository; private Settings settings; private Mock text; private ConfigurationOperation sut; [TestInitialize] public void Initialize() { info = new RuntimeInfo(); logger = new Mock(); messageBox = new Mock(); repository = new Mock(); settings = new Settings(); text = new Mock(); info.AppDataFolder = @"C:\Not\Really\AppData"; info.DefaultSettingsFileName = "SettingsDummy.txt"; info.ProgramDataFolder = @"C:\Not\Really\ProgramData"; // TODO //repository.Setup(r => r.LoadSettings(It.IsAny())).Returns(settings); //repository.Setup(r => r.LoadDefaultSettings()).Returns(settings); } [TestMethod] public void MustNotFailWithoutCommandLineArgs() { //repository.Setup(r => r.LoadDefaultSettings()); //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //sut.Perform(); //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new string[] { }); //sut.Perform(); //repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2)); Assert.Fail(); } [TestMethod] public void MustNotFailWithInvalidUri() { //var path = @"an/invalid\path.'*%yolo/()"; //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new [] { "blubb.exe", path }); //sut.Perform(); Assert.Fail(); } [TestMethod] public void MustUseCommandLineArgumentAs1stPrio() { //var path = @"http://www.safeexambrowser.org/whatever.seb"; //var location = Path.GetDirectoryName(GetType().Assembly.Location); //info.ProgramDataFolder = location; //info.AppDataFolder = location; //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path }); //sut.Perform(); Assert.Fail(); //repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(new Uri(path)))), Times.Once); } [TestMethod] public void MustUseProgramDataAs2ndPrio() { //var location = Path.GetDirectoryName(GetType().Assembly.Location); //info.ProgramDataFolder = location; //info.AppDataFolder = $@"{location}\WRONG"; //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //sut.Perform(); Assert.Fail(); //repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once); } [TestMethod] public void MustUseAppDataAs3rdPrio() { //var location = Path.GetDirectoryName(GetType().Assembly.Location); //info.AppDataFolder = location; //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //sut.Perform(); Assert.Fail(); //repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once); } [TestMethod] public void MustFallbackToDefaultsAsLastPrio() { //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //sut.Perform(); //repository.Verify(r => r.LoadDefaultSettings(), Times.Once); Assert.Fail(); } [TestMethod] public void MustAbortIfWishedByUser() { //info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location); //messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.Yes); //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //var result = sut.Perform(); //Assert.AreEqual(OperationResult.Aborted, result); Assert.Fail(); } [TestMethod] public void MustNotAbortIfNotWishedByUser() { //messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); //var result = sut.Perform(); //Assert.AreEqual(OperationResult.Success, result); Assert.Fail(); } } }