SEBWIN-220: Extended unit test coverage for SafeExamBrowser.Configuration and SafeExamBrowser.Runtime.
This commit is contained in:
parent
8280ac3a92
commit
693829f641
17 changed files with 451 additions and 40 deletions
|
@ -0,0 +1,157 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
using Moq;
|
||||||
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
|
using SafeExamBrowser.Contracts.WindowsApi;
|
||||||
|
|
||||||
|
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 AppConfigMustNeverBeNull()
|
||||||
|
{
|
||||||
|
Assert.IsNotNull(sut.AppConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CurrentSessionIsInitiallyNull()
|
||||||
|
{
|
||||||
|
Assert.IsNull(sut.CurrentSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CurrentSettingsAreInitiallyNull()
|
||||||
|
{
|
||||||
|
Assert.IsNull(sut.CurrentSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustCorrectlyBuildClientConfiguration()
|
||||||
|
{
|
||||||
|
sut.LoadDefaultSettings();
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
var appConfig = sut.AppConfig;
|
||||||
|
var clientConfig = sut.BuildClientConfiguration();
|
||||||
|
var session = sut.CurrentSession;
|
||||||
|
var settings = sut.CurrentSettings;
|
||||||
|
|
||||||
|
Assert.AreEqual(session.Id, clientConfig.SessionId);
|
||||||
|
Assert.AreSame(appConfig, clientConfig.AppConfig);
|
||||||
|
Assert.AreSame(settings, clientConfig.Settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustCorrectlyInitializeSessionConfiguration()
|
||||||
|
{
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
Assert.IsNull(sut.CurrentSession.ClientProcess);
|
||||||
|
Assert.IsNull(sut.CurrentSession.ClientProxy);
|
||||||
|
Assert.IsInstanceOfType(sut.CurrentSession.Id, typeof(Guid));
|
||||||
|
Assert.IsInstanceOfType(sut.CurrentSession.StartupToken, typeof(Guid));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustCorrectlyUpdateAppConfig()
|
||||||
|
{
|
||||||
|
var clientAddress = sut.AppConfig.ClientAddress;
|
||||||
|
var clientId = sut.AppConfig.ClientId;
|
||||||
|
var clientLogFile = sut.AppConfig.ClientLogFile;
|
||||||
|
var runtimeAddress = sut.AppConfig.RuntimeAddress;
|
||||||
|
var runtimeId = sut.AppConfig.RuntimeId;
|
||||||
|
var runtimeLogFile = sut.AppConfig.RuntimeLogFile;
|
||||||
|
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
Assert.AreNotEqual(sut.AppConfig.ClientAddress, clientAddress);
|
||||||
|
Assert.AreNotEqual(sut.AppConfig.ClientId, clientId);
|
||||||
|
Assert.AreEqual(sut.AppConfig.ClientLogFile, clientLogFile);
|
||||||
|
Assert.AreEqual(sut.AppConfig.RuntimeAddress, runtimeAddress);
|
||||||
|
Assert.AreEqual(sut.AppConfig.RuntimeId, runtimeId);
|
||||||
|
Assert.AreEqual(sut.AppConfig.RuntimeLogFile, runtimeLogFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustCorrectlyUpdateSessionConfiguration()
|
||||||
|
{
|
||||||
|
var process = new Mock<IProcess>();
|
||||||
|
var proxy = new Mock<IClientProxy>();
|
||||||
|
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
var firstSession = sut.CurrentSession;
|
||||||
|
|
||||||
|
sut.CurrentSession.ClientProcess = process.Object;
|
||||||
|
sut.CurrentSession.ClientProxy = proxy.Object;
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
var secondSession = sut.CurrentSession;
|
||||||
|
|
||||||
|
Assert.AreSame(firstSession.ClientProcess, secondSession.ClientProcess);
|
||||||
|
Assert.AreSame(firstSession.ClientProxy, secondSession.ClientProxy);
|
||||||
|
Assert.AreNotEqual(firstSession.Id, secondSession.Id);
|
||||||
|
Assert.AreNotEqual(firstSession.StartupToken, secondSession.StartupToken);
|
||||||
|
|
||||||
|
sut.CurrentSession.ClientProcess = null;
|
||||||
|
sut.CurrentSession.ClientProxy = null;
|
||||||
|
sut.InitializeSessionConfiguration();
|
||||||
|
|
||||||
|
var thirdSession = sut.CurrentSession;
|
||||||
|
|
||||||
|
Assert.IsNull(thirdSession.ClientProcess);
|
||||||
|
Assert.IsNull(thirdSession.ClientProxy);
|
||||||
|
Assert.AreNotEqual(secondSession.Id, thirdSession.Id);
|
||||||
|
Assert.AreNotEqual(secondSession.StartupToken, thirdSession.StartupToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void MustNotAllowNullForExecutablePath()
|
||||||
|
{
|
||||||
|
new ConfigurationRepository(null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void MustNotAllowNullForProgramCopyright()
|
||||||
|
{
|
||||||
|
new ConfigurationRepository(string.Empty, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void MustNotAllowNullForProgramTitle()
|
||||||
|
{
|
||||||
|
new ConfigurationRepository(string.Empty, string.Empty, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void MustNotAllowNullForProgramVersion()
|
||||||
|
{
|
||||||
|
new ConfigurationRepository(string.Empty, string.Empty, string.Empty, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("SafeExamBrowser.Configuration.UnitTests")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("SafeExamBrowser.Configuration.UnitTests")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
[assembly: Guid("9cdd03e7-ed65-409f-8c07-bd6f633a0170")]
|
||||||
|
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{9CDD03E7-ED65-409F-8C07-BD6F633A0170}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>SafeExamBrowser.Configuration.UnitTests</RootNamespace>
|
||||||
|
<AssemblyName>SafeExamBrowser.Configuration.UnitTests</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||||
|
<IsCodedUITest>False</IsCodedUITest>
|
||||||
|
<TestProjectType>UnitTest</TestProjectType>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||||
|
<OutputPath>bin\x86\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Moq, Version=4.9.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Moq.4.9.0\lib\net45\Moq.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="ConfigurationRepositoryTests.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="app.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SafeExamBrowser.Configuration\SafeExamBrowser.Configuration.csproj">
|
||||||
|
<Project>{c388c4dd-a159-457d-af92-89f7ad185109}</Project>
|
||||||
|
<Name>SafeExamBrowser.Configuration</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\SafeExamBrowser.Contracts\SafeExamBrowser.Contracts.csproj">
|
||||||
|
<Project>{47da5933-bef8-4729-94e6-abde2db12262}</Project>
|
||||||
|
<Name>SafeExamBrowser.Contracts</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
|
||||||
|
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
|
||||||
|
</Target>
|
||||||
|
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
|
||||||
|
</Project>
|
15
SafeExamBrowser.Configuration.UnitTests/app.config
Normal file
15
SafeExamBrowser.Configuration.UnitTests/app.config
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
10
SafeExamBrowser.Configuration.UnitTests/packages.config
Normal file
10
SafeExamBrowser.Configuration.UnitTests/packages.config
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Castle.Core" version="4.3.1" targetFramework="net452" />
|
||||||
|
<package id="Moq" version="4.9.0" targetFramework="net452" />
|
||||||
|
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net452" />
|
||||||
|
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net452" />
|
||||||
|
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="net452" />
|
||||||
|
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net452" />
|
||||||
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net452" />
|
||||||
|
</packages>
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
|
@ -19,7 +18,11 @@ namespace SafeExamBrowser.Configuration
|
||||||
{
|
{
|
||||||
private const string BASE_ADDRESS = "net.pipe://localhost/safeexambrowser";
|
private const string BASE_ADDRESS = "net.pipe://localhost/safeexambrowser";
|
||||||
|
|
||||||
private bool firstSession = true;
|
private readonly string executablePath;
|
||||||
|
private readonly string programCopyright;
|
||||||
|
private readonly string programTitle;
|
||||||
|
private readonly string programVersion;
|
||||||
|
|
||||||
private AppConfig appConfig;
|
private AppConfig appConfig;
|
||||||
|
|
||||||
public ISessionData CurrentSession { get; private set; }
|
public ISessionData CurrentSession { get; private set; }
|
||||||
|
@ -39,6 +42,14 @@ namespace SafeExamBrowser.Configuration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigurationRepository(string executablePath, string programCopyright, string programTitle, string programVersion)
|
||||||
|
{
|
||||||
|
this.executablePath = executablePath ?? throw new ArgumentNullException(nameof(executablePath));
|
||||||
|
this.programCopyright = programCopyright ?? throw new ArgumentNullException(nameof(programCopyright));
|
||||||
|
this.programTitle = programTitle ?? throw new ArgumentNullException(nameof(programTitle));
|
||||||
|
this.programVersion = programVersion ?? throw new ArgumentNullException(nameof(programVersion));
|
||||||
|
}
|
||||||
|
|
||||||
public ClientConfiguration BuildClientConfiguration()
|
public ClientConfiguration BuildClientConfiguration()
|
||||||
{
|
{
|
||||||
return new ClientConfiguration
|
return new ClientConfiguration
|
||||||
|
@ -53,18 +64,13 @@ namespace SafeExamBrowser.Configuration
|
||||||
{
|
{
|
||||||
CurrentSession = new SessionData
|
CurrentSession = new SessionData
|
||||||
{
|
{
|
||||||
|
ClientProcess = CurrentSession?.ClientProcess,
|
||||||
|
ClientProxy = CurrentSession?.ClientProxy,
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
StartupToken = Guid.NewGuid()
|
StartupToken = Guid.NewGuid()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!firstSession)
|
UpdateAppConfig();
|
||||||
{
|
|
||||||
UpdateAppConfig();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
firstSession = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoadStatus LoadSettings(Uri resource, string settingsPassword = null, string adminPassword = null)
|
public LoadStatus LoadSettings(Uri resource, string settingsPassword = null, string adminPassword = null)
|
||||||
|
@ -101,7 +107,6 @@ namespace SafeExamBrowser.Configuration
|
||||||
private void InitializeAppConfig()
|
private void InitializeAppConfig()
|
||||||
{
|
{
|
||||||
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(SafeExamBrowser));
|
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(SafeExamBrowser));
|
||||||
var executable = Assembly.GetEntryAssembly();
|
|
||||||
var startTime = DateTime.Now;
|
var startTime = DateTime.Now;
|
||||||
var logFolder = Path.Combine(appDataFolder, "Logs");
|
var logFolder = Path.Combine(appDataFolder, "Logs");
|
||||||
var logFilePrefix = startTime.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
|
var logFilePrefix = startTime.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
|
||||||
|
@ -113,16 +118,16 @@ namespace SafeExamBrowser.Configuration
|
||||||
appConfig.BrowserLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Browser.log");
|
appConfig.BrowserLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Browser.log");
|
||||||
appConfig.ClientId = Guid.NewGuid();
|
appConfig.ClientId = Guid.NewGuid();
|
||||||
appConfig.ClientAddress = $"{BASE_ADDRESS}/client/{Guid.NewGuid()}";
|
appConfig.ClientAddress = $"{BASE_ADDRESS}/client/{Guid.NewGuid()}";
|
||||||
appConfig.ClientExecutablePath = Path.Combine(Path.GetDirectoryName(executable.Location), $"{nameof(SafeExamBrowser)}.Client.exe");
|
appConfig.ClientExecutablePath = Path.Combine(Path.GetDirectoryName(executablePath), $"{nameof(SafeExamBrowser)}.Client.exe");
|
||||||
appConfig.ClientLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Client.log");
|
appConfig.ClientLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Client.log");
|
||||||
appConfig.ConfigurationFileExtension = ".seb";
|
appConfig.ConfigurationFileExtension = ".seb";
|
||||||
appConfig.DefaultSettingsFileName = "SebClientSettings.seb";
|
appConfig.DefaultSettingsFileName = "SebClientSettings.seb";
|
||||||
appConfig.DownloadDirectory = Path.Combine(appDataFolder, "Downloads");
|
appConfig.DownloadDirectory = Path.Combine(appDataFolder, "Downloads");
|
||||||
appConfig.LogLevel = LogLevel.Debug;
|
appConfig.LogLevel = LogLevel.Debug;
|
||||||
appConfig.ProgramCopyright = executable.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
|
appConfig.ProgramCopyright = programCopyright;
|
||||||
appConfig.ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), nameof(SafeExamBrowser));
|
appConfig.ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), nameof(SafeExamBrowser));
|
||||||
appConfig.ProgramTitle = executable.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
appConfig.ProgramTitle = programTitle;
|
||||||
appConfig.ProgramVersion = executable.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
appConfig.ProgramVersion = programVersion;
|
||||||
appConfig.RuntimeId = Guid.NewGuid();
|
appConfig.RuntimeId = Guid.NewGuid();
|
||||||
appConfig.RuntimeAddress = $"{BASE_ADDRESS}/runtime/{Guid.NewGuid()}";
|
appConfig.RuntimeAddress = $"{BASE_ADDRESS}/runtime/{Guid.NewGuid()}";
|
||||||
appConfig.RuntimeLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Runtime.log");
|
appConfig.RuntimeLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Runtime.log");
|
||||||
|
|
|
@ -58,6 +58,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
configuration.SetupGet(c => c.CurrentSession).Returns(session.Object);
|
configuration.SetupGet(c => c.CurrentSession).Returns(session.Object);
|
||||||
configuration.SetupGet(c => c.AppConfig).Returns(appConfig);
|
configuration.SetupGet(c => c.AppConfig).Returns(appConfig);
|
||||||
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).Returns(proxy.Object);
|
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).Returns(proxy.Object);
|
||||||
|
session.SetupGet(s => s.ClientProcess).Returns(process.Object);
|
||||||
|
session.SetupGet(s => s.ClientProxy).Returns(proxy.Object);
|
||||||
|
|
||||||
sut = new ClientOperation(configuration.Object, logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
sut = new ClientOperation(configuration.Object, logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
||||||
}
|
}
|
||||||
|
@ -125,8 +127,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
|
|
||||||
result = sut.Perform();
|
result = sut.Perform();
|
||||||
|
|
||||||
session.VerifySet(s => s.ClientProcess = process.Object, Times.Never);
|
session.VerifySet(s => s.ClientProcess = process.Object, Times.Once);
|
||||||
session.VerifySet(s => s.ClientProxy = proxy.Object, Times.Never);
|
session.VerifySet(s => s.ClientProxy = proxy.Object, Times.Once);
|
||||||
|
|
||||||
Assert.AreEqual(OperationResult.Failed, result);
|
Assert.AreEqual(OperationResult.Failed, result);
|
||||||
}
|
}
|
||||||
|
@ -145,8 +147,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
|
|
||||||
result = sut.Perform();
|
result = sut.Perform();
|
||||||
|
|
||||||
session.VerifySet(s => s.ClientProcess = process.Object, Times.Never);
|
session.VerifySet(s => s.ClientProcess = process.Object, Times.Once);
|
||||||
session.VerifySet(s => s.ClientProxy = proxy.Object, Times.Never);
|
session.VerifySet(s => s.ClientProxy = proxy.Object, Times.Once);
|
||||||
|
|
||||||
Assert.AreEqual(OperationResult.Failed, result);
|
Assert.AreEqual(OperationResult.Failed, result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ using Moq;
|
||||||
using SafeExamBrowser.Contracts.Communication.Hosts;
|
using SafeExamBrowser.Contracts.Communication.Hosts;
|
||||||
using SafeExamBrowser.Contracts.Communication.Proxies;
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
using SafeExamBrowser.Contracts.WindowsApi;
|
using SafeExamBrowser.Contracts.WindowsApi;
|
||||||
using SafeExamBrowser.Runtime.Operations;
|
using SafeExamBrowser.Runtime.Operations;
|
||||||
|
@ -50,6 +51,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
configuration.SetupGet(c => c.CurrentSession).Returns(session.Object);
|
configuration.SetupGet(c => c.CurrentSession).Returns(session.Object);
|
||||||
configuration.SetupGet(c => c.AppConfig).Returns(appConfig);
|
configuration.SetupGet(c => c.AppConfig).Returns(appConfig);
|
||||||
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).Returns(proxy.Object);
|
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>())).Returns(proxy.Object);
|
||||||
|
session.SetupGet(s => s.ClientProxy).Returns(proxy.Object);
|
||||||
|
|
||||||
sut = new ClientTerminationOperation(configuration.Object, logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
sut = new ClientTerminationOperation(configuration.Object, logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
||||||
}
|
}
|
||||||
|
@ -59,9 +61,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
{
|
{
|
||||||
sut.Perform();
|
sut.Perform();
|
||||||
|
|
||||||
|
process.VerifyNoOtherCalls();
|
||||||
processFactory.VerifyNoOtherCalls();
|
processFactory.VerifyNoOtherCalls();
|
||||||
proxy.VerifyNoOtherCalls();
|
proxy.VerifyNoOtherCalls();
|
||||||
proxyFactory.VerifyNoOtherCalls();
|
proxyFactory.VerifyNoOtherCalls();
|
||||||
|
runtimeHost.VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
@ -70,15 +74,71 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
sut.Revert();
|
sut.Revert();
|
||||||
|
|
||||||
process.VerifyNoOtherCalls();
|
process.VerifyNoOtherCalls();
|
||||||
|
processFactory.VerifyNoOtherCalls();
|
||||||
proxy.VerifyNoOtherCalls();
|
proxy.VerifyNoOtherCalls();
|
||||||
|
proxyFactory.VerifyNoOtherCalls();
|
||||||
runtimeHost.VerifyNoOtherCalls();
|
runtimeHost.VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TODO()
|
public void MustTerminateClientOnRepeat()
|
||||||
{
|
{
|
||||||
// TODO: MustStartClientOnRepeat -> Extract static fields from operation -> allows unit testing of this requirement etc.!
|
var terminated = new Action(() =>
|
||||||
Assert.Fail();
|
{
|
||||||
|
runtimeHost.Raise(h => h.ClientDisconnected += null);
|
||||||
|
process.Raise(p => p.Terminated += null, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
proxy.Setup(p => p.Disconnect()).Callback(terminated);
|
||||||
|
session.SetupGet(s => s.ClientProcess).Returns(process.Object);
|
||||||
|
|
||||||
|
var result = sut.Repeat();
|
||||||
|
|
||||||
|
proxy.Verify(p => p.InitiateShutdown(), Times.Once);
|
||||||
|
proxy.Verify(p => p.Disconnect(), Times.Once);
|
||||||
|
process.Verify(p => p.Kill(), Times.Never);
|
||||||
|
session.VerifySet(s => s.ClientProcess = null, Times.Once);
|
||||||
|
session.VerifySet(s => s.ClientProxy = null, Times.Once);
|
||||||
|
|
||||||
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustDoNothingIfNoClientCreated()
|
||||||
|
{
|
||||||
|
session.SetupGet(s => s.ClientProcess).Returns(null as IProcess);
|
||||||
|
|
||||||
|
var result = sut.Repeat();
|
||||||
|
|
||||||
|
session.VerifyGet(s => s.ClientProcess, Times.Once);
|
||||||
|
|
||||||
|
process.VerifyNoOtherCalls();
|
||||||
|
processFactory.VerifyNoOtherCalls();
|
||||||
|
proxy.VerifyNoOtherCalls();
|
||||||
|
proxyFactory.VerifyNoOtherCalls();
|
||||||
|
runtimeHost.VerifyNoOtherCalls();
|
||||||
|
|
||||||
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustDoNothingIfNoClientRunning()
|
||||||
|
{
|
||||||
|
process.SetupGet(p => p.HasTerminated).Returns(true);
|
||||||
|
session.SetupGet(s => s.ClientProcess).Returns(process.Object);
|
||||||
|
|
||||||
|
var result = sut.Repeat();
|
||||||
|
|
||||||
|
process.VerifyGet(p => p.HasTerminated, Times.Once);
|
||||||
|
session.VerifyGet(s => s.ClientProcess, Times.Exactly(2));
|
||||||
|
|
||||||
|
process.VerifyNoOtherCalls();
|
||||||
|
processFactory.VerifyNoOtherCalls();
|
||||||
|
proxy.VerifyNoOtherCalls();
|
||||||
|
proxyFactory.VerifyNoOtherCalls();
|
||||||
|
runtimeHost.VerifyNoOtherCalls();
|
||||||
|
|
||||||
|
Assert.AreEqual(OperationResult.Success, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,13 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
using SafeExamBrowser.Contracts.Core.OperationModel;
|
|
||||||
using SafeExamBrowser.Contracts.Communication.Data;
|
using SafeExamBrowser.Contracts.Communication.Data;
|
||||||
using SafeExamBrowser.Contracts.Communication.Events;
|
using SafeExamBrowser.Contracts.Communication.Events;
|
||||||
using SafeExamBrowser.Contracts.Communication.Hosts;
|
using SafeExamBrowser.Contracts.Communication.Hosts;
|
||||||
using SafeExamBrowser.Contracts.Communication.Proxies;
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||||
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
using SafeExamBrowser.Contracts.I18n;
|
using SafeExamBrowser.Contracts.I18n;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
using SafeExamBrowser.Contracts.UserInterface;
|
using SafeExamBrowser.Contracts.UserInterface;
|
||||||
|
@ -68,7 +68,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
public void MustUseCommandLineArgumentAs1stPrio()
|
public void MustUseCommandLineArgumentAs1stPrio()
|
||||||
{
|
{
|
||||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
||||||
|
|
||||||
appConfig.ProgramDataFolder = location;
|
appConfig.ProgramDataFolder = location;
|
||||||
appConfig.AppDataFolder = location;
|
appConfig.AppDataFolder = location;
|
||||||
|
@ -86,7 +86,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustUseProgramDataAs2ndPrio()
|
public void MustUseProgramDataAs2ndPrio()
|
||||||
{
|
{
|
||||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
||||||
|
|
||||||
appConfig.ProgramDataFolder = location;
|
appConfig.ProgramDataFolder = location;
|
||||||
appConfig.AppDataFolder = $@"{location}\WRONG";
|
appConfig.AppDataFolder = $@"{location}\WRONG";
|
||||||
|
@ -104,7 +104,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustUseAppDataAs3rdPrio()
|
public void MustUseAppDataAs3rdPrio()
|
||||||
{
|
{
|
||||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
var location = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
||||||
|
|
||||||
appConfig.AppDataFolder = location;
|
appConfig.AppDataFolder = location;
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustAbortIfWishedByUser()
|
public void MustAbortIfWishedByUser()
|
||||||
{
|
{
|
||||||
appConfig.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location);
|
appConfig.ProgramDataFolder = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations));
|
||||||
messageBox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.Yes);
|
messageBox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>())).Returns(MessageBoxResult.Yes);
|
||||||
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
repository.Setup(r => r.LoadSettings(It.IsAny<Uri>(), null, null)).Returns(LoadStatus.Success);
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||||
public void MustReconfigureSuccessfullyWithCorrectUri()
|
public void MustReconfigureSuccessfullyWithCorrectUri()
|
||||||
{
|
{
|
||||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
||||||
var resource = new Uri(Path.Combine(location, "SettingsDummy.txt"));
|
var resource = new Uri(Path.Combine(location, nameof(Operations), "SettingsDummy.txt"));
|
||||||
|
|
||||||
repository.SetupGet(r => r.ReconfigurationFilePath).Returns(resource.AbsolutePath);
|
repository.SetupGet(r => r.ReconfigurationFilePath).Returns(resource.AbsolutePath);
|
||||||
repository.Setup(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null)).Returns(LoadStatus.Success);
|
repository.Setup(r => r.LoadSettings(It.Is<Uri>(u => u.Equals(resource)), null, null)).Returns(LoadStatus.Success);
|
||||||
|
|
|
@ -113,10 +113,10 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="SettingsDummy.txt">
|
<Content Include="Operations\SettingsDummy.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="WRONG\SettingsDummy.txt">
|
<Content Include="Operations\WRONG\SettingsDummy.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace SafeExamBrowser.Runtime
|
||||||
const int TEN_SECONDS = 10000;
|
const int TEN_SECONDS = 10000;
|
||||||
|
|
||||||
var args = Environment.GetCommandLineArgs();
|
var args = Environment.GetCommandLineArgs();
|
||||||
var configuration = new ConfigurationRepository();
|
var configuration = BuildConfigurationRepository();
|
||||||
var nativeMethods = new NativeMethods();
|
var nativeMethods = new NativeMethods();
|
||||||
|
|
||||||
logger = new Logger();
|
logger = new Logger();
|
||||||
|
@ -101,6 +101,17 @@ namespace SafeExamBrowser.Runtime
|
||||||
logger?.Log($"# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
logger?.Log($"# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConfigurationRepository BuildConfigurationRepository()
|
||||||
|
{
|
||||||
|
var executable = Assembly.GetExecutingAssembly();
|
||||||
|
var programCopyright = executable.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
|
||||||
|
var programTitle = executable.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
||||||
|
var programVersion = executable.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||||
|
var repository = new ConfigurationRepository(executable.Location, programCopyright, programTitle, programVersion);
|
||||||
|
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializeLogging()
|
private void InitializeLogging()
|
||||||
{
|
{
|
||||||
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), appConfig.RuntimeLogFile);
|
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), appConfig.RuntimeLogFile);
|
||||||
|
|
|
@ -30,10 +30,20 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
protected IProxyFactory proxyFactory;
|
protected IProxyFactory proxyFactory;
|
||||||
protected IRuntimeHost runtimeHost;
|
protected IRuntimeHost runtimeHost;
|
||||||
|
|
||||||
protected static IProcess ClientProcess { get; private set; }
|
|
||||||
protected static IClientProxy ClientProxy { get; private set; }
|
|
||||||
public IProgressIndicator ProgressIndicator { protected get; set; }
|
public IProgressIndicator ProgressIndicator { protected get; set; }
|
||||||
|
|
||||||
|
protected IProcess ClientProcess
|
||||||
|
{
|
||||||
|
get { return configuration.CurrentSession.ClientProcess; }
|
||||||
|
set { configuration.CurrentSession.ClientProcess = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IClientProxy ClientProxy
|
||||||
|
{
|
||||||
|
get { return configuration.CurrentSession.ClientProxy; }
|
||||||
|
set { configuration.CurrentSession.ClientProxy = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public ClientOperation(
|
public ClientOperation(
|
||||||
IConfigurationRepository configuration,
|
IConfigurationRepository configuration,
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
|
@ -132,9 +142,6 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
|
|
||||||
logger.Info("Authentication of client has been successful, client is ready to operate.");
|
logger.Info("Authentication of client has been successful, client is ready to operate.");
|
||||||
|
|
||||||
configuration.CurrentSession.ClientProcess = ClientProcess;
|
|
||||||
configuration.CurrentSession.ClientProxy = ClientProxy;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +198,8 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
configuration.CurrentSession.ClientProcess = null;
|
ClientProcess = null;
|
||||||
configuration.CurrentSession.ClientProxy = null;
|
ClientProxy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* 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 SafeExamBrowser.Contracts.Core.OperationModel;
|
|
||||||
using SafeExamBrowser.Contracts.Communication.Hosts;
|
using SafeExamBrowser.Contracts.Communication.Hosts;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||||
using SafeExamBrowser.Contracts.I18n;
|
using SafeExamBrowser.Contracts.I18n;
|
||||||
using SafeExamBrowser.Contracts.Logging;
|
using SafeExamBrowser.Contracts.Logging;
|
||||||
using SafeExamBrowser.Contracts.UserInterface;
|
using SafeExamBrowser.Contracts.UserInterface;
|
||||||
|
@ -58,7 +58,7 @@ namespace SafeExamBrowser.Runtime.Operations
|
||||||
runtimeHost.StartupToken = configuration.CurrentSession.StartupToken;
|
runtimeHost.StartupToken = configuration.CurrentSession.StartupToken;
|
||||||
|
|
||||||
logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}");
|
logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}");
|
||||||
logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId} (as reference, does not change)");
|
logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}");
|
||||||
logger.Info($" -> Session-ID: {configuration.CurrentSession.Id}");
|
logger.Info($" -> Session-ID: {configuration.CurrentSession.Id}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Logging", "
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Logging.UnitTests", "SafeExamBrowser.Logging.UnitTests\SafeExamBrowser.Logging.UnitTests.csproj", "{7F012305-1125-47CE-9C2A-146C891C0924}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Logging.UnitTests", "SafeExamBrowser.Logging.UnitTests\SafeExamBrowser.Logging.UnitTests.csproj", "{7F012305-1125-47CE-9C2A-146C891C0924}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Configuration.UnitTests", "SafeExamBrowser.Configuration.UnitTests\SafeExamBrowser.Configuration.UnitTests.csproj", "{9CDD03E7-ED65-409F-8C07-BD6F633A0170}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -222,6 +224,14 @@ Global
|
||||||
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|x86.ActiveCfg = Release|x86
|
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|x86.ActiveCfg = Release|x86
|
||||||
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|x86.Build.0 = Release|x86
|
{7F012305-1125-47CE-9C2A-146C891C0924}.Release|x86.Build.0 = Release|x86
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{9CDD03E7-ED65-409F-8C07-BD6F633A0170}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -8,6 +8,7 @@ build_script:
|
||||||
test_script:
|
test_script:
|
||||||
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor SafeExamBrowser.Client.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Client.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -output:"coverage.xml"
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor SafeExamBrowser.Client.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Client.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -output:"coverage.xml"
|
||||||
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Communication.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Communication.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Communication.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Communication.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
||||||
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Configuration.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Configuration.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
||||||
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Core.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Core.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Core.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Core.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
||||||
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.I18n.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.I18n.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.I18n.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.I18n.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
||||||
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Logging.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Logging.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
- .\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/logger:Appveyor .\SafeExamBrowser.Logging.UnitTests\bin\%PLATFORM%\%CONFIGURATION%\SafeExamBrowser.Logging.UnitTests.dll" -filter:"+[*]* -[*.UnitTests]*" -mergebyhash -mergeoutput -output:"coverage.xml"
|
||||||
|
|
Loading…
Reference in a new issue