Skip to content

Commit c7468d4

Browse files
committed
SEBWIN-686: Extended unit test coverage for runtime component.
1 parent 1fb7c00 commit c7468d4

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

SafeExamBrowser.Runtime.UnitTests/Operations/Session/KioskModeOperationTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,25 @@ public void Revert_MustCorrectlyRevertDisableExplorerShell()
480480
Assert.AreEqual(OperationResult.Success, revertResult);
481481
}
482482

483+
[TestMethod]
484+
public void Revert_MustNotFailIfNotInitialized()
485+
{
486+
desktopFactory.Reset();
487+
nextSettings.Security.KioskMode = KioskMode.CreateNewDesktop;
488+
489+
try
490+
{
491+
sut.Perform();
492+
}
493+
catch
494+
{
495+
}
496+
497+
var result = sut.Revert();
498+
499+
Assert.AreEqual(OperationResult.Success, result);
500+
}
501+
483502
[TestMethod]
484503
public void MustDoNothingWithoutKioskMode()
485504
{

SafeExamBrowser.Runtime.UnitTests/Operations/Session/ServerOperationTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,39 @@ public void Perform_MustDoNothingIfNormalSession()
311311
Assert.AreEqual(OperationResult.Success, result);
312312
}
313313

314+
[TestMethod]
315+
public void Perform_MustSetCustomBrowserExamKey()
316+
{
317+
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
318+
var browserExamKey = "BEK-TEST-1234";
319+
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
320+
var examSettings = new AppSettings();
321+
var serverSettings = context.Next.Settings.Server;
322+
var examDialog = new Mock<IExamSelectionDialog>();
323+
var serverDialog = new Mock<IServerFailureDialog>();
324+
325+
examDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(Assert.Fail);
326+
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
327+
context.Next.Settings.SessionMode = SessionMode.Server;
328+
context.Next.Settings.Server.ExamId = "some id";
329+
fileSystem.Setup(f => f.Delete(It.IsAny<string>()));
330+
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
331+
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
332+
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
333+
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, new[] { exam }));
334+
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
335+
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, browserExamKey));
336+
serverDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(Assert.Fail);
337+
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
338+
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
339+
340+
var result = sut.Perform();
341+
342+
Assert.AreEqual(browserExamKey, context.Next.Settings.Browser.CustomBrowserExamKey);
343+
Assert.AreEqual(OperationResult.Success, result);
344+
345+
}
346+
314347
[TestMethod]
315348
public void Repeat_MustCorrectlyInitializeServerSession()
316349
{
@@ -420,6 +453,43 @@ public void Repeat_MustFailIfSettingsCouldNotBeLoaded()
420453
Assert.AreEqual(SessionMode.Server, context.Next.Settings.SessionMode);
421454
}
422455

456+
[TestMethod]
457+
public void Repeat_MustFailIfFinalizationOfCurrentSessionFails()
458+
{
459+
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
460+
var dialog = new Mock<IExamSelectionDialog>();
461+
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
462+
var examSettings = new AppSettings();
463+
var initialSettings = context.Next.Settings;
464+
var serverSettings = context.Next.Settings.Server;
465+
466+
dialog
467+
.Setup(d => d.Show(It.IsAny<IWindow>()))
468+
.Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
469+
repository
470+
.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>()))
471+
.Returns(LoadStatus.Success);
472+
context.Current.Settings.SessionMode = SessionMode.Server;
473+
context.Next.Settings.SessionMode = SessionMode.Server;
474+
fileSystem.Setup(f => f.Delete(It.IsAny<string>()));
475+
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
476+
server.Setup(s => s.Disconnect()).Returns(new ServerResponse(false));
477+
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
478+
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
479+
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
480+
server
481+
.Setup(s => s.GetAvailableExams(It.IsAny<string>()))
482+
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
483+
server
484+
.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>()))
485+
.Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
486+
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
487+
488+
var result = sut.Repeat();
489+
490+
Assert.AreEqual(OperationResult.Failed, result);
491+
}
492+
423493
[TestMethod]
424494
public void Repeat_MustCorrectlyAbort()
425495
{

0 commit comments

Comments
 (0)