From 4ca2fac50e55bcbb703bb552926253112b76c027 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 5 Oct 2018 10:22:13 +0200 Subject: [PATCH] SEBWIN-221: Ensured all client operations do not allow repeating. --- .../Operations/BrowserOperationTests.cs | 8 +++ .../ClientHostDisconnectionOperationTests.cs | 10 ++-- .../Operations/ClipboardOperationTests.cs | 8 +++ .../Operations/ConfigurationOperationTests.cs | 50 +++++++++++++++++++ .../DisplayMonitorOperationTests.cs | 8 +++ .../KeyboardInterceptorOperationTests.cs | 8 +++ .../MouseInterceptorOperationTests.cs | 8 +++ .../ProcessMonitorOperationTests.cs | 8 +++ .../RuntimeConnectionOperationTests.cs | 46 +++++++++++++++++ .../Operations/TaskbarOperationTests.cs | 10 +++- .../Operations/WindowMonitorOperationTests.cs | 10 ++++ .../SafeExamBrowser.Client.UnitTests.csproj | 2 + .../Operations/BrowserOperation.cs | 3 +- .../ClientHostDisconnectionOperation.cs | 3 +- .../Operations/ClipboardOperation.cs | 3 +- .../Operations/ConfigurationOperation.cs | 2 +- .../Operations/DisplayMonitorOperation.cs | 3 +- .../KeyboardInterceptorOperation.cs | 3 +- .../Operations/MouseInterceptorOperation.cs | 3 +- .../Operations/ProcessMonitorOperation.cs | 3 +- .../Operations/RuntimeConnectionOperation.cs | 2 +- .../Operations/TaskbarOperation.cs | 3 +- .../Operations/WindowMonitorOperation.cs | 3 +- .../Operations/I18nOperationTests.cs | 14 ++++-- .../Operations/I18nOperation.cs | 3 +- 25 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs create mode 100644 SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs diff --git a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs index dea65dfb..0c3c5477 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -63,5 +64,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations controllerMock.Verify(c => c.Terminate(), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs index 6f26e940..26c838d3 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Diagnostics; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -97,13 +98,10 @@ namespace SafeExamBrowser.Client.UnitTests.Operations } [TestMethod] - public void MustDoNothingOnRepeat() + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() { - var result = sut.Repeat(); - - clientHost.VerifyNoOtherCalls(); - - Assert.AreEqual(OperationResult.Success, result); + sut.Repeat(); } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs index 638eafab..1fd710d2 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -46,5 +47,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations nativeMethodsMock.Verify(n => n.EmptyClipboard(), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs new file mode 100644 index 00000000..8e274b41 --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs @@ -0,0 +1,50 @@ +/* + * 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 Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Client.Operations; +using SafeExamBrowser.Contracts.Communication.Proxies; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Client.UnitTests.Operations +{ + [TestClass] + public class ConfigurationOperationTests + { + private ClientConfiguration configuration; + private Mock logger; + private Mock runtime; + private ConfigurationOperation sut; + + [TestInitialize] + public void Initialize() + { + configuration = new ClientConfiguration(); + logger = new Mock(); + runtime = new Mock(); + + sut = new ConfigurationOperation(configuration, logger.Object, runtime.Object); + } + + [TestMethod] + public void TODO() + { + Assert.Fail(); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } + } +} diff --git a/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs index a35e99bf..ac5d3045 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -63,5 +64,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations displayMonitorMock.Verify(d => d.StopMonitoringDisplayChanges(), Times.Once); displayMonitorMock.Verify(d => d.ResetPrimaryDisplay(), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs index b6f399c7..b5e74ece 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -49,5 +50,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations nativeMethodsMock.Verify(n => n.DeregisterKeyboardHook(It.IsAny()), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs index 1f8815b8..22bdb47b 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -49,5 +50,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations nativeMethodsMock.Verify(n => n.DeregisterMouseHook(It.IsAny()), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ProcessMonitorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ProcessMonitorOperationTests.cs index 8a3c5259..13b3da5a 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ProcessMonitorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ProcessMonitorOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -70,5 +71,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations processMonitor.Verify(p => p.StartMonitoringExplorer(), Times.Never); processMonitor.Verify(p => p.StopMonitoringExplorer(), Times.Never); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs new file mode 100644 index 00000000..0311cff0 --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs @@ -0,0 +1,46 @@ +/* + * 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 Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Client.Operations; +using SafeExamBrowser.Contracts.Communication.Proxies; +using SafeExamBrowser.Contracts.Logging; + +namespace SafeExamBrowser.Client.UnitTests.Operations +{ + [TestClass] + public class RuntimeConnectionOperationTests + { + private Mock logger; + private Mock runtime; + + [TestInitialize] + public void Initialize() + { + logger = new Mock(); + runtime = new Mock(); + } + + [TestMethod] + public void TODO() + { + Assert.Fail(); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + var sut = new RuntimeConnectionOperation(logger.Object, runtime.Object, Guid.Empty); + + sut.Repeat(); + } + } +} diff --git a/SafeExamBrowser.Client.UnitTests/Operations/TaskbarOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/TaskbarOperationTests.cs index d0457e54..97590b21 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/TaskbarOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/TaskbarOperationTests.cs @@ -6,12 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; -using SafeExamBrowser.Contracts.Core; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.Core; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.SystemComponents; @@ -93,5 +94,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations powerSupplyMock.Verify(p => p.Terminate(), Times.Once); wirelessNetworkMock.Verify(w => w.Terminate(), Times.Once); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/WindowMonitorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/WindowMonitorOperationTests.cs index 9b9c59b7..1fac8d16 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/WindowMonitorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/WindowMonitorOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Operations; @@ -105,5 +106,14 @@ namespace SafeExamBrowser.Client.UnitTests.Operations windowMonitorMock.VerifyNoOtherCalls(); } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + var sut = new WindowMonitorOperation(KioskMode.None, loggerMock.Object, windowMonitorMock.Object); + + sut.Repeat(); + } } } diff --git a/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj index 0b593732..08a78944 100644 --- a/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj +++ b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj @@ -80,10 +80,12 @@ + + diff --git a/SafeExamBrowser.Client/Operations/BrowserOperation.cs b/SafeExamBrowser.Client/Operations/BrowserOperation.cs index c78325c7..1c89e6e2 100644 --- a/SafeExamBrowser.Client/Operations/BrowserOperation.cs +++ b/SafeExamBrowser.Client/Operations/BrowserOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Core; using SafeExamBrowser.Contracts.Core.OperationModel; @@ -59,7 +60,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(BrowserOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs b/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs index 3fac12e5..82ff3b42 100644 --- a/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs +++ b/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Threading; using SafeExamBrowser.Contracts.Communication.Events; using SafeExamBrowser.Contracts.Communication.Hosts; @@ -43,7 +44,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(ClientHostDisconnectionOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/ClipboardOperation.cs b/SafeExamBrowser.Client/Operations/ClipboardOperation.cs index 0bf3a20a..15931606 100644 --- a/SafeExamBrowser.Client/Operations/ClipboardOperation.cs +++ b/SafeExamBrowser.Client/Operations/ClipboardOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; using SafeExamBrowser.Contracts.I18n; @@ -37,7 +38,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(ClipboardOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs index 091baeec..48bc5260 100644 --- a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs +++ b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs @@ -63,7 +63,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(ConfigurationOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs b/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs index a2c63c83..4594f351 100644 --- a/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs +++ b/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; using SafeExamBrowser.Contracts.I18n; @@ -45,7 +46,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(DisplayMonitorOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs b/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs index e4f60d36..52eea6ea 100644 --- a/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs +++ b/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; using SafeExamBrowser.Contracts.I18n; @@ -46,7 +47,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(KeyboardInterceptorOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs b/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs index bfd9e4df..67ac3df7 100644 --- a/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs +++ b/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; using SafeExamBrowser.Contracts.I18n; @@ -46,7 +47,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(MouseInterceptorOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/ProcessMonitorOperation.cs b/SafeExamBrowser.Client/Operations/ProcessMonitorOperation.cs index f6210971..b98bb42c 100644 --- a/SafeExamBrowser.Client/Operations/ProcessMonitorOperation.cs +++ b/SafeExamBrowser.Client/Operations/ProcessMonitorOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; @@ -46,7 +47,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(ProcessMonitorOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs b/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs index 9c8f95c8..799bf05b 100644 --- a/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs +++ b/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs @@ -53,7 +53,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(RuntimeConnectionOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/TaskbarOperation.cs b/SafeExamBrowser.Client/Operations/TaskbarOperation.cs index 4d964eed..d0af78bb 100644 --- a/SafeExamBrowser.Client/Operations/TaskbarOperation.cs +++ b/SafeExamBrowser.Client/Operations/TaskbarOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Core; @@ -92,7 +93,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(TaskbarOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Client/Operations/WindowMonitorOperation.cs b/SafeExamBrowser.Client/Operations/WindowMonitorOperation.cs index 5b7e4e5d..8e1baf34 100644 --- a/SafeExamBrowser.Client/Operations/WindowMonitorOperation.cs +++ b/SafeExamBrowser.Client/Operations/WindowMonitorOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; @@ -51,7 +52,7 @@ namespace SafeExamBrowser.Client.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(WindowMonitorOperation)}' is not meant to be repeated!"); } public void Revert() diff --git a/SafeExamBrowser.Core.UnitTests/Operations/I18nOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Operations/I18nOperationTests.cs index afcad325..fccadad1 100644 --- a/SafeExamBrowser.Core.UnitTests/Operations/I18nOperationTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Operations/I18nOperationTests.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Contracts.Core.OperationModel; @@ -45,11 +46,18 @@ namespace SafeExamBrowser.Core.UnitTests.Operations } [TestMethod] - public void MustRepeatCorrectly() + public void MustDoNothingOnRevert() { - var result = sut.Repeat(); + sut.Revert(); - Assert.AreEqual(OperationResult.Success, result); + text.VerifyNoOtherCalls(); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void MustNotAllowRepeating() + { + sut.Repeat(); } } } diff --git a/SafeExamBrowser.Core/Operations/I18nOperation.cs b/SafeExamBrowser.Core/Operations/I18nOperation.cs index 544f3d1a..e434edc9 100644 --- a/SafeExamBrowser.Core/Operations/I18nOperation.cs +++ b/SafeExamBrowser.Core/Operations/I18nOperation.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Globalization; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; @@ -44,7 +45,7 @@ namespace SafeExamBrowser.Core.Operations public OperationResult Repeat() { - return OperationResult.Success; + throw new InvalidOperationException($"The '{nameof(I18nOperation)}' is not meant to be repeated!"); } public void Revert()