SEBWIN-301: Fixed test coverage for session operation.
This commit is contained in:
		
							parent
							
								
									e9d91cb898
								
							
						
					
					
						commit
						97bf224b37
					
				
					 1 changed files with 71 additions and 0 deletions
				
			
		| 
						 | 
					@ -15,7 +15,9 @@ using SafeExamBrowser.Contracts.Configuration;
 | 
				
			||||||
using SafeExamBrowser.Contracts.Configuration.Settings;
 | 
					using SafeExamBrowser.Contracts.Configuration.Settings;
 | 
				
			||||||
using SafeExamBrowser.Contracts.Core.OperationModel;
 | 
					using SafeExamBrowser.Contracts.Core.OperationModel;
 | 
				
			||||||
using SafeExamBrowser.Contracts.Logging;
 | 
					using SafeExamBrowser.Contracts.Logging;
 | 
				
			||||||
 | 
					using SafeExamBrowser.Contracts.UserInterface.MessageBox;
 | 
				
			||||||
using SafeExamBrowser.Runtime.Operations;
 | 
					using SafeExamBrowser.Runtime.Operations;
 | 
				
			||||||
 | 
					using SafeExamBrowser.Runtime.Operations.Events;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
					namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -133,16 +135,34 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
				
			||||||
			service.Verify(s => s.StartSession(It.IsAny<ServiceConfiguration>()), Times.Never);
 | 
								service.Verify(s => s.StartSession(It.IsAny<ServiceConfiguration>()), Times.Never);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[TestMethod]
 | 
				
			||||||
 | 
							public void Perform_MustHandleCommunicationFailureWhenStartingSession()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								service.SetupGet(s => s.IsConnected).Returns(true);
 | 
				
			||||||
 | 
								service.Setup(s => s.Connect(null, true)).Returns(true);
 | 
				
			||||||
 | 
								service.Setup(s => s.StartSession(It.IsAny<ServiceConfiguration>())).Returns(new CommunicationResult(false));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var result = sut.Perform();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								service.Verify(s => s.StartSession(It.IsAny<ServiceConfiguration>()), Times.Once);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(OperationResult.Failed, result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[TestMethod]
 | 
							[TestMethod]
 | 
				
			||||||
		public void Perform_MustFailIfServiceMandatoryAndNotAvailable()
 | 
							public void Perform_MustFailIfServiceMandatoryAndNotAvailable()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
								var errorShown = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			service.SetupGet(s => s.IsConnected).Returns(false);
 | 
								service.SetupGet(s => s.IsConnected).Returns(false);
 | 
				
			||||||
			service.Setup(s => s.Connect(null, true)).Returns(false);
 | 
								service.Setup(s => s.Connect(null, true)).Returns(false);
 | 
				
			||||||
			settings.ServicePolicy = ServicePolicy.Mandatory;
 | 
								settings.ServicePolicy = ServicePolicy.Mandatory;
 | 
				
			||||||
 | 
								sut.ActionRequired += (args) => errorShown = args is MessageEventArgs m && m.Icon == MessageBoxIcon.Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var result = sut.Perform();
 | 
								var result = sut.Perform();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Assert.AreEqual(OperationResult.Failed, result);
 | 
								Assert.AreEqual(OperationResult.Failed, result);
 | 
				
			||||||
 | 
								Assert.IsTrue(errorShown);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[TestMethod]
 | 
							[TestMethod]
 | 
				
			||||||
| 
						 | 
					@ -158,6 +178,22 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
				
			||||||
			Assert.AreEqual(OperationResult.Success, result);
 | 
								Assert.AreEqual(OperationResult.Success, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[TestMethod]
 | 
				
			||||||
 | 
							public void Perform_MustShowWarningIfServiceNotAvailableAndPolicyWarn()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								var warningShown = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								service.SetupGet(s => s.IsConnected).Returns(false);
 | 
				
			||||||
 | 
								service.Setup(s => s.Connect(null, true)).Returns(false);
 | 
				
			||||||
 | 
								settings.ServicePolicy = ServicePolicy.Warn;
 | 
				
			||||||
 | 
								sut.ActionRequired += (args) => warningShown = args is MessageEventArgs m && m.Icon == MessageBoxIcon.Warning;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var result = sut.Perform();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(OperationResult.Success, result);
 | 
				
			||||||
 | 
								Assert.IsTrue(warningShown);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[TestMethod]
 | 
							[TestMethod]
 | 
				
			||||||
		public void Repeat_MustStopCurrentAndStartNewSession()
 | 
							public void Repeat_MustStopCurrentAndStartNewSession()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					@ -178,6 +214,26 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
				
			||||||
			Assert.AreEqual(OperationResult.Success, result);
 | 
								Assert.AreEqual(OperationResult.Success, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[TestMethod]
 | 
				
			||||||
 | 
							public void Repeat_MustEstablishConnectionIfNotConnected()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								PerformNormally();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								service.Reset();
 | 
				
			||||||
 | 
								service.SetupGet(s => s.IsConnected).Returns(false);
 | 
				
			||||||
 | 
								service.Setup(s => s.Connect(null, true)).Returns(true);
 | 
				
			||||||
 | 
								service
 | 
				
			||||||
 | 
									.Setup(s => s.StopSession(It.IsAny<Guid>()))
 | 
				
			||||||
 | 
									.Returns(new CommunicationResult(true))
 | 
				
			||||||
 | 
									.Callback(() => runtimeHost.Raise(h => h.ServiceSessionStopped += null));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var result = sut.Repeat();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								service.Verify(s => s.Connect(It.IsAny<Guid?>(), It.IsAny<bool>()), Times.Once);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(OperationResult.Success, result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[TestMethod]
 | 
							[TestMethod]
 | 
				
			||||||
		public void Repeat_MustFailIfCurrentSessionWasNotStoppedSuccessfully()
 | 
							public void Repeat_MustFailIfCurrentSessionWasNotStoppedSuccessfully()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					@ -273,6 +329,21 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
 | 
				
			||||||
			Assert.AreEqual(OperationResult.Failed, result);
 | 
								Assert.AreEqual(OperationResult.Failed, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[TestMethod]
 | 
				
			||||||
 | 
							public void Revert_MustFailIfSessionStopUnsuccessful()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								service
 | 
				
			||||||
 | 
									.Setup(s => s.StopSession(It.IsAny<Guid>()))
 | 
				
			||||||
 | 
									.Returns(new CommunicationResult(true))
 | 
				
			||||||
 | 
									.Callback(() => runtimeHost.Raise(h => h.ServiceFailed += null));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								PerformNormally();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var result = sut.Revert();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(OperationResult.Failed, result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[TestMethod]
 | 
							[TestMethod]
 | 
				
			||||||
		public void Revert_MustFailIfSessionNotStoppedWithinTimeout()
 | 
							public void Revert_MustFailIfSessionNotStoppedWithinTimeout()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue