Restore SEBPatch
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* 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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Service.Operations;
|
||||
|
||||
namespace SafeExamBrowser.Service.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionActivationOperationTests
|
||||
{
|
||||
private Mock<ILogger> logger;
|
||||
private SessionContext sessionContext;
|
||||
private SessionActivationOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
logger = new Mock<ILogger>();
|
||||
sessionContext = new SessionContext();
|
||||
|
||||
sut = new SessionActivationOperation(logger.Object, sessionContext);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Perform_MustSetServiceEvent()
|
||||
{
|
||||
sessionContext.ServiceEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
|
||||
|
||||
var wasSet = false;
|
||||
var task = Task.Run(() => wasSet = sessionContext.ServiceEvent.WaitOne(1000));
|
||||
var result = sut.Perform();
|
||||
|
||||
task.Wait();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.IsTrue(wasSet);
|
||||
Assert.IsTrue(sessionContext.IsRunning);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Revert_MustDoNothing()
|
||||
{
|
||||
sessionContext.IsRunning = true;
|
||||
|
||||
var result = sut.Revert();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.IsTrue(sessionContext.IsRunning);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user