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/. |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | using System; | ||||||
|  | using System.IO; | ||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||
| using Moq; | using Moq; | ||||||
|  | using SafeExamBrowser.Contracts.Behaviour.OperationModel; | ||||||
| using SafeExamBrowser.Contracts.Configuration; | using SafeExamBrowser.Contracts.Configuration; | ||||||
| using SafeExamBrowser.Contracts.Configuration.Settings; | using SafeExamBrowser.Contracts.Configuration.Settings; | ||||||
| using SafeExamBrowser.Contracts.I18n; | using SafeExamBrowser.Contracts.I18n; | ||||||
|  | @ -41,125 +44,124 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations | ||||||
| 			info.AppDataFolder = @"C:\Not\Really\AppData"; | 			info.AppDataFolder = @"C:\Not\Really\AppData"; | ||||||
| 			info.DefaultSettingsFileName = "SettingsDummy.txt"; | 			info.DefaultSettingsFileName = "SettingsDummy.txt"; | ||||||
| 			info.ProgramDataFolder = @"C:\Not\Really\ProgramData"; | 			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] | 		[TestMethod] | ||||||
| 		public void MustNotFailWithoutCommandLineArgs() | 		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[] { }); | 			repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2)); | ||||||
| 
 |  | ||||||
| 			//sut.Perform(); |  | ||||||
| 
 |  | ||||||
| 			//repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2)); |  | ||||||
| 			Assert.Fail(); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustNotFailWithInvalidUri() | 		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 = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path }); | ||||||
| 
 | 			sut.Perform(); | ||||||
| 			//sut.Perform(); |  | ||||||
| 			Assert.Fail(); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustUseCommandLineArgumentAs1stPrio() | 		public void MustUseCommandLineArgumentAs1stPrio() | ||||||
| 		{ | 		{ | ||||||
| 			//var path = @"http://www.safeexambrowser.org/whatever.seb"; | 			var path = @"http://www.safeexambrowser.org/whatever.seb"; | ||||||
| 			//var location = Path.GetDirectoryName(GetType().Assembly.Location); | 			var location = Path.GetDirectoryName(GetType().Assembly.Location); | ||||||
| 
 | 
 | ||||||
| 			//info.ProgramDataFolder = location; | 			info.ProgramDataFolder = location; | ||||||
| 			//info.AppDataFolder = 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(); | 			var resource = new Uri(path); | ||||||
| 			//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(path)))), Times.Once); | 
 | ||||||
|  | 			repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustUseProgramDataAs2ndPrio() | 		public void MustUseProgramDataAs2ndPrio() | ||||||
| 		{ | 		{ | ||||||
| 			//var location = Path.GetDirectoryName(GetType().Assembly.Location); | 			var location = Path.GetDirectoryName(GetType().Assembly.Location); | ||||||
| 
 | 
 | ||||||
| 			//info.ProgramDataFolder = location; | 			info.ProgramDataFolder = location; | ||||||
| 			//info.AppDataFolder = $@"{location}\WRONG"; | 			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(); | 			var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); | ||||||
| 			//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once); | 
 | ||||||
|  | 			repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustUseAppDataAs3rdPrio() | 		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(); | 			var resource = new Uri(Path.Combine(location, "SettingsDummy.txt")); | ||||||
| 			//repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(new Uri(Path.Combine(location, "SettingsDummy.txt"))))), Times.Once); | 
 | ||||||
|  | 			repository.Verify(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null), Times.Once); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustFallbackToDefaultsAsLastPrio() | 		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); | ||||||
| 
 |  | ||||||
| 			//repository.Verify(r => r.LoadDefaultSettings(), Times.Once); |  | ||||||
| 			Assert.Fail(); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustAbortIfWishedByUser() | 		public void MustAbortIfWishedByUser() | ||||||
| 		{ | 		{ | ||||||
| 			//info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location); | 			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); | 			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.AreEqual(OperationResult.Aborted, result); | ||||||
| 
 |  | ||||||
| 			Assert.Fail(); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
| 		public void MustNotAbortIfNotWishedByUser() | 		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.AreEqual(OperationResult.Success, result); | ||||||
| 
 |  | ||||||
| 			Assert.Fail(); |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -119,11 +119,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 			{ | 			{ | ||||||
| 				status = repository.LoadSettings(uri, settingsPassword, adminPassword); | 				status = repository.LoadSettings(uri, settingsPassword, adminPassword); | ||||||
| 
 | 
 | ||||||
| 				if (status == LoadStatus.InvalidData || status == LoadStatus.Success) | 				if (status == LoadStatus.AdminPasswordNeeded || status == LoadStatus.SettingsPasswordNeeded) | ||||||
| 				{ |  | ||||||
| 					break; |  | ||||||
| 				} |  | ||||||
| 				else if (status == LoadStatus.AdminPasswordNeeded || status == LoadStatus.SettingsPasswordNeeded) |  | ||||||
| 				{ | 				{ | ||||||
| 					var isAdmin = status == LoadStatus.AdminPasswordNeeded; | 					var isAdmin = status == LoadStatus.AdminPasswordNeeded; | ||||||
| 					var success = isAdmin ? TryGetAdminPassword(out adminPassword) : TryGetSettingsPassword(out settingsPassword); | 					var success = isAdmin ? TryGetAdminPassword(out adminPassword) : TryGetSettingsPassword(out settingsPassword); | ||||||
|  | @ -138,6 +134,10 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 						return OperationResult.Aborted; | 						return OperationResult.Aborted; | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
|  | 				else | ||||||
|  | 				{ | ||||||
|  | 					break; | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if (status == LoadStatus.InvalidData) | 			if (status == LoadStatus.InvalidData) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 dbuechel
						dbuechel