diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs index e4eb36aa..6c3cdbe3 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs @@ -6,8 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; +using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +using SafeExamBrowser.Contracts.Behaviour.OperationModel; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; @@ -41,125 +44,124 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations 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()); + repository.Setup(r => r.LoadDefaultSettings()); - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut.Perform(); - //sut.Perform(); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new string[] { }); + 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(); + repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2)); } [TestMethod] public void MustNotFailWithInvalidUri() { - //var path = @"an/invalid\path.'*%yolo/()"; + 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(); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path }); + sut.Perform(); } [TestMethod] public void MustUseCommandLineArgumentAs1stPrio() { - //var path = @"http://www.safeexambrowser.org/whatever.seb"; - //var location = Path.GetDirectoryName(GetType().Assembly.Location); + var path = @"http://www.safeexambrowser.org/whatever.seb"; + var location = Path.GetDirectoryName(GetType().Assembly.Location); - //info.ProgramDataFolder = location; - //info.AppDataFolder = location; + info.ProgramDataFolder = location; + info.AppDataFolder = location; - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path }); + repository.SetupGet(r => r.CurrentSettings).Returns(settings); + repository.Setup(r => r.LoadSettings(It.IsAny(), null, null)).Returns(LoadStatus.Success); - //sut.Perform(); + 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); + var resource = new Uri(path); + + repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(resource)), null, null), Times.Once); } [TestMethod] public void MustUseProgramDataAs2ndPrio() { - //var location = Path.GetDirectoryName(GetType().Assembly.Location); + var location = Path.GetDirectoryName(GetType().Assembly.Location); - //info.ProgramDataFolder = location; - //info.AppDataFolder = $@"{location}\WRONG"; + info.ProgramDataFolder = location; + info.AppDataFolder = $@"{location}\WRONG"; - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + repository.SetupGet(r => r.CurrentSettings).Returns(settings); + repository.Setup(r => r.LoadSettings(It.IsAny(), null, null)).Returns(LoadStatus.Success); - //sut.Perform(); + 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); + var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); + + repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(resource)), null, null), Times.Once); } [TestMethod] public void MustUseAppDataAs3rdPrio() { - //var location = Path.GetDirectoryName(GetType().Assembly.Location); + var location = Path.GetDirectoryName(GetType().Assembly.Location); - //info.AppDataFolder = location; + info.AppDataFolder = location; - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + repository.SetupGet(r => r.CurrentSettings).Returns(settings); + repository.Setup(r => r.LoadSettings(It.IsAny(), null, null)).Returns(LoadStatus.Success); - //sut.Perform(); + 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); + var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); + + repository.Verify(r => r.LoadSettings(It.Is(u => u.Equals(resource)), null, null), Times.Once); } [TestMethod] public void MustFallbackToDefaultsAsLastPrio() { - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut.Perform(); - //sut.Perform(); - - //repository.Verify(r => r.LoadDefaultSettings(), Times.Once); - Assert.Fail(); + repository.Verify(r => r.LoadDefaultSettings(), Times.Once); } [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); + info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location); + messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.Yes); + repository.SetupGet(r => r.CurrentSettings).Returns(settings); + repository.Setup(r => r.LoadSettings(It.IsAny(), null, null)).Returns(LoadStatus.Success); - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); - //var result = sut.Perform(); + var result = sut.Perform(); - //Assert.AreEqual(OperationResult.Aborted, result); - - Assert.Fail(); + Assert.AreEqual(OperationResult.Aborted, result); } [TestMethod] public void MustNotAbortIfNotWishedByUser() { - //messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); + messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); + repository.SetupGet(r => r.CurrentSettings).Returns(settings); + repository.Setup(r => r.LoadSettings(It.IsAny(), null, null)).Returns(LoadStatus.Success); - //sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); - //var result = sut.Perform(); + var result = sut.Perform(); - //Assert.AreEqual(OperationResult.Success, result); - - Assert.Fail(); + Assert.AreEqual(OperationResult.Success, result); } } } diff --git a/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs index 2b32609b..f459e75a 100644 --- a/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs +++ b/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs @@ -119,11 +119,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations { status = repository.LoadSettings(uri, settingsPassword, adminPassword); - if (status == LoadStatus.InvalidData || status == LoadStatus.Success) - { - break; - } - else if (status == LoadStatus.AdminPasswordNeeded || status == LoadStatus.SettingsPasswordNeeded) + if (status == LoadStatus.AdminPasswordNeeded || status == LoadStatus.SettingsPasswordNeeded) { var isAdmin = status == LoadStatus.AdminPasswordNeeded; var success = isAdmin ? TryGetAdminPassword(out adminPassword) : TryGetSettingsPassword(out settingsPassword); @@ -138,6 +134,10 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations return OperationResult.Aborted; } } + else + { + break; + } } if (status == LoadStatus.InvalidData)