SEBWIN-220: Fixed unit tests for ConfigurationOperation.
This commit is contained in:
parent
a74609eb46
commit
639bde7860
2 changed files with 63 additions and 61 deletions
|
@ -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<Uri>())).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<Uri>(), 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<Uri>(u => u.Equals(new Uri(path)))), Times.Once);
|
||||
var resource = new Uri(path);
|
||||
|
||||
repository.Verify(r => r.LoadSettings(It.Is<Uri>(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<Uri>(), 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<Uri>(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<Uri>(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<Uri>(), 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<Uri>(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<Uri>(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<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.Yes);
|
||||
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);
|
||||
repository.SetupGet(r => r.CurrentSettings).Returns(settings);
|
||||
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), 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<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.No);
|
||||
messageBox.Setup(u => u.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.No);
|
||||
repository.SetupGet(r => r.CurrentSettings).Returns(settings);
|
||||
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue