SEBWIN-219: Extracted text dependency from user interface factory methods.

This commit is contained in:
dbuechel 2018-02-07 13:25:49 +01:00
parent 8cd0659a22
commit 001c262158
16 changed files with 110 additions and 85 deletions

View file

@ -19,14 +19,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
public class AboutNotificationControllerTests
{
private Mock<IRuntimeInfo> runtimeInfoMock;
private Mock<IText> textMock;
private Mock<IUserInterfaceFactory> uiFactoryMock;
[TestInitialize]
public void Initialize()
{
runtimeInfoMock = new Mock<IRuntimeInfo>();
textMock = new Mock<IText>();
uiFactoryMock = new Mock<IUserInterfaceFactory>();
}
@ -35,9 +33,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
{
var button = new NotificationButtonMock();
var window = new Mock<IWindow>();
var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object);
uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>(), It.IsAny<IText>())).Returns(window.Object);
uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click();
sut.Terminate();
@ -50,9 +48,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
{
var button = new NotificationButtonMock();
var window = new Mock<IWindow>();
var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object);
uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>(), It.IsAny<IText>())).Returns(window.Object);
uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click();
button.Click();
@ -60,7 +58,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
button.Click();
button.Click();
uiFactoryMock.Verify(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>(), It.IsAny<IText>()), Times.Once);
uiFactoryMock.Verify(u => u.CreateAboutWindow(It.IsAny<IRuntimeInfo>()), Times.Once);
window.Verify(u => u.Show(), Times.Once);
window.Verify(u => u.BringToForeground(), Times.Exactly(4));
}
@ -69,7 +67,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
public void MustSubscribeToClickEvent()
{
var button = new NotificationButtonMock();
var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object);
sut.RegisterNotification(button);

View file

@ -9,7 +9,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SafeExamBrowser.Client.Notifications;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
@ -19,14 +18,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
public class LogNotificationControllerTests
{
private Mock<ILogger> loggerMock;
private Mock<IText> textMock;
private Mock<IUserInterfaceFactory> uiFactoryMock;
[TestInitialize]
public void Initialize()
{
loggerMock = new Mock<ILogger>();
textMock = new Mock<IText>();
uiFactoryMock = new Mock<IUserInterfaceFactory>();
}
@ -35,9 +32,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
{
var button = new NotificationButtonMock();
var window = new Mock<IWindow>();
var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object);
uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>(), It.IsAny<IText>())).Returns(window.Object);
uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click();
sut.Terminate();
@ -50,9 +47,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
{
var button = new NotificationButtonMock();
var window = new Mock<IWindow>();
var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object);
uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>(), It.IsAny<IText>())).Returns(window.Object);
uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny<ILogger>())).Returns(window.Object);
sut.RegisterNotification(button);
button.Click();
button.Click();
@ -60,7 +57,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
button.Click();
button.Click();
uiFactoryMock.Verify(u => u.CreateLogWindow(It.IsAny<ILogger>(), It.IsAny<IText>()), Times.Once);
uiFactoryMock.Verify(u => u.CreateLogWindow(It.IsAny<ILogger>()), Times.Once);
window.Verify(u => u.Show(), Times.Once);
window.Verify(u => u.BringToForeground(), Times.Exactly(4));
}
@ -69,7 +66,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications
public void MustSubscribeToClickEvent()
{
var button = new NotificationButtonMock();
var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object);
var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object);
sut.RegisterNotification(button);

View file

@ -140,10 +140,11 @@ namespace SafeExamBrowser.Client.Behaviour.Operations
private void CreateLogNotification()
{
// TODO: Resolve dependencies -> CompositionRoot!
var logInfo = new LogNotificationInfo(text);
var logNotification = uiFactory.CreateNotification(logInfo);
logController = new LogNotificationController(logger, text, uiFactory);
logController = new LogNotificationController(logger, uiFactory);
logController.RegisterNotification(logNotification);
taskbar.AddNotification(logNotification);

View file

@ -9,7 +9,6 @@
using System.Collections.Generic;
using SafeExamBrowser.Browser;
using SafeExamBrowser.Configuration;
using SafeExamBrowser.Configuration.Settings;
using SafeExamBrowser.Contracts.Behaviour;
using SafeExamBrowser.Contracts.Behaviour.Operations;
using SafeExamBrowser.Contracts.Configuration;
@ -60,11 +59,11 @@ namespace SafeExamBrowser.Client
nativeMethods = new NativeMethods();
settings = new ConfigurationRepository().LoadDefaultSettings();
systemInfo = new SystemInfo();
uiFactory = new UserInterfaceFactory();
InitializeLogging();
text = new Text(logger);
uiFactory = new UserInterfaceFactory(text);
// TODO
//Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar)));
//browserController = new BrowserApplicationController(settings.Browser, text, uiFactory);

View file

@ -18,14 +18,12 @@ namespace SafeExamBrowser.Client.Notifications
{
private INotificationButton notification;
private IRuntimeInfo runtimeInfo;
private IText text;
private IUserInterfaceFactory uiFactory;
private IWindow window;
public AboutNotificationController(IRuntimeInfo runtimeInfo, IText text, IUserInterfaceFactory uiFactory)
public AboutNotificationController(IRuntimeInfo runtimeInfo, IUserInterfaceFactory uiFactory)
{
this.runtimeInfo = runtimeInfo;
this.text = text;
this.uiFactory = uiFactory;
}
@ -45,7 +43,7 @@ namespace SafeExamBrowser.Client.Notifications
{
if (window == null)
{
window = uiFactory.CreateAboutWindow(runtimeInfo, text);
window = uiFactory.CreateAboutWindow(runtimeInfo);
window.Closing += () => window = null;
window.Show();

View file

@ -18,14 +18,12 @@ namespace SafeExamBrowser.Client.Notifications
{
private INotificationButton notification;
private ILogger logger;
private IText text;
private IUserInterfaceFactory uiFactory;
private IWindow window;
public LogNotificationController(ILogger logger, IText text, IUserInterfaceFactory uiFactory)
public LogNotificationController(ILogger logger, IUserInterfaceFactory uiFactory)
{
this.logger = logger;
this.text = text;
this.uiFactory = uiFactory;
}
@ -45,7 +43,7 @@ namespace SafeExamBrowser.Client.Notifications
{
if (window == null)
{
window = uiFactory.CreateLogWindow(logger, text);
window = uiFactory.CreateLogWindow(logger);
window.Closing += () => window = null;
window.Show();

View file

@ -13,14 +13,13 @@ namespace SafeExamBrowser.Client.Notifications
{
internal class LogNotificationInfo : INotificationInfo
{
private IText text;
public string Tooltip => text.Get(TextKey.Notification_LogTooltip);
public IIconResource IconResource { get; } = new LogNotificationIconResource();
public string Tooltip { get; private set; }
public IIconResource IconResource { get; private set; }
public LogNotificationInfo(IText text)
{
this.text = text;
Tooltip = text.Get(TextKey.Notification_LogTooltip);
IconResource = new LogNotificationIconResource();
}
}
}

View file

@ -17,6 +17,8 @@ namespace SafeExamBrowser.Contracts.I18n
LogWindow_Title,
MessageBox_ConfigureClientSuccess,
MessageBox_ConfigureClientSuccessTitle,
MessageBox_SessionStartError,
MessageBox_SessionStartErrorTitle,
MessageBox_ShutdownError,
MessageBox_ShutdownErrorTitle,
MessageBox_SingleInstance,

View file

@ -6,6 +6,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.Contracts.I18n;
namespace SafeExamBrowser.Contracts.UserInterface
{
public interface IMessageBox
@ -14,5 +16,10 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// Shows a message box according to the specified parameters and returns the result chosen by the user.
/// </summary>
MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information);
/// <summary>
/// Shows a message box according to the specified parameters and returns the result chosen by the user.
/// </summary>
MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information);
}
}

View file

@ -8,7 +8,6 @@
using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
@ -19,7 +18,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// <summary>
/// Creates a new about window displaying information about the currently running application version.
/// </summary>
IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text);
IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo);
/// <summary>
/// Creates a taskbar button, initialized with the given application information.
@ -34,7 +33,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// <summary>
/// Creates a new log window which runs on its own thread.
/// </summary>
IWindow CreateLogWindow(ILogger logger, IText text);
IWindow CreateLogWindow(ILogger logger);
/// <summary>
/// Creates a taskbar notification, initialized with the given notification information.
@ -55,12 +54,12 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// Creates a new runtime window which runs on its own thread.
/// </summary>
/// <returns></returns>
IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text);
IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo);
/// <summary>
/// Creates a new splash screen which runs on its own thread.
/// </summary>
ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text);
ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo);
/// <summary>
/// Creates a system control which allows to change the wireless network connection of the computer.

View file

@ -531,7 +531,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations
var sut = new OperationSequence(loggerMock.Object, new Queue<IOperation>());
var indicatorMock = new Mock<IProgressIndicator>();
indicatorMock.Setup(i => i.SetMaxValue(It.IsAny<int>())).Throws<Exception>();
indicatorMock.Setup(i => i.SetIndeterminate()).Throws<Exception>();
sut.ProgressIndicator = indicatorMock.Object;
var success = sut.TryRevert();

View file

@ -12,6 +12,12 @@
<Entry key="MessageBox_ConfigureClientSuccessTitle">
Configuration Successful
</Entry>
<Entry key="MessageBox_SessionStartError">
The application failed to start a new session. Please consult the application log for more information...
</Entry>
<Entry key="MessageBox_SessionStartErrorTitle">
Session Start Error
</Entry>
<Entry key="MessageBox_ShutdownError">
An unexpected error occurred during the shutdown procedure! Please consult the application log for more information...
</Entry>

View file

@ -32,7 +32,6 @@ namespace SafeExamBrowser.Runtime.Behaviour
private IServiceProxy serviceProxy;
private ISplashScreen splashScreen;
private Action shutdown;
private IText text;
private IUserInterfaceFactory uiFactory;
public RuntimeController(
@ -44,7 +43,6 @@ namespace SafeExamBrowser.Runtime.Behaviour
IRuntimeInfo runtimeInfo,
IServiceProxy serviceProxy,
Action shutdown,
IText text,
IUserInterfaceFactory uiFactory)
{
this.configuration = configuration;
@ -55,7 +53,6 @@ namespace SafeExamBrowser.Runtime.Behaviour
this.runtimeInfo = runtimeInfo;
this.serviceProxy = serviceProxy;
this.shutdown = shutdown;
this.text = text;
this.uiFactory = uiFactory;
}
@ -63,11 +60,13 @@ namespace SafeExamBrowser.Runtime.Behaviour
{
logger.Info("--- Initiating startup procedure ---");
runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo, text);
splashScreen = uiFactory.CreateSplashScreen(runtimeInfo, text);
splashScreen.Show();
runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo);
splashScreen = uiFactory.CreateSplashScreen(runtimeInfo);
bootstrapSequence.ProgressIndicator = splashScreen;
sessionSequence.ProgressIndicator = runtimeWindow;
splashScreen.Show();
initialized = bootstrapSequence.TryPerform();
@ -117,10 +116,12 @@ namespace SafeExamBrowser.Runtime.Behaviour
if (success)
{
logger.Info("--- Application successfully finalized! ---");
logger.Log(string.Empty);
}
else
{
logger.Info("--- Shutdown procedure failed! ---");
logger.Log(string.Empty);
}
splashScreen?.Close();
@ -129,44 +130,43 @@ namespace SafeExamBrowser.Runtime.Behaviour
private void StartSession(bool initial = false)
{
logger.Info("Starting new session...");
runtimeWindow.UpdateText(TextKey.RuntimeWindow_StartSession, true);
runtimeWindow.Show();
sessionSequence.ProgressIndicator = runtimeWindow;
// TODO:
// - Initialize configuration
// - Initialize kiosk mode
// - Initialize session data
// - Create and connect to client
// - Initialize session with service
// - Verify session integrity and start event handling
var success = initial ? sessionSequence.TryPerform() : sessionSequence.TryRepeat();
if (success)
{
// TODO
// TODO:
// - Initialize session data
// - Create and connect to client
// - Initialize session with service
// - Verify session integrity and start event handling
runtimeWindow.HideProgressBar();
runtimeWindow.UpdateText(TextKey.RuntimeWindow_ApplicationRunning);
if (configuration.CurrentSettings.KioskMode == KioskMode.DisableExplorerShell)
{
runtimeWindow.Hide();
}
}
else
{
// TODO
uiFactory.Show(TextKey.MessageBox_SessionStartError, TextKey.MessageBox_SessionStartErrorTitle, icon: MessageBoxIcon.Error);
if (initial)
{
initialized = false;
}
else
{
shutdown();
}
}
// TODO: Remove!
System.Threading.Thread.Sleep(5000);
runtimeWindow.HideProgressBar();
runtimeWindow.UpdateText(TextKey.RuntimeWindow_ApplicationRunning);
if (configuration.CurrentSettings.KioskMode == KioskMode.DisableExplorerShell)
{
runtimeWindow.Hide();
}
// TODO: Remove!
System.Threading.Thread.Sleep(5000);
shutdown.Invoke();
}
private void StopSession()
@ -183,9 +183,6 @@ namespace SafeExamBrowser.Runtime.Behaviour
// - Stop event handling and close session
var success = sessionSequence.TryRevert();
// TODO: Remove!
System.Threading.Thread.Sleep(5000);
if (success)
{
// TODO

View file

@ -41,7 +41,6 @@ namespace SafeExamBrowser.Runtime
var sessionOperations = new Queue<IOperation>();
var nativeMethods = new NativeMethods();
var configuration = new ConfigurationRepository();
var uiFactory = new UserInterfaceFactory();
logger = new Logger();
runtimeInfo = configuration.RuntimeInfo;
@ -50,6 +49,7 @@ namespace SafeExamBrowser.Runtime
InitializeLogging();
var text = new Text(logger);
var uiFactory = new UserInterfaceFactory(text);
var runtimeHost = new RuntimeHost(runtimeInfo.RuntimeAddress, new ModuleLogger(logger, typeof(RuntimeHost)));
var serviceProxy = new ServiceProxy(runtimeInfo.ServiceAddress, new ModuleLogger(logger, typeof(ServiceProxy)));
@ -63,7 +63,7 @@ namespace SafeExamBrowser.Runtime
var boostrapSequence = new OperationSequence(logger, bootstrapOperations);
var sessionSequence = new OperationSequence(logger, sessionOperations);
RuntimeController = new RuntimeController(configuration, logger, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, Application.Current.Shutdown, text, uiFactory);
RuntimeController = new RuntimeController(configuration, logger, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, Application.Current.Shutdown, uiFactory);
}
internal void LogStartupInformation()

View file

@ -22,7 +22,14 @@ namespace SafeExamBrowser.UserInterface.Classic
{
public class UserInterfaceFactory : IUserInterfaceFactory
{
public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text)
private IText text;
public UserInterfaceFactory(IText text)
{
this.text = text;
}
public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo)
{
return new AboutWindow(runtimeInfo, text);
}
@ -37,7 +44,7 @@ namespace SafeExamBrowser.UserInterface.Classic
return new BrowserWindow(control, settings);
}
public IWindow CreateLogWindow(ILogger logger, IText text)
public IWindow CreateLogWindow(ILogger logger)
{
LogWindow logWindow = null;
var logWindowReadyEvent = new AutoResetEvent(false);
@ -77,7 +84,7 @@ namespace SafeExamBrowser.UserInterface.Classic
return new PowerSupplyControl();
}
public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text)
public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo)
{
RuntimeWindow runtimeWindow = null;
var windowReadyEvent = new AutoResetEvent(false);
@ -101,7 +108,7 @@ namespace SafeExamBrowser.UserInterface.Classic
return runtimeWindow;
}
public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text)
public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo)
{
SplashScreen splashScreen = null;
var splashReadyEvent = new AutoResetEvent(false);
@ -140,6 +147,11 @@ namespace SafeExamBrowser.UserInterface.Classic
return ToResult(result);
}
public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information)
{
return Show(text.Get(message), text.Get(title), action, icon);
}
private MessageBoxButton ToButton(MessageBoxAction action)
{
switch (action)

View file

@ -21,7 +21,14 @@ namespace SafeExamBrowser.UserInterface.Windows10
{
public class UserInterfaceFactory : IUserInterfaceFactory
{
public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text)
private IText text;
public UserInterfaceFactory(IText text)
{
this.text = text;
}
public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo)
{
return new AboutWindow(runtimeInfo, text);
}
@ -36,7 +43,7 @@ namespace SafeExamBrowser.UserInterface.Windows10
return new BrowserWindow(control, settings);
}
public IWindow CreateLogWindow(ILogger logger, IText text)
public IWindow CreateLogWindow(ILogger logger)
{
LogWindow logWindow = null;
var logWindowReadyEvent = new AutoResetEvent(false);
@ -77,13 +84,13 @@ namespace SafeExamBrowser.UserInterface.Windows10
return new PowerSupplyControl();
}
public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text)
public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo)
{
// TODO
throw new System.NotImplementedException();
}
public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text)
public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo)
{
SplashScreen splashScreen = null;
var splashReadyEvent = new AutoResetEvent(false);
@ -123,6 +130,11 @@ namespace SafeExamBrowser.UserInterface.Windows10
return ToResult(result);
}
public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information)
{
return Show(text.Get(message), text.Get(title), action, icon);
}
private MessageBoxButton ToButton(MessageBoxAction action)
{
switch (action)