SEBWIN-320: Made mutex names application-wide constants and fixed unit test for lockdown operation.

This commit is contained in:
dbuechel 2019-07-19 10:56:32 +02:00
parent 8d0c83998c
commit d9f546aa74
6 changed files with 24 additions and 7 deletions
SafeExamBrowser.Client
SafeExamBrowser.Configuration
SafeExamBrowser.Contracts/Configuration
SafeExamBrowser.ResetUtility/Procedure
SafeExamBrowser.Runtime
SafeExamBrowser.Service.UnitTests/Operations

View file

@ -9,12 +9,13 @@
using System;
using System.Threading;
using System.Windows;
using SafeExamBrowser.Contracts.Configuration;
namespace SafeExamBrowser.Client
{
public class App : Application
{
private static readonly Mutex Mutex = new Mutex(true, "safe_exam_browser_client_mutex");
private static readonly Mutex Mutex = new Mutex(true, AppConfig.CLIENT_MUTEX_NAME);
private CompositionRoot instances = new CompositionRoot();
[STAThread]

View file

@ -50,7 +50,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" />

View file

@ -26,11 +26,26 @@ namespace SafeExamBrowser.Contracts.Configuration
/// </summary>
public const string BASE_ADDRESS = "net.pipe://localhost/safeexambrowser";
/// <summary>
/// The name of the synchronization primitive for the client component.
/// </summary>
public const string CLIENT_MUTEX_NAME = "safe_exam_browser_client_mutex";
/// <summary>
/// The name of the synchronization primitive for the runtime component.
/// </summary>
public const string RUNTIME_MUTEX_NAME = "safe_exam_browser_runtime_mutex";
/// <summary>
/// The communication address of the service component.
/// </summary>
public const string SERVICE_ADDRESS = BASE_ADDRESS + "/service";
/// <summary>
/// The name of the synchronization primitive for the service component.
/// </summary>
public const string SERVICE_MUTEX_NAME = "safe_exam_browser_reset_mutex";
/// <summary>
/// The file path of the local client configuration for the active user.
/// </summary>

View file

@ -9,12 +9,13 @@
using System;
using System.Security.Principal;
using System.Threading;
using SafeExamBrowser.Contracts.Configuration;
namespace SafeExamBrowser.ResetUtility.Procedure
{
internal class Initialization : ProcedureStep
{
private static readonly Mutex mutex = new Mutex(true, "safe_exam_browser_reset_mutex");
private static readonly Mutex mutex = new Mutex(true, AppConfig.SERVICE_MUTEX_NAME);
public Initialization(ProcedureContext context) : base(context)
{
@ -77,7 +78,7 @@ namespace SafeExamBrowser.ResetUtility.Procedure
private bool SebNotRunning()
{
var isRunning = Mutex.TryOpenExisting("safe_exam_browser_runtime_mutex", out _);
var isRunning = Mutex.TryOpenExisting(AppConfig.RUNTIME_MUTEX_NAME, out _);
if (isRunning)
{

View file

@ -10,12 +10,13 @@ using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using SafeExamBrowser.Contracts.Configuration;
namespace SafeExamBrowser.Runtime
{
public class App : Application
{
private static readonly Mutex Mutex = new Mutex(true, "safe_exam_browser_runtime_mutex");
private static readonly Mutex Mutex = new Mutex(true, AppConfig.RUNTIME_MUTEX_NAME);
private CompositionRoot instances = new CompositionRoot();
[STAThread]

View file

@ -51,7 +51,7 @@ namespace SafeExamBrowser.Service.UnitTests.Operations
public void Perform_MustSetConfigurationsCorrectly()
{
var configuration = new Mock<IFeatureConfiguration>();
var count = typeof(IFeatureConfigurationFactory).GetMethods().Where(m => m.Name.StartsWith("Create")).Count();
var count = typeof(IFeatureConfigurationFactory).GetMethods().Where(m => m.Name.StartsWith("Create") && m.Name != nameof(IFeatureConfigurationFactory.CreateAll)).Count();
configuration.SetReturnsDefault(true);
factory.SetReturnsDefault(configuration.Object);
@ -105,7 +105,7 @@ namespace SafeExamBrowser.Service.UnitTests.Operations
public void Perform_MustImmediatelyAbortOnFailure()
{
var configuration = new Mock<IFeatureConfiguration>();
var count = typeof(IFeatureConfigurationFactory).GetMethods().Where(m => m.Name.StartsWith("Create")).Count();
var count = typeof(IFeatureConfigurationFactory).GetMethods().Where(m => m.Name.StartsWith("Create") && m.Name != nameof(IFeatureConfigurationFactory.CreateAll)).Count();
var counter = 0;
var offset = 3;