/* * 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.Configuration; using SafeExamBrowser.Contracts.Core; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Contracts.UserInterface.Taskbar; namespace SafeExamBrowser.Client.UnitTests.Operations { [TestClass] public class BrowserOperationTests { private Mock controllerMock; private Mock appInfoMock; private Mock loggerMock; private Mock taskbarMock; private Mock uiFactoryMock; private BrowserOperation sut; [TestInitialize] public void Initialize() { controllerMock = new Mock(); appInfoMock = new Mock(); loggerMock = new Mock(); taskbarMock = new Mock(); uiFactoryMock = new Mock(); sut = new BrowserOperation(controllerMock.Object, appInfoMock.Object, loggerMock.Object, taskbarMock.Object, uiFactoryMock.Object); } [TestMethod] public void MustPeformCorrectly() { var order = 0; controllerMock.Setup(c => c.Initialize()).Callback(() => Assert.AreEqual(++order, 1)); controllerMock.Setup(c => c.RegisterApplicationButton(It.IsAny())).Callback(() => Assert.AreEqual(++order, 2)); taskbarMock.Setup(t => t.AddApplication(It.IsAny())).Callback(() => Assert.AreEqual(++order, 3)); sut.Perform(); controllerMock.Verify(c => c.Initialize(), Times.Once); controllerMock.Verify(c => c.RegisterApplicationButton(It.IsAny()), Times.Once); taskbarMock.Verify(t => t.AddApplication(It.IsAny()), Times.Once); } [TestMethod] public void MustRevertCorrectly() { sut.Revert(); controllerMock.Verify(c => c.Terminate(), Times.Once); } [TestMethod] [ExpectedException(typeof(InvalidOperationException))] public void MustNotAllowRepeating() { sut.Repeat(); } } }