SEBWIN-220: Added missing unit test for OperationSequence.
This commit is contained in:
parent
6acd40eb74
commit
3cea7ee7c9
3 changed files with 47 additions and 4 deletions
|
@ -11,7 +11,7 @@ namespace SafeExamBrowser.Contracts.Core.OperationModel.Events
|
|||
/// <summary>
|
||||
/// Base class for all event arguments used for <see cref="IOperationSequence.ProgressChanged"/>.
|
||||
/// </summary>
|
||||
public class ActionRequiredEventArgs
|
||||
public abstract class ActionRequiredEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ using System.Collections.Generic;
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Contracts.Core.OperationModel;
|
||||
using SafeExamBrowser.Contracts.Core.OperationModel.Events;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Core.OperationModel;
|
||||
|
||||
|
@ -54,6 +56,47 @@ namespace SafeExamBrowser.Core.UnitTests.OperationModel
|
|||
operationC.Verify(o => o.Perform(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyPropagateEventSubscription()
|
||||
{
|
||||
var actionRequiredCalled = false;
|
||||
var actionRequiredHandler = new ActionRequiredEventHandler(args => actionRequiredCalled = true);
|
||||
var statusChangedCalled = false;
|
||||
var statusChangedHandler = new StatusChangedEventHandler(t => statusChangedCalled = true);
|
||||
var operationA = new Mock<IOperation>();
|
||||
var operationB = new Mock<IOperation>();
|
||||
var operationC = new Mock<IOperation>();
|
||||
var operations = new Queue<IOperation>();
|
||||
|
||||
operationA.Setup(o => o.Perform()).Returns(OperationResult.Success);
|
||||
operationB.Setup(o => o.Perform()).Returns(OperationResult.Success).Raises(o => o.ActionRequired += null, new Mock<ActionRequiredEventArgs>().Object);
|
||||
operationC.Setup(o => o.Perform()).Returns(OperationResult.Success).Raises(o => o.StatusChanged += null, default(TextKey));
|
||||
|
||||
operations.Enqueue(operationA.Object);
|
||||
operations.Enqueue(operationB.Object);
|
||||
operations.Enqueue(operationC.Object);
|
||||
|
||||
var sut = new OperationSequence(loggerMock.Object, operations);
|
||||
|
||||
sut.ActionRequired += actionRequiredHandler;
|
||||
sut.StatusChanged += statusChangedHandler;
|
||||
|
||||
sut.TryPerform();
|
||||
|
||||
Assert.IsTrue(actionRequiredCalled);
|
||||
Assert.IsTrue(statusChangedCalled);
|
||||
|
||||
actionRequiredCalled = false;
|
||||
statusChangedCalled = false;
|
||||
sut.ActionRequired -= actionRequiredHandler;
|
||||
sut.StatusChanged -= statusChangedHandler;
|
||||
|
||||
sut.TryPerform();
|
||||
|
||||
Assert.IsFalse(actionRequiredCalled);
|
||||
Assert.IsFalse(statusChangedCalled);
|
||||
}
|
||||
|
||||
#region Perform Tests
|
||||
|
||||
[TestMethod]
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
|
|||
|
||||
sut.Perform();
|
||||
|
||||
operationMock.Raise(o => o.ActionRequired += null, new ActionRequiredEventArgs());
|
||||
operationMock.Raise(o => o.ActionRequired += null, new Mock<ActionRequiredEventArgs>().Object);
|
||||
operationMock.Raise(o => o.StatusChanged += null, default(TextKey));
|
||||
|
||||
Assert.AreEqual(1, actionRequired);
|
||||
|
@ -122,7 +122,7 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
|
|||
sut.ActionRequired -= actionRequiredHandler;
|
||||
sut.StatusChanged -= statusChangedHandler;
|
||||
|
||||
operationMock.Raise(o => o.ActionRequired += null, new ActionRequiredEventArgs());
|
||||
operationMock.Raise(o => o.ActionRequired += null, new Mock<ActionRequiredEventArgs>().Object);
|
||||
operationMock.Raise(o => o.StatusChanged += null, default(TextKey));
|
||||
|
||||
Assert.AreEqual(1, actionRequired);
|
||||
|
@ -131,7 +131,7 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
|
|||
sut.ActionRequired += actionRequiredHandler;
|
||||
sut.StatusChanged += statusChangedHandler;
|
||||
|
||||
operationMock.Raise(o => o.ActionRequired += null, new ActionRequiredEventArgs());
|
||||
operationMock.Raise(o => o.ActionRequired += null, new Mock<ActionRequiredEventArgs>().Object);
|
||||
operationMock.Raise(o => o.StatusChanged += null, default(TextKey));
|
||||
|
||||
Assert.AreEqual(2, actionRequired);
|
||||
|
|
Loading…
Reference in a new issue