2018-09-04 10:58:56 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2018-10-12 15:23:43 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2018-09-04 10:58:56 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Configuration.UnitTests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ConfigurationRepositoryTests
|
|
|
|
|
{
|
|
|
|
|
private ConfigurationRepository sut;
|
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
var executablePath = Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
|
|
|
|
|
sut = new ConfigurationRepository(executablePath, string.Empty, string.Empty, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCorrectlyInitializeSessionConfiguration()
|
|
|
|
|
{
|
2018-10-12 15:23:43 +02:00
|
|
|
|
var appConfig = sut.InitializeAppConfig();
|
|
|
|
|
var configuration = sut.InitializeSessionConfiguration();
|
2018-09-04 10:58:56 +02:00
|
|
|
|
|
2018-10-12 15:23:43 +02:00
|
|
|
|
Assert.IsInstanceOfType(configuration.AppConfig, typeof(AppConfig));
|
|
|
|
|
Assert.IsInstanceOfType(configuration.Id, typeof(Guid));
|
|
|
|
|
Assert.IsNull(configuration.Settings);
|
|
|
|
|
Assert.IsInstanceOfType(configuration.StartupToken, typeof(Guid));
|
2018-09-04 10:58:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCorrectlyUpdateAppConfig()
|
|
|
|
|
{
|
2018-10-12 15:23:43 +02:00
|
|
|
|
var appConfig = sut.InitializeAppConfig();
|
|
|
|
|
var clientAddress = appConfig.ClientAddress;
|
|
|
|
|
var clientId = appConfig.ClientId;
|
|
|
|
|
var clientLogFile = appConfig.ClientLogFile;
|
|
|
|
|
var runtimeAddress = appConfig.RuntimeAddress;
|
|
|
|
|
var runtimeId = appConfig.RuntimeId;
|
|
|
|
|
var runtimeLogFile = appConfig.RuntimeLogFile;
|
|
|
|
|
var configuration = sut.InitializeSessionConfiguration();
|
|
|
|
|
|
|
|
|
|
Assert.AreNotEqual(configuration.AppConfig.ClientAddress, clientAddress);
|
|
|
|
|
Assert.AreNotEqual(configuration.AppConfig.ClientId, clientId);
|
|
|
|
|
Assert.AreEqual(configuration.AppConfig.ClientLogFile, clientLogFile);
|
|
|
|
|
Assert.AreEqual(configuration.AppConfig.RuntimeAddress, runtimeAddress);
|
|
|
|
|
Assert.AreEqual(configuration.AppConfig.RuntimeId, runtimeId);
|
|
|
|
|
Assert.AreEqual(configuration.AppConfig.RuntimeLogFile, runtimeLogFile);
|
2018-09-04 10:58:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCorrectlyUpdateSessionConfiguration()
|
|
|
|
|
{
|
2018-10-12 15:23:43 +02:00
|
|
|
|
var appConfig = sut.InitializeAppConfig();
|
|
|
|
|
var firstSession = sut.InitializeSessionConfiguration();
|
|
|
|
|
var secondSession = sut.InitializeSessionConfiguration();
|
|
|
|
|
var thirdSession = sut.InitializeSessionConfiguration();
|
2018-09-04 10:58:56 +02:00
|
|
|
|
|
|
|
|
|
Assert.AreNotEqual(firstSession.Id, secondSession.Id);
|
|
|
|
|
Assert.AreNotEqual(firstSession.StartupToken, secondSession.StartupToken);
|
|
|
|
|
Assert.AreNotEqual(secondSession.Id, thirdSession.Id);
|
|
|
|
|
Assert.AreNotEqual(secondSession.StartupToken, thirdSession.StartupToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|