2018-03-14 15:27:11 +01:00
|
|
|
|
/*
|
2021-02-03 00:45:33 +01:00
|
|
|
|
* Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET)
|
2018-03-14 15:27:11 +01:00
|
|
|
|
*
|
|
|
|
|
* 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 Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Core.Operations;
|
2018-03-14 15:27:11 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Core.UnitTests.Operations
|
2018-03-14 15:27:11 +01:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class DelegateOperationTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustExecutePerformAction()
|
|
|
|
|
{
|
|
|
|
|
var performed = false;
|
|
|
|
|
void perform() => performed = true;
|
|
|
|
|
var sut = new DelegateOperation(perform);
|
|
|
|
|
|
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(performed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustExecuteRepeatAction()
|
|
|
|
|
{
|
|
|
|
|
var repeated = false;
|
|
|
|
|
void repeat() => repeated = true;
|
|
|
|
|
var sut = new DelegateOperation(() => { }, repeat);
|
|
|
|
|
|
|
|
|
|
sut.Repeat();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(repeated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustExecuteRevertAction()
|
|
|
|
|
{
|
|
|
|
|
var reverted = false;
|
|
|
|
|
void revert() => reverted = true;
|
|
|
|
|
var sut = new DelegateOperation(() => { }, revert: revert);
|
|
|
|
|
|
|
|
|
|
sut.Revert();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(reverted);
|
|
|
|
|
}
|
2018-03-14 15:39:53 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustNotFailIfActionsAreNull()
|
|
|
|
|
{
|
|
|
|
|
var sut = new DelegateOperation(null, null, null);
|
|
|
|
|
|
|
|
|
|
var perform = sut.Perform();
|
|
|
|
|
var repeat = sut.Repeat();
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var revert = sut.Revert();
|
2018-03-14 15:39:53 +01:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, perform);
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, repeat);
|
2018-10-10 09:19:03 +02:00
|
|
|
|
Assert.AreEqual(OperationResult.Success, revert);
|
2018-03-14 15:39:53 +01:00
|
|
|
|
}
|
2018-03-14 15:27:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|