diff --git a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs index 45a477d1..8a5a8248 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Operations/ClientTerminationOperationTests.cs @@ -105,5 +105,33 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations Assert.AreEqual(OperationResult.Success, result); } + + [TestMethod] + public void MustDoNothingOnPerform() + { + var result = sut.Perform(); + + process.VerifyNoOtherCalls(); + processFactory.VerifyNoOtherCalls(); + proxy.VerifyNoOtherCalls(); + proxyFactory.VerifyNoOtherCalls(); + runtimeHost.VerifyNoOtherCalls(); + + Assert.AreEqual(OperationResult.Success, result); + } + + [TestMethod] + public void MustDoNothingOnRevert() + { + var result = sut.Revert(); + + process.VerifyNoOtherCalls(); + processFactory.VerifyNoOtherCalls(); + proxy.VerifyNoOtherCalls(); + proxyFactory.VerifyNoOtherCalls(); + runtimeHost.VerifyNoOtherCalls(); + + Assert.AreEqual(OperationResult.Success, result); + } } } diff --git a/SafeExamBrowser.Runtime.UnitTests/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Operations/ConfigurationOperationTests.cs index ba5e3074..15d1c6fa 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Operations/ConfigurationOperationTests.cs @@ -32,8 +32,6 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations private Mock nextSession; private SessionContext sessionContext; - private ConfigurationOperation sut; - [TestInitialize] public void Initialize() { @@ -67,8 +65,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Perform(); var resource = new Uri(url); @@ -87,8 +84,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Perform(); var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); @@ -103,11 +99,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations var settings = default(Settings); appConfig.AppDataFolder = location; - repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Perform(); var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); @@ -124,8 +118,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings); nextSession.SetupSet(s => s.Settings = It.IsAny()).Callback(s => actualSettings = s); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Perform(); repository.Verify(r => r.LoadDefaultSettings(), Times.Once); @@ -146,7 +139,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); repository.Setup(r => r.ConfigureClientWith(It.IsAny(), It.IsAny())).Returns(SaveStatus.Success); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is ConfigurationCompletedEventArgs c) @@ -170,7 +163,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); repository.Setup(r => r.ConfigureClientWith(It.IsAny(), It.IsAny())).Returns(SaveStatus.Success); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is ConfigurationCompletedEventArgs c) @@ -192,7 +185,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations settings.ConfigurationMode = ConfigurationMode.Exam; repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is ConfigurationCompletedEventArgs c) @@ -216,7 +209,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings); nextSession.SetupSet(s => s.Settings = It.IsAny()).Callback(s => actualSettings = s); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); result = sut.Perform(); repository.Verify(r => r.LoadDefaultSettings(), Times.Once); @@ -235,8 +228,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations public void MustNotFailWithInvalidUri() { var uri = @"an/invalid\uri.'*%yolo/()你好"; - sut = new ConfigurationOperation(new[] { "blubb.exe", uri }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(new[] { "blubb.exe", uri }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Perform(); Assert.AreEqual(OperationResult.Success, result); @@ -256,7 +248,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.Is(u => u.LocalPath.Contains("SettingsDummy")), out localSettings, It.IsAny())).Returns(LoadStatus.Success); nextSession.SetupGet(s => s.Settings).Returns(settings); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator) @@ -281,7 +273,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.PasswordNeeded); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.Settings) @@ -315,7 +307,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.Is(u => u.AbsoluteUri == url), out nextSettings, It.IsAny())).Returns(LoadStatus.Success); repository.Setup(r => r.ConfigureClientWith(It.IsAny(), It.IsAny())).Returns(SaveStatus.Success); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator) @@ -342,7 +334,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.PasswordNeeded); repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.Is(p => p.Password == password))).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p) @@ -367,7 +359,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.PasswordNeeded); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p) @@ -389,7 +381,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.PasswordNeeded); - sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); sut.ActionRequired += args => { if (args is PasswordRequiredEventArgs p) @@ -415,8 +407,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations sessionContext.ReconfigurationFilePath = resource.LocalPath; repository.Setup(r => r.TryLoadSettings(It.Is(u => u.Equals(resource)), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); nextSession.VerifySet(s => s.Settings = settings, Times.Once); @@ -439,8 +430,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Setup(r => r.TryLoadSettings(It.Is(u => u.Equals(resource)), out settings, It.IsAny())).Returns(LoadStatus.Success); repository.Setup(r => r.ConfigureClientWith(It.Is(u => u.Equals(resource)), It.IsAny())).Returns(SaveStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); nextSession.VerifySet(s => s.Settings = settings, Times.Once); @@ -459,8 +449,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations sessionContext.ReconfigurationFilePath = null; repository.Setup(r => r.TryLoadSettings(It.IsAny(), out settings, It.IsAny())).Returns(LoadStatus.Success); - sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); - + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); var result = sut.Repeat(); repository.Verify(r => r.TryLoadSettings(It.Is(u => u.Equals(resource)), out settings, It.IsAny()), Times.Never); @@ -472,5 +461,19 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations repository.Verify(r => r.TryLoadSettings(It.Is(u => u.Equals(resource)), out settings, It.IsAny()), Times.Never); Assert.AreEqual(OperationResult.Failed, result); } + + [TestMethod] + public void MustDoNothingOnRevert() + { + var sut = new ConfigurationOperation(null, repository.Object, hashAlgorithm.Object, logger.Object, sessionContext); + var result = sut.Revert(); + + currentSession.VerifyNoOtherCalls(); + hashAlgorithm.VerifyNoOtherCalls(); + nextSession.VerifyNoOtherCalls(); + repository.VerifyNoOtherCalls(); + + Assert.AreEqual(OperationResult.Success, result); + } } }