Add default FlowDirection and TextAlignment to MessageBoxViweModel

This removes the MessageBoxOptions input to MessageBoxViewModel, and
replaces it with explicit FlowDirection and TextAlignment inputs.
I think this is fair enough - we weren't using most of the members
of MessageBoxOptions, so allowing them to be provided was misleading.

Fixes #12
This commit is contained in:
Antony Male 2016-11-12 11:35:58 +00:00
parent 6dd8c072c1
commit ffb218d666
4 changed files with 85 additions and 78 deletions

View File

@ -15,14 +15,15 @@ namespace Stylet
/// <summary> /// <summary>
/// Setup the MessageBoxViewModel with the information it needs /// Setup the MessageBoxViewModel with the information it needs
/// </summary> /// </summary>
/// <param name="messageBoxText">A System.String that specifies the text to display.</param> /// <param name="messageBoxText">A <see cref="System.String"/> that specifies the text to display.</param>
/// <param name="caption">A System.String that specifies the title bar caption to display.</param> /// <param name="caption">A <see cref="System.String"/> that specifies the title bar caption to display.</param>
/// <param name="buttons">A System.Windows.MessageBoxButton value that specifies which button or buttons to display.</param> /// <param name="buttons">A <see cref="System.Windows.MessageBoxButton"/> value that specifies which button or buttons to display.</param>
/// <param name="icon">A System.Windows.MessageBoxImage value that specifies the icon to display.</param> /// <param name="icon">A <see cref="System.Windows.MessageBoxImage"/> value that specifies the icon to display.</param>
/// <param name="defaultResult">A System.Windows.MessageBoxResult value that specifies the default result of the message box.</param> /// <param name="defaultResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the default result of the message box.</param>
/// <param name="cancelResult">A System.Windows.MessageBoxResult value that specifies the cancel result of the message box</param> /// <param name="cancelResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the cancel result of the message box</param>
/// <param name="options">A System.Windows.MessageBoxOptions value object that specifies the options.</param>
/// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param> /// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param>
/// <param name="flowDirection">The <see cref="System.Windows.FlowDirection"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultFlowDirection"/></param>
/// <param name="textAlignment">The <see cref="System.Windows.TextAlignment"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultTextAlignment"/></param>
void Setup( void Setup(
string messageBoxText, string messageBoxText,
string caption = null, string caption = null,
@ -30,8 +31,9 @@ namespace Stylet
MessageBoxImage icon = MessageBoxImage.None, MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxResult defaultResult = MessageBoxResult.None,
MessageBoxResult cancelResult = MessageBoxResult.None, MessageBoxResult cancelResult = MessageBoxResult.None,
MessageBoxOptions options = MessageBoxOptions.None, IDictionary<MessageBoxResult, string> buttonLabels = null,
IDictionary<MessageBoxResult, string> buttonLabels = null); FlowDirection? flowDirection = null,
TextAlignment? textAlignment = null);
/// <summary> /// <summary>
/// Gets the button clicked by the user, after they've clicked it /// Gets the button clicked by the user, after they've clicked it
@ -64,6 +66,16 @@ namespace Stylet
/// </summary> /// </summary>
public static IDictionary<MessageBoxImage, SystemSound> SoundMapping { get; set; } public static IDictionary<MessageBoxImage, SystemSound> SoundMapping { get; set; }
/// <summary>
/// Gets or sets the default <see cref="System.Windows.FlowDirection"/> to use
/// </summary>
public static FlowDirection DefaultFlowDirection { get; set; }
/// <summary>
/// Gets or sets the default <see cref="System.Windows.TextAlignment"/> to use
/// </summary>
public static TextAlignment DefaultTextAlignment { get; set; }
static MessageBoxViewModel() static MessageBoxViewModel()
{ {
ButtonLabels = new Dictionary<MessageBoxResult, string>() ButtonLabels = new Dictionary<MessageBoxResult, string>()
@ -100,19 +112,23 @@ namespace Stylet
{ MessageBoxImage.Exclamation, SystemSounds.Exclamation }, { MessageBoxImage.Exclamation, SystemSounds.Exclamation },
{ MessageBoxImage.Information, SystemSounds.Asterisk }, { MessageBoxImage.Information, SystemSounds.Asterisk },
}; };
DefaultFlowDirection = FlowDirection.LeftToRight;
DefaultTextAlignment = TextAlignment.Left;
} }
/// <summary> /// <summary>
/// Setup the MessageBoxViewModel with the information it needs /// Setup the MessageBoxViewModel with the information it needs
/// </summary> /// </summary>
/// <param name="messageBoxText">A System.String that specifies the text to display.</param> /// <param name="messageBoxText">A <see cref="System.String"/> that specifies the text to display.</param>
/// <param name="caption">A System.String that specifies the title bar caption to display.</param> /// <param name="caption">A <see cref="System.String"/> that specifies the title bar caption to display.</param>
/// <param name="buttons">A System.Windows.MessageBoxButton value that specifies which button or buttons to display.</param> /// <param name="buttons">A <see cref="System.Windows.MessageBoxButton"/> value that specifies which button or buttons to display.</param>
/// <param name="icon">A System.Windows.MessageBoxImage value that specifies the icon to display.</param> /// <param name="icon">A <see cref="System.Windows.MessageBoxImage"/> value that specifies the icon to display.</param>
/// <param name="defaultResult">A System.Windows.MessageBoxResult value that specifies the default result of the message box.</param> /// <param name="defaultResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the default result of the message box.</param>
/// <param name="cancelResult">A System.Windows.MessageBoxResult value that specifies the cancel result of the message box</param> /// <param name="cancelResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the cancel result of the message box</param>
/// <param name="options">A System.Windows.MessageBoxOptions value object that specifies the options.</param>
/// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param> /// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param>
/// <param name="flowDirection">The <see cref="System.Windows.FlowDirection"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultFlowDirection"/></param>
/// <param name="textAlignment">The <see cref="System.Windows.TextAlignment"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultTextAlignment"/></param>
public void Setup( public void Setup(
string messageBoxText, string messageBoxText,
string caption = null, string caption = null,
@ -120,8 +136,9 @@ namespace Stylet
MessageBoxImage icon = MessageBoxImage.None, MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxResult defaultResult = MessageBoxResult.None,
MessageBoxResult cancelResult = MessageBoxResult.None, MessageBoxResult cancelResult = MessageBoxResult.None,
MessageBoxOptions options = MessageBoxOptions.None, IDictionary<MessageBoxResult, string> buttonLabels = null,
IDictionary<MessageBoxResult, string> buttonLabels = null) FlowDirection? flowDirection = null,
TextAlignment? textAlignment = null)
{ {
this.Text = messageBoxText; this.Text = messageBoxText;
this.DisplayName = caption; this.DisplayName = caption;
@ -158,8 +175,8 @@ namespace Stylet
throw new ArgumentException("CancelButton set to a button which doesn't appear in Buttons"); throw new ArgumentException("CancelButton set to a button which doesn't appear in Buttons");
} }
this.FlowDirection = options.HasFlag(MessageBoxOptions.RtlReading) ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; this.FlowDirection = flowDirection ?? DefaultFlowDirection;
this.TextAlignment = (options.HasFlag(MessageBoxOptions.RightAlign) == options.HasFlag(MessageBoxOptions.RtlReading)) ? TextAlignment.Left : TextAlignment.Right; this.TextAlignment = textAlignment ?? DefaultTextAlignment;
} }
/// <summary> /// <summary>

View File

@ -28,22 +28,24 @@ namespace Stylet
/// <summary> /// <summary>
/// Display a MessageBox /// Display a MessageBox
/// </summary> /// </summary>
/// <param name="messageBoxText">A System.String that specifies the text to display.</param> /// <param name="messageBoxText">A <see cref="System.String"/> that specifies the text to display.</param>
/// <param name="caption">A System.String that specifies the title bar caption to display.</param> /// <param name="caption">A <see cref="System.String"/> that specifies the title bar caption to display.</param>
/// <param name="buttons">A System.Windows.MessageBoxButton value that specifies which button or buttons to display.</param> /// <param name="buttons">A <see cref="System.Windows.MessageBoxButton"/> value that specifies which button or buttons to display.</param>
/// <param name="icon">A System.Windows.MessageBoxImage value that specifies the icon to display.</param> /// <param name="icon">A <see cref="System.Windows.MessageBoxImage"/> value that specifies the icon to display.</param>
/// <param name="defaultResult">A System.Windows.MessageBoxResult value that specifies the default result of the message box.</param> /// <param name="defaultResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the default result of the message box.</param>
/// <param name="cancelResult">A System.Windows.MessageBoxResult value that specifies the cancel result of the message box</param> /// <param name="cancelResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the cancel result of the message box</param>
/// <param name="options">A System.Windows.MessageBoxOptions value object that specifies the options.</param>
/// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param> /// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param>
/// <param name="flowDirection">The <see cref="System.Windows.FlowDirection"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultFlowDirection"/></param>
/// <param name="textAlignment">The <see cref="System.Windows.TextAlignment"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultTextAlignment"/></param>
/// <returns>The result chosen by the user</returns> /// <returns>The result chosen by the user</returns>
MessageBoxResult ShowMessageBox(string messageBoxText, string caption = null, MessageBoxResult ShowMessageBox(string messageBoxText, string caption = "",
MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxButton buttons = MessageBoxButton.OK,
MessageBoxImage icon = MessageBoxImage.None, MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxResult defaultResult = MessageBoxResult.None,
MessageBoxResult cancelResult = MessageBoxResult.None, MessageBoxResult cancelResult = MessageBoxResult.None,
MessageBoxOptions options = MessageBoxOptions.None, IDictionary<MessageBoxResult, string> buttonLabels = null,
IDictionary<MessageBoxResult, string> buttonLabels = null); FlowDirection? flowDirection = null,
TextAlignment? textAlignment = null);
} }
/// <summary> /// <summary>
@ -103,25 +105,27 @@ namespace Stylet
/// <summary> /// <summary>
/// Display a MessageBox /// Display a MessageBox
/// </summary> /// </summary>
/// <param name="messageBoxText">A System.String that specifies the text to display.</param> /// <param name="messageBoxText">A <see cref="System.String"/> that specifies the text to display.</param>
/// <param name="caption">A System.String that specifies the title bar caption to display.</param> /// <param name="caption">A <see cref="System.String"/> that specifies the title bar caption to display.</param>
/// <param name="buttons">A System.Windows.MessageBoxButton value that specifies which button or buttons to display.</param> /// <param name="buttons">A <see cref="System.Windows.MessageBoxButton"/> value that specifies which button or buttons to display.</param>
/// <param name="icon">A System.Windows.MessageBoxImage value that specifies the icon to display.</param> /// <param name="icon">A <see cref="System.Windows.MessageBoxImage"/> value that specifies the icon to display.</param>
/// <param name="defaultResult">A System.Windows.MessageBoxResult value that specifies the default result of the message box.</param> /// <param name="defaultResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the default result of the message box.</param>
/// <param name="cancelResult">A System.Windows.MessageBoxResult value that specifies the cancel result of the message box</param> /// <param name="cancelResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the cancel result of the message box</param>
/// <param name="options">A System.Windows.MessageBoxOptions value object that specifies the options.</param>
/// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param> /// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param>
/// <param name="flowDirection">The <see cref="System.Windows.FlowDirection"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultFlowDirection"/></param>
/// <param name="textAlignment">The <see cref="System.Windows.TextAlignment"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultTextAlignment"/></param>
/// <returns>The result chosen by the user</returns> /// <returns>The result chosen by the user</returns>
public MessageBoxResult ShowMessageBox(string messageBoxText, string caption = "", public MessageBoxResult ShowMessageBox(string messageBoxText, string caption = "",
MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxButton buttons = MessageBoxButton.OK,
MessageBoxImage icon = MessageBoxImage.None, MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxResult defaultResult = MessageBoxResult.None,
MessageBoxResult cancelResult = MessageBoxResult.None, MessageBoxResult cancelResult = MessageBoxResult.None,
MessageBoxOptions options = MessageBoxOptions.None, IDictionary<MessageBoxResult, string> buttonLabels = null,
IDictionary<MessageBoxResult, string> buttonLabels = null) FlowDirection? flowDirection = null,
TextAlignment? textAlignment = null)
{ {
var vm = this.messageBoxViewModelFactory(); var vm = this.messageBoxViewModelFactory();
vm.Setup(messageBoxText, caption, buttons, icon, defaultResult, cancelResult, options, buttonLabels); vm.Setup(messageBoxText, caption, buttons, icon, defaultResult, cancelResult, buttonLabels, flowDirection, textAlignment);
// Don't go through the IoC container to get the View. This means we can simplify it... // Don't go through the IoC container to get the View. This means we can simplify it...
var messageBoxView = new MessageBoxView(); var messageBoxView = new MessageBoxView();
messageBoxView.InitializeComponent(); messageBoxView.InitializeComponent();

View File

@ -31,31 +31,31 @@ namespace StyletUnitTests
[Test] [Test]
public void SetsTextCorrectly() public void SetsTextCorrectly()
{ {
this.vm.Setup("this is the text", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup("this is the text", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual("this is the text", this.vm.Text); Assert.AreEqual("this is the text", this.vm.Text);
} }
[Test] [Test]
public void DeterminesTextIsMultilineCorrectly() public void DeterminesTextIsMultilineCorrectly()
{ {
this.vm.Setup("this is the text", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup("this is the text", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.IsFalse(this.vm.TextIsMultiline); Assert.IsFalse(this.vm.TextIsMultiline);
this.vm.Setup("hello\nworld", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup("hello\nworld", null, MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.IsTrue(this.vm.TextIsMultiline); Assert.IsTrue(this.vm.TextIsMultiline);
} }
[Test] [Test]
public void SetsTitleCorrectly() public void SetsTitleCorrectly()
{ {
this.vm.Setup(null, "this is the title", MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, "this is the title", MessageBoxButton.OK, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual("this is the title", this.vm.DisplayName); Assert.AreEqual("this is the title", this.vm.DisplayName);
} }
[Test] [Test]
public void DisplaysRequestedButtons() public void DisplaysRequestedButtons()
{ {
this.vm.Setup(null, null, MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
var buttons = vm.ButtonList.ToList(); var buttons = vm.ButtonList.ToList();
Assert.AreEqual(2, buttons.Count); Assert.AreEqual(2, buttons.Count);
Assert.AreEqual("OK", buttons[0].Label); Assert.AreEqual("OK", buttons[0].Label);
@ -67,47 +67,47 @@ namespace StyletUnitTests
[Test] [Test]
public void SetsDefaultButtonToTheRequestedButton() public void SetsDefaultButtonToTheRequestedButton()
{ {
this.vm.Setup(null, null, MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.Cancel, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.Cancel, MessageBoxResult.None, null, null, null);
Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.DefaultButton); Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.DefaultButton);
} }
[Test] [Test]
public void SetsDefaultToLeftmostButtonIfDefaultRequested() public void SetsDefaultToLeftmostButtonIfDefaultRequested()
{ {
this.vm.Setup(null, null, MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual(this.vm.ButtonList.ElementAt(0), this.vm.DefaultButton); Assert.AreEqual(this.vm.ButtonList.ElementAt(0), this.vm.DefaultButton);
} }
[Test] [Test]
public void ThrowsIfTheRequestedDefaultButtonIsNotDisplayed() public void ThrowsIfTheRequestedDefaultButtonIsNotDisplayed()
{ {
Assert.Throws<ArgumentException>(() => this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Yes, MessageBoxResult.None, MessageBoxOptions.None, null)); Assert.Throws<ArgumentException>(() => this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Yes, MessageBoxResult.None, null, null, null));
} }
[Test] [Test]
public void SetsCancelButtonToTheRequestedButton() public void SetsCancelButtonToTheRequestedButton()
{ {
this.vm.Setup(null, null, MessageBoxButton.YesNoCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.No, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.YesNoCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.No, null, null, null);
Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.CancelButton); Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.CancelButton);
} }
[Test] [Test]
public void SetsCancelToRighmostButtonIfDefaultRequested() public void SetsCancelToRighmostButtonIfDefaultRequested()
{ {
this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.CancelButton); Assert.AreEqual(this.vm.ButtonList.ElementAt(1), this.vm.CancelButton);
} }
[Test] [Test]
public void ThrowsIfRequestedCancelButtonIsNotDisplayed() public void ThrowsIfRequestedCancelButtonIsNotDisplayed()
{ {
Assert.Throws<ArgumentException>(() => this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.No, MessageBoxOptions.None, null)); Assert.Throws<ArgumentException>(() => this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.No, null, null, null));
} }
[Test] [Test]
public void SetsIconCorrectly() public void SetsIconCorrectly()
{ {
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual(SystemIcons.Exclamation, this.vm.ImageIcon); Assert.AreEqual(SystemIcons.Exclamation, this.vm.ImageIcon);
} }
@ -116,7 +116,7 @@ namespace StyletUnitTests
{ {
var parent = new Mock<IChildDelegate>(); var parent = new Mock<IChildDelegate>();
this.vm.Parent = parent.Object; this.vm.Parent = parent.Object;
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
this.vm.ButtonClicked(MessageBoxResult.No); this.vm.ButtonClicked(MessageBoxResult.No);
@ -129,17 +129,17 @@ namespace StyletUnitTests
{ {
var vm = new MyMessageBoxViewModel(); var vm = new MyMessageBoxViewModel();
// Can't test it actually playing the sound // Can't test it actually playing the sound
vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.DoesNotThrow(() => vm.OnViewLoaded()); Assert.DoesNotThrow(() => vm.OnViewLoaded());
} }
[Test] [Test]
public void ButtonTextOverridesWork() public void ButtonTextOverridesWork()
{ {
this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, new Dictionary<MessageBoxResult, string>() this.vm.Setup(null, null, MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, new Dictionary<MessageBoxResult, string>()
{ {
{ MessageBoxResult.Cancel, "YAY!" }, { MessageBoxResult.Cancel, "YAY!" },
}); }, null, null);
Assert.AreEqual("OK", this.vm.ButtonList.ElementAt(0).Label); Assert.AreEqual("OK", this.vm.ButtonList.ElementAt(0).Label);
Assert.AreEqual("YAY!", this.vm.ButtonList.ElementAt(1).Label); Assert.AreEqual("YAY!", this.vm.ButtonList.ElementAt(1).Label);
} }
@ -147,43 +147,29 @@ namespace StyletUnitTests
[Test] [Test]
public void FlowsLeftToRightByDefault() public void FlowsLeftToRightByDefault()
{ {
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual(FlowDirection.LeftToRight, this.vm.FlowDirection); Assert.AreEqual(FlowDirection.LeftToRight, this.vm.FlowDirection);
} }
[Test] [Test]
public void FlowsRightToLeftIfRequested() public void FlowsRightToLeftIfRequested()
{ {
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.RtlReading, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, FlowDirection.RightToLeft, null);
Assert.AreEqual(FlowDirection.RightToLeft, this.vm.FlowDirection); Assert.AreEqual(FlowDirection.RightToLeft, this.vm.FlowDirection);
} }
[Test] [Test]
public void AlignsLeftIfLeftToRightByDefault() public void AlignsLeftByDefault()
{ {
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.None, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, null);
Assert.AreEqual(TextAlignment.Left, this.vm.TextAlignment); Assert.AreEqual(TextAlignment.Left, this.vm.TextAlignment);
} }
[Test] [Test]
public void AlignsRightIfLeftToRightAndRequested() public void AlignsRightIfRequested()
{ {
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.RightAlign, null); this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, null, null, TextAlignment.Right);
Assert.AreEqual(TextAlignment.Right, this.vm.TextAlignment); Assert.AreEqual(TextAlignment.Right, this.vm.TextAlignment);
} }
[Test]
public void AlignsRightIfRightToLeftByDefault()
{
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.RtlReading, null);
Assert.AreEqual(TextAlignment.Right, this.vm.TextAlignment);
}
[Test]
public void AlignsLeftIfRightToLeftAndRequested()
{
this.vm.Setup(null, null, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxResult.None, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading, null);
Assert.AreEqual(TextAlignment.Left, this.vm.TextAlignment);
}
} }
} }

View File

@ -325,10 +325,10 @@ namespace StyletUnitTests
{ {
var wm = new WindowManagerWithoutCreateWindow(this.viewManager.Object, () => this.messageBoxViewModel.Object, this.config.Object); var wm = new WindowManagerWithoutCreateWindow(this.viewManager.Object, () => this.messageBoxViewModel.Object, this.config.Object);
try { wm.ShowMessageBox("text", "title", MessageBoxButton.OKCancel, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxResult.Cancel, MessageBoxOptions.RtlReading); } try { wm.ShowMessageBox("text", "title", MessageBoxButton.OKCancel, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxResult.Cancel, null, FlowDirection.RightToLeft, TextAlignment.Right); }
catch (TestException) { } catch (TestException) { }
this.messageBoxViewModel.Verify(x => x.Setup("text", "title", MessageBoxButton.OKCancel, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxResult.Cancel, MessageBoxOptions.RtlReading, null)); this.messageBoxViewModel.Verify(x => x.Setup("text", "title", MessageBoxButton.OKCancel, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxResult.Cancel, null, FlowDirection.RightToLeft, TextAlignment.Right));
} }
[Test] [Test]