SEBWIN-183: Changed startup- and shutdown-controller to continue reverting operations, even if one or more of them fail.
This commit is contained in:
parent
451aef8cae
commit
93e84b1120
6 changed files with 73 additions and 6 deletions
|
@ -6,6 +6,7 @@
|
||||||
* 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 System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
@ -84,6 +85,29 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour
|
||||||
Assert.IsTrue(c == 3);
|
Assert.IsTrue(c == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustContinueToRevertOperationsInCaseOfError()
|
||||||
|
{
|
||||||
|
var operationA = new Mock<IOperation>();
|
||||||
|
var operationB = new Mock<IOperation>();
|
||||||
|
var operationC = new Mock<IOperation>();
|
||||||
|
var operations = new Queue<IOperation>();
|
||||||
|
|
||||||
|
operationA.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
operationB.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
operationC.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
|
||||||
|
operations.Enqueue(operationA.Object);
|
||||||
|
operations.Enqueue(operationB.Object);
|
||||||
|
operations.Enqueue(operationC.Object);
|
||||||
|
|
||||||
|
sut.FinalizeApplication(operations);
|
||||||
|
|
||||||
|
operationA.Verify(o => o.Revert(), Times.Once);
|
||||||
|
operationB.Verify(o => o.Revert(), Times.Once);
|
||||||
|
operationC.Verify(o => o.Revert(), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustNotFailWithEmptyQueue()
|
public void MustNotFailWithEmptyQueue()
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,6 +149,33 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour
|
||||||
Assert.IsTrue(a == 3);
|
Assert.IsTrue(a == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MustContinueToRevertOperationsInCaseOfError()
|
||||||
|
{
|
||||||
|
var operationA = new Mock<IOperation>();
|
||||||
|
var operationB = new Mock<IOperation>();
|
||||||
|
var operationC = new Mock<IOperation>();
|
||||||
|
var operations = new Queue<IOperation>();
|
||||||
|
|
||||||
|
operationC.Setup(o => o.Perform()).Throws<Exception>();
|
||||||
|
operationC.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
operationB.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
operationA.Setup(o => o.Revert()).Throws<Exception>();
|
||||||
|
|
||||||
|
operations.Enqueue(operationA.Object);
|
||||||
|
operations.Enqueue(operationB.Object);
|
||||||
|
operations.Enqueue(operationC.Object);
|
||||||
|
|
||||||
|
var result = sut.TryInitializeApplication(operations);
|
||||||
|
|
||||||
|
operationA.Verify(o => o.Perform(), Times.Once);
|
||||||
|
operationA.Verify(o => o.Revert(), Times.Once);
|
||||||
|
operationB.Verify(o => o.Perform(), Times.Once);
|
||||||
|
operationB.Verify(o => o.Revert(), Times.Once);
|
||||||
|
operationC.Verify(o => o.Perform(), Times.Once);
|
||||||
|
operationC.Verify(o => o.Revert(), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MustSucceedWithEmptyQueue()
|
public void MustSucceedWithEmptyQueue()
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,8 +52,16 @@ namespace SafeExamBrowser.Core.Behaviour
|
||||||
foreach (var operation in operations)
|
foreach (var operation in operations)
|
||||||
{
|
{
|
||||||
operation.SplashScreen = splashScreen;
|
operation.SplashScreen = splashScreen;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
operation.Revert();
|
operation.Revert();
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Error($"Failed to revert operation '{operation.GetType().Name}'!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
|
|
|
@ -77,7 +77,15 @@ namespace SafeExamBrowser.Core.Behaviour
|
||||||
{
|
{
|
||||||
var operation = stack.Pop();
|
var operation = stack.Pop();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
operation.Revert();
|
operation.Revert();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Error($"Failed to revert operation '{operation.GetType().Name}'!", e);
|
||||||
|
}
|
||||||
|
|
||||||
splashScreen.Regress();
|
splashScreen.Regress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26730.8
|
VisualStudioVersion = 15.0.26730.16
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser", "SafeExamBrowser\SafeExamBrowser.csproj", "{E3AED2F8-B5DF-45D1-AC19-48066923D6D8}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser", "SafeExamBrowser\SafeExamBrowser.csproj", "{E3AED2F8-B5DF-45D1-AC19-48066923D6D8}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -10,7 +10,6 @@ EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0A9E6674-2FB4-42EA-85DE-B2445B9AE2D9}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0A9E6674-2FB4-42EA-85DE-B2445B9AE2D9}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
LICENSE.txt = LICENSE.txt
|
LICENSE.txt = LICENSE.txt
|
||||||
README.md = README.md
|
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.UserInterface.Windows10", "SafeExamBrowser.UserInterface.Windows10\SafeExamBrowser.UserInterface.Windows10.csproj", "{E1BE031A-4354-41E7-83E8-843DED4489FF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.UserInterface.Windows10", "SafeExamBrowser.UserInterface.Windows10\SafeExamBrowser.UserInterface.Windows10.csproj", "{E1BE031A-4354-41E7-83E8-843DED4489FF}"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
@ -65,7 +66,7 @@ namespace SafeExamBrowser
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
MainWindow = instances.Taskbar;
|
MainWindow = instances.Taskbar;
|
||||||
MainWindow.Closing += (o, args) => ShutdownApplication();
|
MainWindow.Closing += MainWindow_Closing;
|
||||||
MainWindow.Show();
|
MainWindow.Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -74,7 +75,7 @@ namespace SafeExamBrowser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShutdownApplication()
|
private void MainWindow_Closing(object sender, CancelEventArgs e)
|
||||||
{
|
{
|
||||||
var operations = new Queue<IOperation>(instances.StartupOperations.Reverse());
|
var operations = new Queue<IOperation>(instances.StartupOperations.Reverse());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue