diff --git a/.vscode/settings.json b/.vscode/settings.json index c67f183f7d..f63e0af54f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ }, "var": { "configuration" : "Debug", - "buildProperties" : "/v:Minimal /p:GenerateFullPaths=True /consoleLoggerParameters:NoSummary" + "buildProperties" : "/v:Minimal /p:GenerateFullPaths=True /consoleloggerparameters:'ForceNoAlign;NoSummary'" }, "vssolution.altSolutionFolders": [ "src", diff --git a/src/Eto.WinForms/Forms/Controls/SplitterHandler.cs b/src/Eto.WinForms/Forms/Controls/SplitterHandler.cs index f0bc32f8d2..75bfe45d5f 100644 --- a/src/Eto.WinForms/Forms/Controls/SplitterHandler.cs +++ b/src/Eto.WinForms/Forms/Controls/SplitterHandler.cs @@ -365,18 +365,18 @@ void SetInitialPosition() } else if (fixedPanel == SplitterFixedPanel.Panel1) { - var size1 = panel1.GetPreferredSize(); + var size1 = panel1?.GetPreferredSize() ?? Size.Empty; SetRelative(Control.Orientation == swf.Orientation.Vertical ? size1.Width : size1.Height); } else if (fixedPanel == SplitterFixedPanel.Panel2) { - var size2 = panel2.GetPreferredSize(); + var size2 = panel2?.GetPreferredSize() ?? Size.Empty; SetRelative(Control.Orientation == swf.Orientation.Vertical ? size2.Width : size2.Height); } else { - var size1 = panel1.GetPreferredSize(); - var size2 = panel2.GetPreferredSize(); + var size1 = panel1?.GetPreferredSize() ?? Size.Empty; + var size2 = panel2?.GetPreferredSize() ?? Size.Empty; SetRelative(Control.Orientation == swf.Orientation.Vertical ? size1.Width / (double)(size1.Width + size2.Width) : size1.Height / (double)(size1.Height + size2.Height)); diff --git a/src/Eto.Wpf/Forms/Menu/MenuItemHandler.cs b/src/Eto.Wpf/Forms/Menu/MenuItemHandler.cs index 057f0cceed..59ea83f562 100644 --- a/src/Eto.Wpf/Forms/Menu/MenuItemHandler.cs +++ b/src/Eto.Wpf/Forms/Menu/MenuItemHandler.cs @@ -4,6 +4,36 @@ interface IMenuItemHandler { void Validate(); } + + public class EtoKeyGesture : swi.InputGesture + { + public EtoKeyGesture(Func isEnabled, swi.Key key, swi.ModifierKeys modifiers) + { + _isEnabled = isEnabled ?? throw new ArgumentNullException(nameof(isEnabled)); + Key = key; + Modifiers = modifiers; + } + + Func _isEnabled; + + public swi.Key Key { get; } + public swi.ModifierKeys Modifiers { get; } + + public override bool Matches(object targetElement, swi.InputEventArgs inputEventArgs) + { + // only match if enabled, which is different from WPF's default behavior + // this allows specific keys to be used in the application when the menu item is disabled + if (!_isEnabled()) + return false; + if (inputEventArgs is swi.KeyEventArgs args && IsDefinedKey(args.Key)) + { + return ((int)Key == (int)args.Key) && (Modifiers == swi.Keyboard.Modifiers); + } + return false; + } + + internal static bool IsDefinedKey(swi.Key key) => key >= swi.Key.None && key <= swi.Key.OemClear; + } public static class MenuItemHandler { @@ -70,37 +100,6 @@ public string ToolTip set { Control.ToolTip = value; } } - - class EtoKeyGesture : swi.InputGesture - { - public EtoKeyGesture(MenuItemHandler menuItemHandler, swi.Key key, swi.ModifierKeys modifiers) - { - MenuItemHandler = menuItemHandler; - Key = key; - Modifiers = modifiers; - } - - public MenuItemHandler MenuItemHandler { get; } - - public swi.Key Key { get; } - public swi.ModifierKeys Modifiers { get; } - - public override bool Matches(object targetElement, swi.InputEventArgs inputEventArgs) - { - // only match if enabled, which is different from WPF's default behavior - // this allows specific keys to be used in the application when the menu item is disabled - if (!MenuItemHandler.Enabled) - return false; - if (inputEventArgs is swi.KeyEventArgs args && IsDefinedKey(args.Key)) - { - return ( (int)Key == (int)args.Key ) && ( Modifiers == swi.Keyboard.Modifiers ); - } - return false; - } - - internal static bool IsDefinedKey(swi.Key key) => key >= swi.Key.None && key <= swi.Key.OemClear; - } - public Keys Shortcut { get @@ -116,7 +115,7 @@ public Keys Shortcut { var key = value.ToWpfKey(); var modifier = value.ToWpfModifier(); - var gesture = new EtoKeyGesture(this, key, modifier); + var gesture = new EtoKeyGesture(() => Enabled, key, modifier); Control.InputBindings.Add(new swi.InputBinding(this, gesture)); Control.InputGestureText = value.ToShortcutString(); AddKeyBindings(Control); diff --git a/test/Eto.Test.Gtk/Eto.Test.Gtk2.csproj b/test/Eto.Test.Gtk/Eto.Test.Gtk2.csproj index 6f615d3a62..1a1a413fb1 100644 --- a/test/Eto.Test.Gtk/Eto.Test.Gtk2.csproj +++ b/test/Eto.Test.Gtk/Eto.Test.Gtk2.csproj @@ -44,7 +44,7 @@ - + \ No newline at end of file diff --git a/test/Eto.Test.Gtk/Eto.Test.Gtk3.csproj b/test/Eto.Test.Gtk/Eto.Test.Gtk3.csproj index b44e10fd56..0338bff97d 100644 --- a/test/Eto.Test.Gtk/Eto.Test.Gtk3.csproj +++ b/test/Eto.Test.Gtk/Eto.Test.Gtk3.csproj @@ -55,7 +55,7 @@ - + \ No newline at end of file diff --git a/test/Eto.Test.Gtk/UnitTests/NativeParentWindowTests.cs b/test/Eto.Test.Gtk/UnitTests/NativeParentWindowTests.cs index e40dc304bd..23a90d2e5e 100644 --- a/test/Eto.Test.Gtk/UnitTests/NativeParentWindowTests.cs +++ b/test/Eto.Test.Gtk/UnitTests/NativeParentWindowTests.cs @@ -20,8 +20,8 @@ public void ControlInNativeWindowShouldReturnParentWindow() window.Child = panel.ToNative(true); var parentWindow = panel.ParentWindow; - Assert.IsNotNull(parentWindow, "#1"); - Assert.AreSame(window, parentWindow.ControlObject, "#2"); + Assert.That(parentWindow, Is.Not.Null, "#1"); + Assert.That(window, Is.SameAs(parentWindow.ControlObject), "#2"); }); } @@ -88,7 +88,7 @@ public void DialogShouldAllowAttachingToNativeWindow() nswindow.MakeKeyAndOrderFront(nswindow); }); ev.WaitOne(); - Assert.IsTrue(passed); + Assert.That(passed, Is.True); }*/ } } diff --git a/test/Eto.Test.Mac/Eto.Test.Mac64.csproj b/test/Eto.Test.Mac/Eto.Test.Mac64.csproj index 6597c75de3..1823d061b5 100644 --- a/test/Eto.Test.Mac/Eto.Test.Mac64.csproj +++ b/test/Eto.Test.Mac/Eto.Test.Mac64.csproj @@ -56,7 +56,7 @@ - + diff --git a/test/Eto.Test.Mac/Eto.Test.macOS.csproj b/test/Eto.Test.Mac/Eto.Test.macOS.csproj index 095107cb05..73a7820b47 100644 --- a/test/Eto.Test.Mac/Eto.Test.macOS.csproj +++ b/test/Eto.Test.Mac/Eto.Test.macOS.csproj @@ -37,7 +37,7 @@ - + diff --git a/test/Eto.Test.Mac/UnitTests/ButtonTests.cs b/test/Eto.Test.Mac/UnitTests/ButtonTests.cs index adc40ad180..b78f627008 100644 --- a/test/Eto.Test.Mac/UnitTests/ButtonTests.cs +++ b/test/Eto.Test.Mac/UnitTests/ButtonTests.cs @@ -23,18 +23,18 @@ public void ButtonNaturalSizeShouldBeConsistent() form.ClientSize = new Size(200, 200); var handler = button?.Handler as ButtonHandler; - Assert.IsNotNull(handler, "#1.1"); + Assert.That(handler, Is.Not.Null, "#1.1"); // big sur changed default height from 21 to 22. var defaultButtonHeight = ButtonHandler.DefaultButtonSize.Height; var b = new EtoButton(NSButtonType.MomentaryPushIn); var originalSize = b.GetAlignmentRectForFrame(new CGRect(CGPoint.Empty, b.FittingSize)).Size; - Assert.AreEqual((nfloat)defaultButtonHeight, originalSize.Height, "#2.1"); + Assert.That(originalSize.Height, Is.EqualTo((nfloat)defaultButtonHeight), "#2.1"); var preferred = handler.GetPreferredSize(SizeF.PositiveInfinity); - Assert.AreEqual(originalSize.Height, preferred.Height, "#2.1"); - Assert.AreEqual(NSBezelStyle.Rounded, handler.Control.BezelStyle, "#2.2"); + Assert.That(preferred.Height, Is.EqualTo(originalSize.Height), "#2.1"); + Assert.That(handler.Control.BezelStyle, Is.EqualTo(NSBezelStyle.Rounded), "#2.2"); form.Shown += async (sender, e) => { @@ -45,27 +45,27 @@ public void ButtonNaturalSizeShouldBeConsistent() await Task.Delay(1000); await Application.Instance.InvokeAsync(() => { - Assert.AreEqual(NSBezelStyle.RegularSquare, handler.Control.BezelStyle, "#3.1"); - Assert.AreEqual(defaultButtonHeight + 1, handler.Widget.Height, "#3.2"); + Assert.That(handler.Control.BezelStyle, Is.EqualTo(NSBezelStyle.RegularSquare), "#3.1"); + Assert.That(handler.Widget.Height, Is.EqualTo(defaultButtonHeight + 1), "#3.2"); }); panel.Size = new Size(-1, -1); await Application.Instance.InvokeAsync(() => { - Assert.AreEqual(NSBezelStyle.Rounded, handler.Control.BezelStyle, "#4.1"); - Assert.AreEqual(defaultButtonHeight, handler.Widget.Height, "#4.2"); + Assert.That(handler.Control.BezelStyle, Is.EqualTo(NSBezelStyle.Rounded), "#4.1"); + Assert.That(handler.Widget.Height, Is.EqualTo(defaultButtonHeight), "#4.2"); }); panel.Size = new Size(-1, defaultButtonHeight - 1); await Task.Delay(1000); await Application.Instance.InvokeAsync(() => { - Assert.AreEqual(NSBezelStyle.SmallSquare, handler.Control.BezelStyle, "#5.1"); - Assert.AreEqual(defaultButtonHeight - 1, handler.Widget.Height, "#5.2"); + Assert.That(handler.Control.BezelStyle, Is.EqualTo(NSBezelStyle.SmallSquare), "#5.1"); + Assert.That(handler.Widget.Height, Is.EqualTo(defaultButtonHeight - 1), "#5.2"); }); panel.Size = new Size(-1, -1); await Application.Instance.InvokeAsync(() => { - Assert.AreEqual(NSBezelStyle.Rounded, handler.Control.BezelStyle, "#6.1"); - Assert.AreEqual(defaultButtonHeight, handler.Widget.Height, "#6.2"); + Assert.That(handler.Control.BezelStyle, Is.EqualTo(NSBezelStyle.Rounded), "#6.1"); + Assert.That(handler.Widget.Height, Is.EqualTo(defaultButtonHeight), "#6.2"); }); } diff --git a/test/Eto.Test.Mac/UnitTests/IconTests.cs b/test/Eto.Test.Mac/UnitTests/IconTests.cs index 336d5213b0..515cdf065e 100644 --- a/test/Eto.Test.Mac/UnitTests/IconTests.cs +++ b/test/Eto.Test.Mac/UnitTests/IconTests.cs @@ -18,22 +18,22 @@ public void BitmapToIconShouldNotChangeBitmapSize() var newSize = new Size(32, 32); // initial sanity check - Assert.AreEqual(oldSize, bitmapRep.Size.ToEtoSize(), "#1"); + Assert.That(bitmapRep.Size.ToEtoSize(), Is.EqualTo(oldSize), "#1"); var icon = bmp.WithSize(newSize); var iconNSImage = icon.ControlObject as NSImage; var iconRep = iconNSImage.Representations()[0] as NSBitmapImageRep; - Assert.AreEqual(bmp.Size, oldSize, "#2.1"); - Assert.AreEqual(newSize, icon.Size, "#2.2"); - Assert.AreEqual(bmp.Size, icon.Frames.First().PixelSize, "#2.3"); + Assert.That(oldSize, Is.EqualTo(bmp.Size), "#2.1"); + Assert.That(icon.Size, Is.EqualTo(newSize), "#2.2"); + Assert.That(icon.Frames.First().PixelSize, Is.EqualTo(bmp.Size), "#2.3"); // rep in icon needs the new size - Assert.AreEqual(newSize, iconRep.Size.ToEtoSize(), "#2.4"); + Assert.That(iconRep.Size.ToEtoSize(), Is.EqualTo(newSize), "#2.4"); // rep in bitmap should have the old size still.. - Assert.AreEqual(oldSize, bitmapRep.Size.ToEtoSize(), "#3"); + Assert.That(bitmapRep.Size.ToEtoSize(), Is.EqualTo(oldSize), "#3"); icon.Dispose(); bmp.Dispose(); diff --git a/test/Eto.Test.Mac/UnitTests/NativeParentWindowTests.cs b/test/Eto.Test.Mac/UnitTests/NativeParentWindowTests.cs index 45c0271633..7a14df7c42 100644 --- a/test/Eto.Test.Mac/UnitTests/NativeParentWindowTests.cs +++ b/test/Eto.Test.Mac/UnitTests/NativeParentWindowTests.cs @@ -16,8 +16,8 @@ public void ControlInNativeWindowShouldReturnParentWindow() nswindow.ContentView = panel.ToNative(true); var parentWindow = panel.ParentWindow; - Assert.IsNotNull(parentWindow, "#1"); - Assert.AreSame(nswindow, parentWindow.ControlObject, "#2"); + Assert.That(parentWindow, Is.Not.Null, "#1"); + Assert.That(nswindow, Is.SameAs(parentWindow.ControlObject), "#2"); }); } @@ -83,7 +83,7 @@ public void DialogShouldAllowAttachingToNativeWindow() nswindow.MakeKeyAndOrderFront(nswindow); }); ev.WaitOne(); - Assert.IsTrue(passed); + Assert.That(passed, Is.True); } } } diff --git a/test/Eto.Test.Mac/UnitTests/ResourceTests.cs b/test/Eto.Test.Mac/UnitTests/ResourceTests.cs index 1117154b64..dc7ea35212 100644 --- a/test/Eto.Test.Mac/UnitTests/ResourceTests.cs +++ b/test/Eto.Test.Mac/UnitTests/ResourceTests.cs @@ -10,7 +10,7 @@ public void ContentShouldBeInResources() { var path = EtoEnvironment.GetFolderPath(EtoSpecialFolder.ApplicationResources); var file = Path.Combine(path, "Assets", "TestContent.txt"); - Assert.IsTrue(File.Exists(file)); + Assert.That(File.Exists(file), Is.True); } [Test] @@ -18,7 +18,7 @@ public void BundleResourceShouldBeInResources() { var path = EtoEnvironment.GetFolderPath(EtoSpecialFolder.ApplicationResources); var file = Path.Combine(path, "Assets", "TestBundleResource.txt"); - Assert.IsTrue(File.Exists(file)); + Assert.That(File.Exists(file), Is.True); } [Test] @@ -27,10 +27,10 @@ public void CopyToOutputShouldBeInExecutablePath() // getting the location of the assembly can be null when using mkbundle, so we use this instead. var path = EtoEnvironment.GetFolderPath(EtoSpecialFolder.EntryExecutable); - Assert.IsNotEmpty(path, "#1"); + Assert.That(path, Is.Not.Empty, "#1"); var file = Path.Combine(path, "Assets", "TestCopyToOutput.txt"); Console.WriteLine($"Looking for file '{file}'"); - Assert.IsTrue(File.Exists(file), "#2"); + Assert.That(File.Exists(file), Is.True, "#2"); } } } diff --git a/test/Eto.Test.Mac/UnitTests/RichTextAreaHandlerTests.cs b/test/Eto.Test.Mac/UnitTests/RichTextAreaHandlerTests.cs index 50664aef69..1bd2ea8c02 100644 --- a/test/Eto.Test.Mac/UnitTests/RichTextAreaHandlerTests.cs +++ b/test/Eto.Test.Mac/UnitTests/RichTextAreaHandlerTests.cs @@ -18,50 +18,50 @@ public void EnabledShouldChangeEditable() var richTextArea = new RichTextArea(); var handler = richTextArea.Handler as RichTextAreaHandler; - Assert.IsTrue(richTextArea.Enabled, "#1"); - Assert.IsFalse(richTextArea.ReadOnly, "#2"); - Assert.IsTrue(handler.Control.Selectable, "#3"); - Assert.IsTrue(handler.Control.Editable, "#4"); + Assert.That(richTextArea.Enabled, Is.True, "#1"); + Assert.That(richTextArea.ReadOnly, Is.False, "#2"); + Assert.That(handler.Control.Selectable, Is.True, "#3"); + Assert.That(handler.Control.Editable, Is.True, "#4"); richTextArea.Enabled = false; - Assert.IsFalse(handler.Control.Selectable, "#5"); - Assert.IsFalse(handler.Control.Editable, "#6"); + Assert.That(handler.Control.Selectable, Is.False, "#5"); + Assert.That(handler.Control.Editable, Is.False, "#6"); richTextArea.Enabled = true; - Assert.IsTrue(handler.Control.Selectable, "#7"); - Assert.IsTrue(handler.Control.Editable, "#8"); + Assert.That(handler.Control.Selectable, Is.True, "#7"); + Assert.That(handler.Control.Editable, Is.True, "#8"); richTextArea.ReadOnly = true; - Assert.IsTrue(handler.Control.Selectable, "#9"); - Assert.IsFalse(handler.Control.Editable, "#10"); + Assert.That(handler.Control.Selectable, Is.True, "#9"); + Assert.That(handler.Control.Editable, Is.False, "#10"); richTextArea.Enabled = false; - Assert.IsFalse(handler.Control.Selectable, "#11"); - Assert.IsFalse(handler.Control.Editable, "#12"); + Assert.That(handler.Control.Selectable, Is.False, "#11"); + Assert.That(handler.Control.Editable, Is.False, "#12"); richTextArea.Enabled = true; - Assert.IsTrue(handler.Control.Selectable, "#13"); - Assert.IsFalse(handler.Control.Editable, "#14"); + Assert.That(handler.Control.Selectable, Is.True, "#13"); + Assert.That(handler.Control.Editable, Is.False, "#14"); richTextArea.ReadOnly = false; - Assert.IsTrue(handler.Control.Selectable, "#15"); - Assert.IsTrue(handler.Control.Editable, "#16"); + Assert.That(handler.Control.Selectable, Is.True, "#15"); + Assert.That(handler.Control.Editable, Is.True, "#16"); richTextArea.Enabled = false; - Assert.IsFalse(handler.Control.Selectable, "#17"); - Assert.IsFalse(handler.Control.Editable, "#18"); + Assert.That(handler.Control.Selectable, Is.False, "#17"); + Assert.That(handler.Control.Editable, Is.False, "#18"); richTextArea.ReadOnly = true; - Assert.IsFalse(handler.Control.Selectable, "#19"); - Assert.IsFalse(handler.Control.Editable, "#20"); + Assert.That(handler.Control.Selectable, Is.False, "#19"); + Assert.That(handler.Control.Editable, Is.False, "#20"); richTextArea.Enabled = true; - Assert.IsTrue(handler.Control.Selectable, "#21"); - Assert.IsFalse(handler.Control.Editable, "#22"); + Assert.That(handler.Control.Selectable, Is.True, "#21"); + Assert.That(handler.Control.Editable, Is.False, "#22"); richTextArea.ReadOnly = false; - Assert.IsTrue(handler.Control.Selectable, "#23"); - Assert.IsTrue(handler.Control.Editable, "#24"); + Assert.That(handler.Control.Selectable, Is.True, "#23"); + Assert.That(handler.Control.Editable, Is.True, "#24"); }); } } diff --git a/test/Eto.Test.WinForms/Eto.Test.WinForms.csproj b/test/Eto.Test.WinForms/Eto.Test.WinForms.csproj index 8f3ac53763..5f0c4f5584 100644 --- a/test/Eto.Test.WinForms/Eto.Test.WinForms.csproj +++ b/test/Eto.Test.WinForms/Eto.Test.WinForms.csproj @@ -51,8 +51,8 @@ - - + + diff --git a/test/Eto.Test.WinForms/UnitTests/NativeParentWindowTests.cs b/test/Eto.Test.WinForms/UnitTests/NativeParentWindowTests.cs index dce92f6787..b8434779ea 100644 --- a/test/Eto.Test.WinForms/UnitTests/NativeParentWindowTests.cs +++ b/test/Eto.Test.WinForms/UnitTests/NativeParentWindowTests.cs @@ -26,8 +26,8 @@ public void ControlInWinFormsWindowShouldReturnParentWindow() // get the parent window var parentWindow = panel.ParentWindow; - Assert.IsNotNull(parentWindow, "#1"); - Assert.AreEqual(windowhandle, parentWindow.NativeHandle, "#2"); + Assert.That(parentWindow, Is.Not.Null, "#1"); + Assert.That(parentWindow.NativeHandle, Is.EqualTo(windowhandle), "#2"); }); } @@ -102,7 +102,7 @@ public void FormShouldAllowOwningToWinForms() nativeWindow.Show(); }); ev.WaitOne(); - Assert.IsTrue(passed); + Assert.That(passed, Is.True); } } } diff --git a/test/Eto.Test.WinForms/UnitTests/NativeTests.cs b/test/Eto.Test.WinForms/UnitTests/NativeTests.cs index b9b30a04c2..a4862f018e 100644 --- a/test/Eto.Test.WinForms/UnitTests/NativeTests.cs +++ b/test/Eto.Test.WinForms/UnitTests/NativeTests.cs @@ -13,7 +13,7 @@ public class NativeTests public void SignedHiWord_TestCases_WorkCorrectly(int value, int expected) { var actual = Win32.SignedHIWORD(value); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [TestCase(0, 0)] @@ -24,7 +24,7 @@ public void SignedHiWord_TestCases_WorkCorrectly(int value, int expected) public void SignedLoWord_TestCases_WorkCorrectly(int value, int expected) { var actual = Win32.SignedLOWORD(value); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/test/Eto.Test.Wpf/Eto.Test.Wpf.csproj b/test/Eto.Test.Wpf/Eto.Test.Wpf.csproj index 5b1a6bd97d..dbd6985ba0 100644 --- a/test/Eto.Test.Wpf/Eto.Test.Wpf.csproj +++ b/test/Eto.Test.Wpf/Eto.Test.Wpf.csproj @@ -57,7 +57,7 @@ - + diff --git a/test/Eto.Test.Wpf/UnitTests/DataContextTests.cs b/test/Eto.Test.Wpf/UnitTests/DataContextTests.cs index e372b27d89..1f85ba6814 100644 --- a/test/Eto.Test.Wpf/UnitTests/DataContextTests.cs +++ b/test/Eto.Test.Wpf/UnitTests/DataContextTests.cs @@ -24,7 +24,7 @@ public void DataContextInNativeControlShouldBeSet() var content = new Panel { Content = expander }; - Assert.AreEqual(0, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(0)); // embed the expander natively, so it is 'disconnected' from eto var holder = new Panel(); @@ -34,10 +34,10 @@ public void DataContextInNativeControlShouldBeSet() form.Content = holder; content.DataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(1)); }, () => { - Assert.AreEqual(1, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(1)); }); } } diff --git a/test/Eto.Test.Wpf/UnitTests/DropDownTests.cs b/test/Eto.Test.Wpf/UnitTests/DropDownTests.cs index fa484b8a9c..fbe9b7983b 100755 --- a/test/Eto.Test.Wpf/UnitTests/DropDownTests.cs +++ b/test/Eto.Test.Wpf/UnitTests/DropDownTests.cs @@ -33,7 +33,7 @@ public void DropDownInElementHostShouldHaveCorrectInitialValue() }; dlg.ShowModal(Application.Instance.MainForm); - Assert.AreEqual(1, dropDownIndex); + Assert.That(dropDownIndex, Is.EqualTo(1)); } } diff --git a/test/Eto.Test.Wpf/UnitTests/MenuBarTests.cs b/test/Eto.Test.Wpf/UnitTests/MenuBarTests.cs index 2f733610f3..cab9ca1fe9 100644 --- a/test/Eto.Test.Wpf/UnitTests/MenuBarTests.cs +++ b/test/Eto.Test.Wpf/UnitTests/MenuBarTests.cs @@ -28,11 +28,12 @@ public void MenuBarShouldSetInputBindingsForChildren() // check to make sure the input binding for the command made it var host = form.Handler as IInputBindingHost; - Assert.AreEqual(1, host.InputBindings.Count); - Assert.IsInstanceOf(host.InputBindings[0]); - var kb = (swi.KeyBinding)host.InputBindings[0]; - Assert.AreEqual(swi.Key.N, kb.Key); - Assert.AreEqual(swi.ModifierKeys.Control, kb.Modifiers); + Assert.That(host.InputBindings.Count, Is.EqualTo(1)); + Assert.That(host.InputBindings[0], Is.InstanceOf()); + Assert.That(host.InputBindings[0].Gesture, Is.InstanceOf()); + var kb = (EtoKeyGesture)host.InputBindings[0].Gesture; + Assert.That(kb.Key, Is.EqualTo(swi.Key.N)); + Assert.That(kb.Modifiers, Is.EqualTo(swi.ModifierKeys.Control)); }); } } diff --git a/test/Eto.Test.Wpf/UnitTests/NativeParentWindowTests.cs b/test/Eto.Test.Wpf/UnitTests/NativeParentWindowTests.cs index 763eba8e00..15a02ea48f 100644 --- a/test/Eto.Test.Wpf/UnitTests/NativeParentWindowTests.cs +++ b/test/Eto.Test.Wpf/UnitTests/NativeParentWindowTests.cs @@ -19,8 +19,8 @@ public void ControlInWpfWindowShouldReturnParentWindow() nativeWindow.Content = panel.ToNative(true); var parentWindow = panel.ParentWindow; - Assert.IsNotNull(parentWindow, "#1"); - Assert.AreSame(nativeWindow, parentWindow.ControlObject, "#2"); + Assert.That(parentWindow, Is.Not.Null, "#1"); + Assert.That(nativeWindow, Is.SameAs(parentWindow.ControlObject), "#2"); }); } @@ -44,8 +44,8 @@ public void ControlInWinFormsWindowShouldReturnParentWindow() // get the parent window var parentWindow = panel.ParentWindow; - Assert.IsNotNull(parentWindow, "#1"); - Assert.AreEqual(windowhandle, parentWindow.NativeHandle, "#2"); + Assert.That(parentWindow, Is.Not.Null, "#1"); + Assert.That(parentWindow.NativeHandle, Is.EqualTo(windowhandle), "#2"); }); } @@ -116,7 +116,7 @@ public void FormShouldAllowOwningToWinForms() nativeWindow.Show(); }); ev.WaitOne(); - Assert.IsTrue(passed); + Assert.That(passed, Is.True); } [Test, ManualTest] @@ -192,7 +192,7 @@ public void FormShouldAllowOwningToWpf() nativeWindow.Show(); }); ev.WaitOne(); - Assert.IsTrue(passed); + Assert.That(passed, Is.True); } } diff --git a/test/Eto.Test.Wpf/UnitTests/ScreenTests.cs b/test/Eto.Test.Wpf/UnitTests/ScreenTests.cs index 192b456b28..8342d5922b 100644 --- a/test/Eto.Test.Wpf/UnitTests/ScreenTests.cs +++ b/test/Eto.Test.Wpf/UnitTests/ScreenTests.cs @@ -66,9 +66,9 @@ public void ScreenLocationsShouldBeCorrect1(float pixelSize1, float pixelSize2, helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(-1000, 10, 1000, 1000), LogicalPixelSize = pixelSize3 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(-500, 1010, 500, 500), LogicalPixelSize = pixelSize2 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(-1000 / pixelSize3, 10 / helper.GetMaxLogicalPixelSize()), helper.GetLogicalLocation(helper.Screens[1])); - Assert.AreEqual(new PointF(-500 / pixelSize2, 1010 / helper.GetMaxLogicalPixelSize()), helper.GetLogicalLocation(helper.Screens[2])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(-1000 / pixelSize3, 10 / helper.GetMaxLogicalPixelSize()))); + Assert.That(helper.GetLogicalLocation(helper.Screens[2]), Is.EqualTo(new PointF(-500 / pixelSize2, 1010 / helper.GetMaxLogicalPixelSize()))); } [TestCaseSource(nameof(ThreeMonitorSource))] @@ -89,9 +89,9 @@ public void ScreenLocationsShouldBeCorrect2(float pixelSize1, float pixelSize2, helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(-500, 1000, 500, 500), LogicalPixelSize = pixelSize2 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(-1000, 0, 1000, 1000), LogicalPixelSize = pixelSize3 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(-500 / pixelSize2, 1000 / pixelSize1), helper.GetLogicalLocation(helper.Screens[1])); - Assert.AreEqual(new PointF(-1000 / pixelSize3, 0), helper.GetLogicalLocation(helper.Screens[2])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(-500 / pixelSize2, 1000 / pixelSize1))); + Assert.That(helper.GetLogicalLocation(helper.Screens[2]), Is.EqualTo(new PointF(-1000 / pixelSize3, 0))); } [TestCaseSource(nameof(ThreeMonitorSource))] @@ -112,9 +112,9 @@ public void ScreenLocationsShouldBeCorrect3(float pixelSize1, float pixelSize2, helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(0, -500, 500, 500), LogicalPixelSize = pixelSize2 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(1000, -1000, 1000, 1000), LogicalPixelSize = pixelSize3 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(0, -500 / pixelSize2), helper.GetLogicalLocation(helper.Screens[1])); - Assert.AreEqual(new PointF(1000 / pixelSize1, -1000 / pixelSize3), helper.GetLogicalLocation(helper.Screens[2])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(0, -500 / pixelSize2))); + Assert.That(helper.GetLogicalLocation(helper.Screens[2]), Is.EqualTo(new PointF(1000 / pixelSize1, -1000 / pixelSize3))); } [TestCaseSource(nameof(ThreeMonitorSource))] @@ -135,9 +135,9 @@ public void ScreenLocationsShouldBeCorrect4(float pixelSize1, float pixelSize2, helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(0, 1000, 500, 500), LogicalPixelSize = pixelSize2 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(1000, 1000, 1000, 1000), LogicalPixelSize = pixelSize3 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(0, 1000 / pixelSize1), helper.GetLogicalLocation(helper.Screens[1])); - Assert.AreEqual(new PointF(1000 / pixelSize1, 1000 / pixelSize1), helper.GetLogicalLocation(helper.Screens[2])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(0, 1000 / pixelSize1))); + Assert.That(helper.GetLogicalLocation(helper.Screens[2]), Is.EqualTo(new PointF(1000 / pixelSize1, 1000 / pixelSize1))); } @@ -154,8 +154,8 @@ public void ScreenLocationsShouldBeCorrect5(float pixelSize1, float pixelSize2) helper.Screens.Add(helper.Primary = new TestScreen { Bounds = new sd.Rectangle(0, 0, 1000, 1000), LogicalPixelSize = pixelSize1 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(1000, 0, 1000, 1000), LogicalPixelSize = pixelSize2 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(1000 / pixelSize1, 0), helper.GetLogicalLocation(helper.Screens[1])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(1000 / pixelSize1, 0))); } [TestCaseSource(nameof(TwoMonitorSource))] @@ -171,8 +171,8 @@ public void ScreenLocationsShouldBeCorrect6(float pixelSize1, float pixelSize2) helper.Screens.Add(helper.Primary = new TestScreen { Bounds = new sd.Rectangle(0, 0, 1000, 1000), LogicalPixelSize = pixelSize1 }); helper.Screens.Add(new TestScreen { Bounds = new sd.Rectangle(-1000, 0, 1000, 1000), LogicalPixelSize = pixelSize2 }); - Assert.AreEqual(new PointF(0, 0), helper.GetLogicalLocation(helper.Screens[0])); - Assert.AreEqual(new PointF(-1000 / pixelSize2, 0), helper.GetLogicalLocation(helper.Screens[1])); + Assert.That(helper.GetLogicalLocation(helper.Screens[0]), Is.EqualTo(new PointF(0, 0))); + Assert.That(helper.GetLogicalLocation(helper.Screens[1]), Is.EqualTo(new PointF(-1000 / pixelSize2, 0))); } } } diff --git a/test/Eto.Test.Wpf/UnitTests/TransformStackTest.cs b/test/Eto.Test.Wpf/UnitTests/TransformStackTest.cs index c0db5c6643..bcf7545b0b 100644 --- a/test/Eto.Test.Wpf/UnitTests/TransformStackTest.cs +++ b/test/Eto.Test.Wpf/UnitTests/TransformStackTest.cs @@ -28,23 +28,23 @@ public void TransformStack_TranlateSaveRestore_Verify() var target = new TransformStack(push, pop); - Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f)); + Assert.That(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f), Is.True); target.SaveTransform(); // Save target.TranslateTransform(5f, 5f); - Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f)); + Assert.That(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f), Is.True); target.SaveTransform(); target.TranslateTransform(10f, 10f); - Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 15f, 15f)); + Assert.That(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 15f, 15f), Is.True); target.RestoreTransform(); - Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f)); + Assert.That(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f), Is.True); target.RestoreTransform(); - Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f)); + Assert.That(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f), Is.True); } } } diff --git a/test/Eto.Test/Eto.Test.csproj b/test/Eto.Test/Eto.Test.csproj index e6e6820529..0a6a0840bc 100644 --- a/test/Eto.Test/Eto.Test.csproj +++ b/test/Eto.Test/Eto.Test.csproj @@ -1,9 +1,10 @@  - netstandard2.0;net7.0 + net48;net7.0;net7.0-windows true $(DefineConstants);PCL 10 + true @@ -39,7 +40,9 @@ - + + + diff --git a/test/Eto.Test/TestApplication.cs b/test/Eto.Test/TestApplication.cs index d75a9c8a46..93065e4e0e 100644 --- a/test/Eto.Test/TestApplication.cs +++ b/test/Eto.Test/TestApplication.cs @@ -8,11 +8,7 @@ public class TestApplication : Application public static IEnumerable DefaultTestAssemblies() { -#if PCL - yield return typeof(TestApplication).GetTypeInfo().Assembly; -#else yield return typeof(TestApplication).Assembly; -#endif } public List TestAssemblies { get; private set; } diff --git a/test/Eto.Test/TestSections.cs b/test/Eto.Test/TestSections.cs index 41950e5e05..edcf7ce996 100644 --- a/test/Eto.Test/TestSections.cs +++ b/test/Eto.Test/TestSections.cs @@ -35,11 +35,7 @@ public static IEnumerable
Get(IEnumerable testAssemblies) { foreach (var type in asm.ExportedTypes) { - #if PCL - var section = type.GetTypeInfo().GetCustomAttribute(false); - #else var section = type.GetCustomAttribute(false); - #endif if (section != null) { if (section.Requires != null && !Platform.Instance.Supports(section.Requires)) diff --git a/test/Eto.Test/UnitTests/CollectionChangedHandlerTest.cs b/test/Eto.Test/UnitTests/CollectionChangedHandlerTest.cs index 557fbc3175..b3ee92e244 100644 --- a/test/Eto.Test/UnitTests/CollectionChangedHandlerTest.cs +++ b/test/Eto.Test/UnitTests/CollectionChangedHandlerTest.cs @@ -59,9 +59,9 @@ public void LookupCacheShouldBeClearedWhenEnumerableChanges() var handler = new CollectionHandler(); var collection = new Collection(new[] {"1"}); handler.Register(collection); - Assert.AreEqual(1, handler.Count); + Assert.That(handler.Count, Is.EqualTo(1)); collection.Update(new[] { "1", "2" }); - Assert.AreEqual(2, handler.Count); + Assert.That(handler.Count, Is.EqualTo(2)); } } } diff --git a/test/Eto.Test/UnitTests/Drawing/BitmapTests.cs b/test/Eto.Test/UnitTests/Drawing/BitmapTests.cs index 7ec9b719e5..1883c88479 100644 --- a/test/Eto.Test/UnitTests/Drawing/BitmapTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/BitmapTests.cs @@ -4,12 +4,6 @@ namespace Eto.Test.UnitTests.Drawing [TestFixture] public class BitmapTests : TestBase { - public BitmapTests() - { - // initialize test generator if running through IDE or nunit-gui - TestBase.Initialize(); - } - [Test] public void TestClone32Bit() { @@ -73,7 +67,7 @@ public void TestGetPixelWithLock24bit(float red, float green, float blue) if (colorSet != colorGet) { - Assert.Fail("Pixels are not the same (SetPixel: {0}, GetPixel: {1})", colorSet, colorGet); + Assert.Fail($"Pixels are not the same (SetPixel: {colorSet}, GetPixel: {colorGet})"); } } } @@ -95,7 +89,7 @@ public void TestGetPixelWithoutLock24bit(float red, float green, float blue) if (colorSet != colorGet) { - Assert.Fail("Pixels are not the same (SetPixel: {0}, GetPixel: {1})", colorSet, colorGet); + Assert.Fail($"Pixels are not the same (SetPixel: {colorSet}, GetPixel: {colorGet})"); } } @@ -118,7 +112,7 @@ public void TestGetPixelWithLock32bit(float red, float green, float blue, float if (colorSet != colorGet) { - Assert.Fail("Pixels are not the same (SetPixel: {0}, GetPixel: {1})", colorSet, colorGet); + Assert.Fail($"Pixels are not the same (SetPixel: {colorSet}, GetPixel: {colorGet})"); } } } @@ -140,7 +134,7 @@ public void TestGetPixelWithoutLock32bit(float red, float green, float blue, flo if (colorSet != colorGet) { - Assert.Fail("Pixels are not the same (SetPixel: {0}, GetPixel: {1})", colorSet, colorGet); + Assert.Fail($"Pixels are not the same (SetPixel: {colorSet}, GetPixel: {colorGet})"); } } @@ -168,7 +162,7 @@ static void ValidateImages(Bitmap image, Bitmap clone, Rectangle? rect = null) var clonePixel = *(clonerow++); if (imagePixel != clonePixel) { - Assert.Fail("Image pixels are not the same at position {0},{1} (source: {2}, clone: {3})", x, y, imagePixel, clonePixel); + Assert.Fail($"Image pixels are not the same at position {x},{y} (source: {imagePixel}, clone: {clonePixel})"); } } imageptr += imageData.ScanWidth; @@ -183,7 +177,7 @@ static void ValidateImages(Bitmap image, Bitmap clone, Rectangle? rect = null) var imagePixel = imageData.GetPixel(x + testRect.Left, y + testRect.Top); var clonePixel = cloneData.GetPixel(x, y); if (imagePixel != clonePixel) - Assert.Fail("Image pixels are not the same at position {0},{1} (source: {2}, clone: {3})", x, y, imagePixel, clonePixel); + Assert.Fail($"Image pixels are not the same at position {x},{y} (source: {imagePixel}, clone: {clonePixel})"); } } } @@ -259,15 +253,15 @@ await Task.Run(() => // }); // test output in test thread - Assert.AreEqual(Colors.Blue, bmp.GetPixel(0, 0), "#1"); - Assert.AreEqual(Colors.Green, bmp.GetPixel(10, 0), "#2"); - Assert.AreEqual(Colors.Red, bmp.GetPixel(20, 0), "#3"); + Assert.That(bmp.GetPixel(0, 0), Is.EqualTo(Colors.Blue), "#1"); + Assert.That(bmp.GetPixel(10, 0), Is.EqualTo(Colors.Green), "#2"); + Assert.That(bmp.GetPixel(20, 0), Is.EqualTo(Colors.Red), "#3"); using (var bd = bmp.Lock()) { - Assert.AreEqual(Colors.Blue, bd.GetPixel(0, 0), "#4"); - Assert.AreEqual(Colors.Green, bd.GetPixel(10, 0), "#5"); - Assert.AreEqual(Colors.Red, bd.GetPixel(20, 0), "#6"); + Assert.That(bd.GetPixel(0, 0), Is.EqualTo(Colors.Blue), "#4"); + Assert.That(bd.GetPixel(10, 0), Is.EqualTo(Colors.Green), "#5"); + Assert.That(bd.GetPixel(20, 0), Is.EqualTo(Colors.Red), "#6"); } await Task.Run(() => Shown(f => new ImageView { Image = bmp }, @@ -275,15 +269,15 @@ await Task.Run(() => { // also test in UI thread - Assert.AreEqual(Colors.Blue, bmp.GetPixel(0, 0), "#7"); - Assert.AreEqual(Colors.Green, bmp.GetPixel(10, 0), "#8"); - Assert.AreEqual(Colors.Red, bmp.GetPixel(20, 0), "#9"); + Assert.That(bmp.GetPixel(0, 0), Is.EqualTo(Colors.Blue), "#7"); + Assert.That(bmp.GetPixel(10, 0), Is.EqualTo(Colors.Green), "#8"); + Assert.That(bmp.GetPixel(20, 0), Is.EqualTo(Colors.Red), "#9"); using (var bd = bmp.Lock()) { - Assert.AreEqual(Colors.Blue, bd.GetPixel(0, 0), "#10"); - Assert.AreEqual(Colors.Green, bd.GetPixel(10, 0), "#11"); - Assert.AreEqual(Colors.Red, bd.GetPixel(20, 0), "#12"); + Assert.That(bd.GetPixel(0, 0), Is.EqualTo(Colors.Blue), "#10"); + Assert.That(bd.GetPixel(10, 0), Is.EqualTo(Colors.Green), "#11"); + Assert.That(bd.GetPixel(20, 0), Is.EqualTo(Colors.Red), "#12"); } })); } @@ -324,8 +318,8 @@ public void LockShouldNowThrowIfCalledSequentially() } // sanity check - Assert.AreEqual(Colors.Red, bmp.GetPixel(0, 0)); - Assert.AreEqual(Colors.Blue, bmp.GetPixel(10, 0)); + Assert.That(bmp.GetPixel(0, 0), Is.EqualTo(Colors.Red)); + Assert.That(bmp.GetPixel(10, 0), Is.EqualTo(Colors.Blue)); }); } @@ -359,7 +353,7 @@ public void LockShouldSetPixelsCorrectly(PixelFormat format, int width, int heig for (int j = 0; j < height; ++j) { var c = j < height / 2 ? Colors.Red : Colors.Green; - Assert.AreEqual(c, bitmap.GetPixel(i, j), $"Pixel at {i},{j} is incorrect"); + Assert.That(bitmap.GetPixel(i, j), Is.EqualTo(c), $"Pixel at {i},{j} is incorrect"); } } }); @@ -392,7 +386,7 @@ public void LockShouldGetPixelsCorrectly(PixelFormat format, int width, int heig for (int j = 0; j < height; ++j) { var c = j < height / 2 ? Colors.Red : Colors.Green; - Assert.AreEqual(c, bd.GetPixel(i, j), $"Pixel at {i},{j} is incorrect"); + Assert.That(bd.GetPixel(i, j), Is.EqualTo(c), $"Pixel at {i},{j} is incorrect"); } } } @@ -404,9 +398,9 @@ public void SizeShouldBeInPixels() { Invoke(() => { - Assert.AreEqual(new Size(128, 128), TestIcons.Logo288Bitmap.Size); + Assert.That(TestIcons.Logo288Bitmap.Size, Is.EqualTo(new Size(128, 128))); - Assert.AreEqual(new Size(128, 128), TestIcons.LogoBitmap.Size); + Assert.That(TestIcons.LogoBitmap.Size, Is.EqualTo(new Size(128, 128))); }); } @@ -486,32 +480,32 @@ void GetSavedBitmap() void TestPixels(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight, string test) { - Assert.IsNotNull(bmp); - Assert.IsNotNull(savedBitmap); + Assert.That(bmp, Is.Not.Null); + Assert.That(savedBitmap, Is.Not.Null); - Assert.AreEqual(topLeft, bmp.GetPixel(0, 0), test + ".1.1"); - Assert.AreEqual(topRight, bmp.GetPixel(halfSize, 0), test + ".1.2"); - Assert.AreEqual(bottomLeft, bmp.GetPixel(0, halfSize), test + ".1.3"); - Assert.AreEqual(bottomRight, bmp.GetPixel(halfSize, halfSize), test + ".1.4"); + Assert.That(bmp.GetPixel(0, 0), Is.EqualTo(topLeft), test + ".1.1"); + Assert.That(bmp.GetPixel(halfSize, 0), Is.EqualTo(topRight), test + ".1.2"); + Assert.That(bmp.GetPixel(0, halfSize), Is.EqualTo(bottomLeft), test + ".1.3"); + Assert.That(bmp.GetPixel(halfSize, halfSize), Is.EqualTo(bottomRight), test + ".1.4"); - Assert.AreEqual(topLeft, savedBitmap.GetPixel(0, 0), test + ".2.1"); - Assert.AreEqual(topRight, savedBitmap.GetPixel(halfSize, 0), test + ".2.2"); - Assert.AreEqual(bottomLeft, savedBitmap.GetPixel(0, halfSize), test + ".2.3"); - Assert.AreEqual(bottomRight, savedBitmap.GetPixel(halfSize, halfSize), test + ".2.4"); + Assert.That(savedBitmap.GetPixel(0, 0), Is.EqualTo(topLeft), test + ".2.1"); + Assert.That(savedBitmap.GetPixel(halfSize, 0), Is.EqualTo(topRight), test + ".2.2"); + Assert.That(savedBitmap.GetPixel(0, halfSize), Is.EqualTo(bottomLeft), test + ".2.3"); + Assert.That(savedBitmap.GetPixel(halfSize, halfSize), Is.EqualTo(bottomRight), test + ".2.4"); using (var bd = bmp.Lock()) { - Assert.AreEqual(topLeft, bd.GetPixel(0, 0), test + ".3.1"); - Assert.AreEqual(topRight, bd.GetPixel(halfSize, 0), test + ".3.2"); - Assert.AreEqual(bottomLeft, bd.GetPixel(0, halfSize), test + ".3.3"); - Assert.AreEqual(bottomRight, bd.GetPixel(halfSize, halfSize), test + ".3.4"); + Assert.That(bd.GetPixel(0, 0), Is.EqualTo(topLeft), test + ".3.1"); + Assert.That(bd.GetPixel(halfSize, 0), Is.EqualTo(topRight), test + ".3.2"); + Assert.That(bd.GetPixel(0, halfSize), Is.EqualTo(bottomLeft), test + ".3.3"); + Assert.That(bd.GetPixel(halfSize, halfSize), Is.EqualTo(bottomRight), test + ".3.4"); } using (var bd = savedBitmap.Lock()) { - Assert.AreEqual(topLeft, bd.GetPixel(0, 0), test + ".4.1"); - Assert.AreEqual(topRight, bd.GetPixel(halfSize, 0), test + ".4.2"); - Assert.AreEqual(bottomLeft, bd.GetPixel(0, halfSize), test + ".4.3"); - Assert.AreEqual(bottomRight, bd.GetPixel(halfSize, halfSize), test + ".4.4"); + Assert.That(bd.GetPixel(0, 0), Is.EqualTo(topLeft), test + ".4.1"); + Assert.That(bd.GetPixel(halfSize, 0), Is.EqualTo(topRight), test + ".4.2"); + Assert.That(bd.GetPixel(0, halfSize), Is.EqualTo(bottomLeft), test + ".4.3"); + Assert.That(bd.GetPixel(halfSize, halfSize), Is.EqualTo(bottomRight), test + ".4.4"); } } diff --git a/test/Eto.Test/UnitTests/Drawing/BrushTests.cs b/test/Eto.Test/UnitTests/Drawing/BrushTests.cs index d0e6bbe247..f7bca49c68 100644 --- a/test/Eto.Test/UnitTests/Drawing/BrushTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/BrushTests.cs @@ -66,15 +66,15 @@ public void LinearGradientBrushShouldFillWithRectangleAndAngle() // start out mostly blue var startPixel = bmp.GetPixel(1, 2); - Assert.LessOrEqual(startPixel.Rb, 10, "#1.1"); - Assert.LessOrEqual(startPixel.Gb, 10, "#1.2"); - Assert.GreaterOrEqual(startPixel.Bb, 10, "#1.3"); + Assert.That(startPixel.Rb, Is.LessThanOrEqualTo(10), "#1.1"); + Assert.That(startPixel.Gb, Is.LessThanOrEqualTo(10), "#1.2"); + Assert.That(startPixel.Bb, Is.GreaterThanOrEqualTo(10), "#1.3"); // end mostly green var endPixel = bmp.GetPixel(98, 99); - Assert.LessOrEqual(endPixel.Rb, 10, "#2.1"); - Assert.GreaterOrEqual(endPixel.Gb, 80, "#2.2"); - Assert.LessOrEqual(endPixel.Bb, 10, "#2.3"); + Assert.That(endPixel.Rb, Is.LessThanOrEqualTo(10), "#2.1"); + Assert.That(endPixel.Gb, Is.GreaterThanOrEqualTo(80), "#2.2"); + Assert.That(endPixel.Bb, Is.LessThanOrEqualTo(10), "#2.3"); } } diff --git a/test/Eto.Test/UnitTests/Drawing/ClipTests.cs b/test/Eto.Test/UnitTests/Drawing/ClipTests.cs index 1fb200af09..edf6c12a64 100644 --- a/test/Eto.Test/UnitTests/Drawing/ClipTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/ClipTests.cs @@ -12,8 +12,8 @@ public void ClipBoundsShouldMatchClientSize() TestBase.Paint((drawable, e) => { var graphics = e.Graphics; - Assert.AreEqual(size, drawable.ClientSize, "Drawable client size should be 300x300"); - Assert.AreEqual(Size.Round(drawable.ClientSize), Size.Round(graphics.ClipBounds.Size), "Clip bounds should match drawable client size"); + Assert.That(drawable.ClientSize, Is.EqualTo(size), "Drawable client size should be 300x300"); + Assert.That(Size.Round(graphics.ClipBounds.Size), Is.EqualTo(Size.Round(drawable.ClientSize)), "Clip bounds should match drawable client size"); }, size); } @@ -33,7 +33,7 @@ public void ClipRectangleShouldTranslate() // Check that the clip region was correctly translated var clip = graphics.ClipBounds; var expectedClip = new RectangleF(-new Point(clipTo), clipTo); - Assert.AreEqual(Rectangle.Round(expectedClip), Rectangle.Round(clip), "Clip rectangle wasn't translated properly"); + Assert.That(Rectangle.Round(clip), Is.EqualTo(Rectangle.Round(expectedClip)), "Clip rectangle wasn't translated properly"); }); } } diff --git a/test/Eto.Test/UnitTests/Drawing/ColorTests.cs b/test/Eto.Test/UnitTests/Drawing/ColorTests.cs index 87dc486ce8..2a006cda68 100644 --- a/test/Eto.Test/UnitTests/Drawing/ColorTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/ColorTests.cs @@ -17,7 +17,7 @@ public class ColorTests public void ToArgbShouldRoundtrip(int argb) { var color = Color.FromArgb(argb); - Assert.AreEqual(argb, color.ToArgb(), "Color {0} does not roundtrip", argb); + Assert.That(color.ToArgb(), Is.EqualTo(argb), $"Color {argb} does not roundtrip"); } [TestCase(unchecked((int)0xFFAABBCC))] @@ -32,8 +32,8 @@ public void ToArgbShouldRoundtrip(int argb) public void ToRgbShouldRoundtrip(int rgb) { var color = Color.FromRgb(rgb); - Assert.AreEqual(color.Ab, 255, "Alpha should be 255 when using Color.FromRgb"); - Assert.AreEqual(rgb & 0xFFFFFF, color.ToArgb() & 0xFFFFFF, "Color {0} does not roundtrip", rgb); + Assert.That(255, Is.EqualTo(color.Ab), "Alpha should be 255 when using Color.FromRgb"); + Assert.That(color.ToArgb() & 0xFFFFFF, Is.EqualTo(rgb & 0xFFFFFF), $"Color {rgb} does not roundtrip"); } [TestCase((uint)0x00000000)] @@ -50,10 +50,10 @@ public void ColorToHsbShouldNotHaveNan(uint rgb) { var color = Color.FromArgb(unchecked((int)rgb)); var hsb = color.ToHSB(); - Assert.AreNotEqual(double.NaN, hsb.A, "#1. A is NaN"); - Assert.AreNotEqual(double.NaN, hsb.H, "#2. H is NaN"); - Assert.AreNotEqual(double.NaN, hsb.S, "#3. S is NaN"); - Assert.AreNotEqual(double.NaN, hsb.B, "#4. B is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.A), "#1. A is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.H), "#2. H is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.S), "#3. S is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.B), "#4. B is NaN"); } [TestCase((uint)0x00000000)] @@ -70,10 +70,10 @@ public void ColorToHslShouldNotHaveNan(uint rgb) { var color = Color.FromArgb(unchecked((int)rgb)); var hsb = color.ToHSL(); - Assert.AreNotEqual(double.NaN, hsb.A, "#1. A is NaN"); - Assert.AreNotEqual(double.NaN, hsb.H, "#2. H is NaN"); - Assert.AreNotEqual(double.NaN, hsb.S, "#3. S is NaN"); - Assert.AreNotEqual(double.NaN, hsb.L, "#4. L is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.A), "#1. A is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.H), "#2. H is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.S), "#3. S is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.L), "#4. L is NaN"); } [TestCase((uint)0x00000000)] @@ -90,11 +90,11 @@ public void ColorToCmykShouldNotHaveNan(uint rgb) { var color = Color.FromArgb(unchecked((int)rgb)); var hsb = color.ToCMYK(); - Assert.AreNotEqual(double.NaN, hsb.A, "#1. A is NaN"); - Assert.AreNotEqual(double.NaN, hsb.C, "#2. C is NaN"); - Assert.AreNotEqual(double.NaN, hsb.M, "#3. M is NaN"); - Assert.AreNotEqual(double.NaN, hsb.Y, "#4. Y is NaN"); - Assert.AreNotEqual(double.NaN, hsb.K, "#4. K is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.A), "#1. A is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.C), "#2. C is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.M), "#3. M is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.Y), "#4. Y is NaN"); + Assert.That(double.NaN, Is.Not.EqualTo(hsb.K), "#4. K is NaN"); } [TestCase("#000", 255, 0, 0, 0)] @@ -181,12 +181,12 @@ public void ColorShouldParse(string text, int a, int r, int g, int b, ColorStyle Thread.CurrentThread.CurrentCulture = systemCulture; - Assert.IsTrue(result, "#1 - Color could not be parsed from text"); + Assert.That(result, Is.True, "#1 - Color could not be parsed from text"); - Assert.AreEqual(a, color.Ab, "#2.1 - Alpha component is incorrect"); - Assert.AreEqual(r, color.Rb, "#2.2 - Red component is incorrect"); - Assert.AreEqual(g, color.Gb, "#2.3 - Green component is incorrect"); - Assert.AreEqual(b, color.Bb, "#2.4 - Blue component is incorrect"); + Assert.That(color.Ab, Is.EqualTo(a), "#2.1 - Alpha component is incorrect"); + Assert.That(color.Rb, Is.EqualTo(r), "#2.2 - Red component is incorrect"); + Assert.That(color.Gb, Is.EqualTo(g), "#2.3 - Green component is incorrect"); + Assert.That(color.Bb, Is.EqualTo(b), "#2.4 - Blue component is incorrect"); } [TestCase("#0000", 0, 0, 0, 0, ColorStyles.ShortHex)] @@ -212,7 +212,7 @@ public void ColorToHexShouldBeCorrect(string text, int a, int r, int g, int b, C { var color = Color.FromArgb(r, g, b, a); var value = style != null ? color.ToHex(style.Value) : color.ToHex(); - Assert.AreEqual(text, value, "#1 Hex value incorrect"); + Assert.That(value, Is.EqualTo(text), "#1 Hex value incorrect"); } } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Drawing/FontTests.cs b/test/Eto.Test/UnitTests/Drawing/FontTests.cs index bbbb8f9324..8a8f03b716 100644 --- a/test/Eto.Test/UnitTests/Drawing/FontTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/FontTests.cs @@ -31,8 +31,8 @@ public void FontMeasureStringShouldWorkForMultiLineStrings() => Invoke(() => var singleLineSize = font.MeasureString("A single-line string!"); var multiLineSize = font.MeasureString("A\nmulti\nline\nstring!"); Console.WriteLine($"Single-line: {singleLineSize}, Multi-line: {multiLineSize}"); - Assert.Greater(multiLineSize.Height, singleLineSize.Height, "#1 The multi-line string does not have a greater height than the single line"); - Assert.Less(multiLineSize.Width, singleLineSize.Width, "#2 The multi-line string should not be as wide as the single line string"); + Assert.That(multiLineSize.Height, Is.GreaterThan(singleLineSize.Height), "#1 The multi-line string does not have a greater height than the single line"); + Assert.That(multiLineSize.Width, Is.LessThan(singleLineSize.Width), "#2 The multi-line string should not be as wide as the single line string"); }); } } diff --git a/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs b/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs index c4ea95841e..ebf1b9d7b1 100644 --- a/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/GraphicsPathTests.cs @@ -3,7 +3,7 @@ namespace Eto.Test.UnitTests.Drawing { [TestFixture] - public class GraphicsPathTests + public class GraphicsPathTests : TestBase { [Test, InvokeOnUI] public void GraphicsPathFillContainsShouldWork() @@ -11,15 +11,15 @@ public void GraphicsPathFillContainsShouldWork() var path = new GraphicsPath(); path.AddRectangle(0, 0, 10, 10); - Assert.IsTrue(path.FillContains(new PointF(5, 5)), "#1.1"); - Assert.IsFalse(path.FillContains(new PointF(11, 5)), "#1.2"); - Assert.IsTrue(path.FillContains(new PointF(9, 5)), "#1.3"); - Assert.IsFalse(path.FillContains(new PointF(10.5f, 5)), "#1.4"); - Assert.IsTrue(path.FillContains(new PointF(0, 0)), "#1.5"); - Assert.IsFalse(path.FillContains(new PointF(-1, 0)), "#1.6"); + Assert.That(path.FillContains(new PointF(5, 5)), Is.True, "#1.1"); + Assert.That(path.FillContains(new PointF(11, 5)), Is.False, "#1.2"); + Assert.That(path.FillContains(new PointF(9, 5)), Is.True, "#1.3"); + Assert.That(path.FillContains(new PointF(10.5f, 5)), Is.False, "#1.4"); + Assert.That(path.FillContains(new PointF(0, 0)), Is.True, "#1.5"); + Assert.That(path.FillContains(new PointF(-1, 0)), Is.False, "#1.6"); // slightly different behaviour with System.Drawing for some reason, ignore it for now. if (!Platform.Instance.IsWinForms) - Assert.IsTrue(path.FillContains(new PointF(10, 5)), "#1.7"); + Assert.That(path.FillContains(new PointF(10, 5)), Is.True, "#1.7"); } [Test, InvokeOnUI] @@ -29,10 +29,10 @@ public void GraphicsPathStrokeContainsShouldWork() path.AddRectangle(0, 0, 10, 10); var pen = new Pen(Colors.Black, 1); - Assert.IsTrue(path.StrokeContains(pen, new PointF(0, 0)), "#1.1"); - Assert.IsFalse(path.StrokeContains(pen, new PointF(1, 1)), "#1.2"); - Assert.IsTrue(path.StrokeContains(pen, new PointF(10, 1)), "#1.3"); - Assert.IsTrue(path.StrokeContains(pen, new PointF(10, 10)), "#1.4"); + Assert.That(path.StrokeContains(pen, new PointF(0, 0)), Is.True, "#1.1"); + Assert.That(path.StrokeContains(pen, new PointF(1, 1)), Is.False, "#1.2"); + Assert.That(path.StrokeContains(pen, new PointF(10, 1)), Is.True, "#1.3"); + Assert.That(path.StrokeContains(pen, new PointF(10, 10)), Is.True, "#1.4"); } } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Drawing/GraphicsTests.cs b/test/Eto.Test/UnitTests/Drawing/GraphicsTests.cs index 817b966d77..16f570d9dd 100755 --- a/test/Eto.Test/UnitTests/Drawing/GraphicsTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/GraphicsTests.cs @@ -11,9 +11,9 @@ public void DefaultValuesShouldBeCorrect() { var graphics = e.Graphics; - Assert.AreEqual(PixelOffsetMode.None, graphics.PixelOffsetMode, "PixelOffsetMode should default to None"); - Assert.AreEqual(true, graphics.AntiAlias, "AntiAlias should be true"); - Assert.AreEqual(ImageInterpolation.Default, graphics.ImageInterpolation, "ImageInterpolation should be default"); + Assert.That(graphics.PixelOffsetMode, Is.EqualTo(PixelOffsetMode.None), "PixelOffsetMode should default to None"); + Assert.That(graphics.AntiAlias, Is.EqualTo(true), "AntiAlias should be true"); + Assert.That(graphics.ImageInterpolation, Is.EqualTo(ImageInterpolation.Default), "ImageInterpolation should be default"); }); } @@ -40,10 +40,10 @@ public void AntiAliasShouldNotInterfereWithTransform() } using (var bd = bmp.Lock()) { - Assert.AreEqual(Colors.Red, bd.GetPixel(0, 0), "#1"); - Assert.AreEqual(Colors.Green, bd.GetPixel(10, 0), "#2"); - Assert.AreEqual(Colors.Blue, bd.GetPixel(20, 0), "#3"); - Assert.AreEqual(Colors.Yellow, bd.GetPixel(30, 0), "#4"); + Assert.That(bd.GetPixel(0, 0), Is.EqualTo(Colors.Red), "#1"); + Assert.That(bd.GetPixel(10, 0), Is.EqualTo(Colors.Green), "#2"); + Assert.That(bd.GetPixel(20, 0), Is.EqualTo(Colors.Blue), "#3"); + Assert.That(bd.GetPixel(30, 0), Is.EqualTo(Colors.Yellow), "#4"); } } @@ -90,23 +90,23 @@ public void ImageInterpolationShouldBeIndependent() void hasBlue(Color c) { - Assert.Greater(c.B, 0); - Assert.AreEqual(0, c.G); - Assert.AreEqual(0, c.R); + Assert.That(c.B, Is.GreaterThan(0)); + Assert.That(c.G, Is.EqualTo(0)); + Assert.That(c.R, Is.EqualTo(0)); } void hasRed(Color c) { - Assert.AreEqual(0, c.B); - Assert.AreEqual(0, c.G); - Assert.Greater(c.R, 0); + Assert.That(c.B, Is.EqualTo(0)); + Assert.That(c.G, Is.EqualTo(0)); + Assert.That(c.R, Is.GreaterThan(0)); } void hasRedAndBlue(Color c) { - Assert.Greater(c.B, 0); - Assert.AreEqual(0, c.G); - Assert.Greater(c.R, 0); + Assert.That(c.B, Is.GreaterThan(0)); + Assert.That(c.G, Is.EqualTo(0)); + Assert.That(c.R, Is.GreaterThan(0)); } void checkInterpolated(BitmapData bd, int x, int y) @@ -123,13 +123,13 @@ void checkInterpolated(BitmapData bd, int x, int y) void checkNonInterpolated(BitmapData bd, int x, int y) { - Assert.AreEqual(Colors.Blue, bd.GetPixel(x + 0, y + 0)); - Assert.AreEqual(Colors.Blue, bd.GetPixel(x + 99, y + 0)); - Assert.AreEqual(Colors.Blue, bd.GetPixel(x + 50, y + 50)); - Assert.AreEqual(Colors.Blue, bd.GetPixel(x + 50, y + 49)); - Assert.AreEqual(Colors.Blue, bd.GetPixel(x + 49, y + 49)); - Assert.AreEqual(Colors.Red, bd.GetPixel(x + 49, y + 51)); - Assert.AreEqual(Colors.Red, bd.GetPixel(x + 0, y + 99)); + Assert.That(bd.GetPixel(x + 0, y + 0), Is.EqualTo(Colors.Blue)); + Assert.That(bd.GetPixel(x + 99, y + 0), Is.EqualTo(Colors.Blue)); + Assert.That(bd.GetPixel(x + 50, y + 50), Is.EqualTo(Colors.Blue)); + Assert.That(bd.GetPixel(x + 50, y + 49), Is.EqualTo(Colors.Blue)); + Assert.That(bd.GetPixel(x + 49, y + 49), Is.EqualTo(Colors.Blue)); + Assert.That(bd.GetPixel(x + 49, y + 51), Is.EqualTo(Colors.Red)); + Assert.That(bd.GetPixel(x + 0, y + 99), Is.EqualTo(Colors.Red)); } using (var bd = bmp2.Lock()) diff --git a/test/Eto.Test/UnitTests/Drawing/IconTests.cs b/test/Eto.Test/UnitTests/Drawing/IconTests.cs index d8ab10afcd..6d5a232a81 100755 --- a/test/Eto.Test/UnitTests/Drawing/IconTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/IconTests.cs @@ -15,14 +15,14 @@ public void IconShouldSupportMultipleResolutions(float scale, float expectedResu { var icon = TestIcons.Logo; - Assert.IsNotNull(icon, "#1"); + Assert.That(icon, Is.Not.Null, "#1"); var expectedScales = new [] { 0.5f, 1f, 1.5f, 2f, 4f }; - Assert.AreEqual(expectedScales.Length, icon.Frames.Count(), "#2 - Should be a representation for each image with @"); + Assert.That(icon.Frames.Count(), Is.EqualTo(expectedScales.Length), "#2 - Should be a representation for each image with @"); - CollectionAssert.AreEqual(expectedScales, icon.Frames.Select(r => r.Scale).OrderBy(r => r), "#3 - scales weren't loaded"); + Assert.That(icon.Frames.Select(r => r.Scale).OrderBy(r => r), Is.EqualTo(expectedScales), "#3 - scales weren't loaded"); - Assert.AreEqual(expectedResult, icon.GetFrame(scale).Scale, "#4"); + Assert.That(icon.GetFrame(scale).Scale, Is.EqualTo(expectedResult), "#4"); } [Test] @@ -30,9 +30,9 @@ public void IconFromIcoShouldSetFrames() { var icon = TestIcons.TestIcon; - Assert.IsNotNull(icon, "#1"); + Assert.That(icon, Is.Not.Null, "#1"); - Assert.AreEqual(5, icon.Frames.Count(), "#2"); + Assert.That(icon.Frames.Count(), Is.EqualTo(5), "#2"); var sizes = new [] { @@ -42,9 +42,9 @@ public void IconFromIcoShouldSetFrames() new Size(64, 64), new Size(128, 128), }; - CollectionAssert.AreEquivalent(sizes, icon.Frames.Select(r => r.PixelSize), "#3"); + Assert.That(icon.Frames.Select(r => r.PixelSize), Is.EquivalentTo(sizes), "#3"); - Assert.IsTrue(icon.Frames.All(r => r.Scale == 1), "#4"); + Assert.That(icon.Frames.All(r => r.Scale == 1), Is.True, "#4"); } [TestCase(.50f, 64, null)] @@ -57,12 +57,12 @@ public void GetFrameWithScaleShouldWorkWithIco(float scale, int expectedSize, in var icon = TestIcons.TestIcon; // sanity check - Assert.IsNotNull(icon, "#1"); - Assert.AreEqual(5, icon.Frames.Count(), "#2"); - Assert.IsTrue(icon.Frames.All(r => r.Scale == 1), "#5"); + Assert.That(icon, Is.Not.Null, "#1"); + Assert.That(icon.Frames.Count(), Is.EqualTo(5), "#2"); + Assert.That(icon.Frames.All(r => r.Scale == 1), Is.True, "#5"); var fs = fittingSize != null ? (Size?)new Size(fittingSize.Value, fittingSize.Value) : null; - Assert.AreEqual(new Size(expectedSize, expectedSize), icon.GetFrame(scale, fs).PixelSize, ""); + Assert.That(icon.GetFrame(scale, fs).PixelSize, Is.EqualTo(new Size(expectedSize, expectedSize)), ""); } [TestCase("Some.File.That.Does.Not.Exist.png")] @@ -93,15 +93,15 @@ public void DrawingManyIconsShouldNotCrash() public void BitmapDpiShouldNotAffectIconSize(string resourceName, int width, int height) { var icon = Icon.FromResource(resourceName); - Assert.AreEqual(width, icon.Size.Width, "Icon width is incorrect"); - Assert.AreEqual(height, icon.Size.Height, "Icon width is incorrect"); + Assert.That(icon.Size.Width, Is.EqualTo(width), "Icon width is incorrect"); + Assert.That(icon.Size.Height, Is.EqualTo(height), "Icon width is incorrect"); int i = 0; foreach (var frame in icon.Frames) { i++; - Assert.AreEqual(width, frame.Size.Width, $"Frame #{i} with scale {frame.Scale} does not match icon width"); - Assert.AreEqual(height, frame.Size.Height, $"Frame #{i} with scale {frame.Scale} does not match icon height"); + Assert.That(frame.Size.Width, Is.EqualTo(width), $"Frame #{i} with scale {frame.Scale} does not match icon width"); + Assert.That(frame.Size.Height, Is.EqualTo(height), $"Frame #{i} with scale {frame.Scale} does not match icon height"); } } @@ -113,9 +113,9 @@ public void BitmapToIconShouldNotChangeBitmapSize() var icon = bmp.WithSize(32, 32); - Assert.AreEqual(bmp.Size, oldSize, "#1"); - Assert.AreEqual(new Size(32, 32), icon.Size, "#2"); - Assert.AreEqual(bmp.Size, icon.Frames.First().PixelSize, "#3"); + Assert.That(oldSize, Is.EqualTo(bmp.Size), "#1"); + Assert.That(icon.Size, Is.EqualTo(new Size(32, 32)), "#2"); + Assert.That(icon.Frames.First().PixelSize, Is.EqualTo(bmp.Size), "#3"); } [Test] diff --git a/test/Eto.Test/UnitTests/Drawing/MatrixTests.cs b/test/Eto.Test/UnitTests/Drawing/MatrixTests.cs index a1c51f3dc6..50e230eebf 100644 --- a/test/Eto.Test/UnitTests/Drawing/MatrixTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/MatrixTests.cs @@ -13,12 +13,6 @@ namespace Eto.Test.UnitTests.Drawing [TestFixture] public class MatrixTests { - public MatrixTests() - { - // initialize test generator if running through IDE or nunit-gui - TestBase.Initialize(); - } - public static bool Equals(IMatrix m, float xx, float yx, float xy, float yy, float x0, float y0) { var e = m.Elements; @@ -45,7 +39,7 @@ private bool AreEqual(PointF a, PointF b) public void Matrix_CreateIdentity_VerifyElements() { var m = Matrix.Create(); - Assert.IsTrue(Equals(m, 1, 0, 0, 1, 0, 0)); + Assert.That(Equals(m, 1, 0, 0, 1, 0, 0), Is.True); } [TestCase( @@ -60,7 +54,7 @@ public void Matrix_Append_Appends( var m = Matrix.Create(xx, yx, xy, yy, x0, y0); var a = Matrix.Create(XX, YX, XY, YY, X0, Y0); m.Append(a); - Assert.IsTrue(Equals(m, Xx, Yx, Xy, Yy, a0, b0)); + Assert.That(Equals(m, Xx, Yx, Xy, Yy, a0, b0), Is.True); } [TestCase( @@ -75,7 +69,7 @@ public void Matrix_Prepend_Prepends( var m = Matrix.Create(xx, yx, xy, yy, x0, y0); var a = Matrix.Create(XX, YX, XY, YY, X0, Y0); m.Prepend(a); - Assert.IsTrue(Equals(m, Xx, Yx, Xy, Yy, a0, b0)); + Assert.That(Equals(m, Xx, Yx, Xy, Yy, a0, b0), Is.True); } [TestCase( @@ -93,7 +87,7 @@ public void Matrix_Invert_Inverts( { var m = Matrix.Create(xx, yx, xy, yy, x0, y0); m.Invert(); - Assert.IsTrue(Equals(m, XX, YX, XY, YY, X0, Y0)); + Assert.That(Equals(m, XX, YX, XY, YY, X0, Y0), Is.True); } [Test] @@ -101,7 +95,7 @@ public void Matrix_Translate_Translates() { var m = Matrix.Create(); m.Translate(100, 200); - Assert.IsTrue(Equals(m, 1, 0, 0, 1, 100, 200)); + Assert.That(Equals(m, 1, 0, 0, 1, 100, 200), Is.True); } [TestCase( @@ -113,7 +107,7 @@ public void Matrix_Rotate_Rotates( { var m = Matrix.Create(xx, yx, xy, yy, x0, y0); m.Rotate(degrees); - Assert.IsTrue(Equals(m, XX, YX, XY, YY, X0, Y0)); + Assert.That(Equals(m, XX, YX, XY, YY, X0, Y0), Is.True); } [TestCase( @@ -125,7 +119,7 @@ public void Matrix_Scale_Scales( { var m = Matrix.Create(xx, yx, xy, yy, x0, y0); m.Scale(sx, sy); - Assert.IsTrue(Equals(m, XX, YX, XY, YY, X0, Y0)); + Assert.That(Equals(m, XX, YX, XY, YY, X0, Y0), Is.True); } @@ -138,7 +132,7 @@ public void Matrix_TransformPoint_TransformsPoint( { var m = Matrix.Create(xx, yx, xy, yy, x0, y0); var p = m.TransformPoint(new PointF(x, y)); - Assert.IsTrue(AreEqual(new PointF(X, Y), p)); + Assert.That(AreEqual(new PointF(X, Y), p), Is.True); } } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Drawing/PenTests.cs b/test/Eto.Test/UnitTests/Drawing/PenTests.cs index f29a376976..8368db356e 100644 --- a/test/Eto.Test/UnitTests/Drawing/PenTests.cs +++ b/test/Eto.Test/UnitTests/Drawing/PenTests.cs @@ -11,14 +11,14 @@ public class PenTests : TestBase public void PenShouldReturnBrush() { var pen = new Pen(Colors.Blue); - Assert.IsNotNull(pen.Brush, "#1.1"); - Assert.IsInstanceOf(pen.Brush, "#1.2"); - Assert.AreEqual(Colors.Blue, ((SolidBrush)pen.Brush).Color, "#1.3"); + Assert.That(pen.Brush, Is.Not.Null, "#1.1"); + Assert.That(pen.Brush, Is.InstanceOf()); + Assert.That(((SolidBrush)pen.Brush).Color, Is.EqualTo(Colors.Blue), "#1.3"); var brush = new SolidBrush(Colors.Blue); pen = new Pen(brush); - Assert.IsNotNull(pen.Brush, "#2.1"); - Assert.AreSame(brush, pen.Brush, "#2.2"); + Assert.That(pen.Brush, Is.Not.Null, "#2.1"); + Assert.That(brush, Is.SameAs(pen.Brush), "#2.2"); } } } diff --git a/test/Eto.Test/UnitTests/Forms/ApplicationTests.cs b/test/Eto.Test/UnitTests/Forms/ApplicationTests.cs index 05fcbc0615..4cad1cd871 100755 --- a/test/Eto.Test/UnitTests/Forms/ApplicationTests.cs +++ b/test/Eto.Test/UnitTests/Forms/ApplicationTests.cs @@ -84,7 +84,7 @@ public void RunIterationShouldAllowBlocking(int delay) form.Close(); }); - Assert.IsTrue(stopClicked, "#1 - Must press the stop button to close the form"); + Assert.That(stopClicked, Is.True, "#1 - Must press the stop button to close the form"); } [Test] diff --git a/test/Eto.Test/UnitTests/Forms/Behaviors/MouseTests.cs b/test/Eto.Test/UnitTests/Forms/Behaviors/MouseTests.cs index 61d03fdfe7..caeceaa99d 100644 --- a/test/Eto.Test/UnitTests/Forms/Behaviors/MouseTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Behaviors/MouseTests.cs @@ -78,10 +78,10 @@ public void EventsFromParentShouldWorkWhenChildRemoved() }, allowPass: false); - Assert.IsTrue(mouseUpCalled, "#1 - MouseUp was not called on top control"); - Assert.IsTrue(contentRemoved, "#2 - Content (blue square) was not removed"); - Assert.IsTrue(mouseDownInChild, "#3 - MouseUp should NOT be called on child even though it was removed"); - Assert.IsFalse(mouseMovedEvenAfterRemoved, "#4 - MouseMoved should NOT be called on child after it was removed"); + Assert.That(mouseUpCalled, Is.True, "#1 - MouseUp was not called on top control"); + Assert.That(contentRemoved, Is.True, "#2 - Content (blue square) was not removed"); + Assert.That(mouseDownInChild, Is.True, "#3 - MouseUp should NOT be called on child even though it was removed"); + Assert.That(mouseMovedEvenAfterRemoved, Is.False, "#4 - MouseMoved should NOT be called on child after it was removed"); } [Test, ManualTest] @@ -277,12 +277,12 @@ public void MouseShouldBeCapturedByOtherControl() form.Shown += (sender, e) => panel1.Focus(); return layout; }); - Assert.IsTrue(wasCaptured, "#1 - Mouse was not able to be captured"); - Assert.IsTrue(isMouseCaptured, "#2 - Control.IsMouseCaptured should be true after CaptureMouse() is successful"); - Assert.IsTrue(parent2ShouldBeEntered, "#3 - Parent2 should be entered when mouse is captured on Panel2"); - Assert.IsTrue(parent1ShouldNotBeEntered, "#4 - Parent1 should not be entered when mouse is captured on Panel2"); - Assert.IsFalse(panel1ShouldNeverBeCaptured, "#5 - Panel2 should never be captured"); - Assert.IsFalse(panel2ShouldNeverHaveMouseMoveWithoutCapturing, "#6 - Panel2 should not have a MouseMove with a button down without being captured"); + Assert.That(wasCaptured, Is.True, "#1 - Mouse was not able to be captured"); + Assert.That(isMouseCaptured, Is.True, "#2 - Control.IsMouseCaptured should be true after CaptureMouse() is successful"); + Assert.That(parent2ShouldBeEntered, Is.True, "#3 - Parent2 should be entered when mouse is captured on Panel2"); + Assert.That(parent1ShouldNotBeEntered, Is.True, "#4 - Parent1 should not be entered when mouse is captured on Panel2"); + Assert.That(panel1ShouldNeverBeCaptured, Is.False, "#5 - Panel2 should never be captured"); + Assert.That(panel2ShouldNeverHaveMouseMoveWithoutCapturing, Is.False, "#6 - Panel2 should not have a MouseMove with a button down without being captured"); } } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Forms/Bindings/ChildBindingTests.cs b/test/Eto.Test/UnitTests/Forms/Bindings/ChildBindingTests.cs index ecfa0b417f..fcaba5ed95 100644 --- a/test/Eto.Test/UnitTests/Forms/Bindings/ChildBindingTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Bindings/ChildBindingTests.cs @@ -48,7 +48,7 @@ public void IndirectBindingStructPropertiesShouldWork() Color = Colors.White }; binding.SetValue(item, 0.5f); - Assert.AreEqual(0.5f, item.Color.B, "Struct property value was not set"); + Assert.That(item.Color.B, Is.EqualTo(0.5f), "Struct property value was not set"); } [Test] @@ -63,7 +63,7 @@ public void DirectBindingStructPropertiesShouldWork() var childBinding = binding.Child(Binding.Property((Color c) => c.B)); childBinding.DataValue = 0.5f; - Assert.AreEqual(0.5f, item.Color.B, "Struct property value was not set"); + Assert.That(item.Color.B, Is.EqualTo(0.5f), "Struct property value was not set"); } [Test] @@ -83,15 +83,15 @@ public void AddingMultipleChangeHandlersForIndirectBindingsShouldWork() item.Child.Color = Colors.Green; - Assert.AreEqual(1, valueChange1Count, "#1.1"); - Assert.AreEqual(1, valueChange2Count, "#1.2"); + Assert.That(valueChange1Count, Is.EqualTo(1), "#1.1"); + Assert.That(valueChange2Count, Is.EqualTo(1), "#1.2"); // setting the child to something else should re-wire all the value changed bindings to the new instance // .. and trigger the value changed item.Child = new TestObject { Color = Colors.Blue }; - Assert.AreEqual(2, valueChange1Count, "#2.1"); - Assert.AreEqual(2, valueChange2Count, "#2.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#2.1"); + Assert.That(valueChange2Count, Is.EqualTo(2), "#2.2"); // remove the first handler and ensure the second one is still active childBinding.RemoveValueChangedHandler(changed1, ValueChanged1); @@ -99,13 +99,13 @@ public void AddingMultipleChangeHandlersForIndirectBindingsShouldWork() item.Child.Color = Colors.Yellow; // only hooked up to the second handler - Assert.AreEqual(2, valueChange1Count, "#3.1"); - Assert.AreEqual(3, valueChange2Count, "#3.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#3.1"); + Assert.That(valueChange2Count, Is.EqualTo(3), "#3.2"); item.Child = new TestObject { Color = Colors.White }; - Assert.AreEqual(2, valueChange1Count, "#4.1"); - Assert.AreEqual(4, valueChange2Count, "#4.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#4.1"); + Assert.That(valueChange2Count, Is.EqualTo(4), "#4.2"); childBinding.RemoveValueChangedHandler(changed2, ValueChanged2); @@ -113,8 +113,8 @@ public void AddingMultipleChangeHandlersForIndirectBindingsShouldWork() item.Child = new TestObject { Color = Colors.Wheat }; // no changes as nothing should be hooked up - Assert.AreEqual(2, valueChange1Count, "#5.1"); - Assert.AreEqual(4, valueChange2Count, "#5.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#5.1"); + Assert.That(valueChange2Count, Is.EqualTo(4), "#5.2"); } @@ -135,15 +135,15 @@ public void AddingMultipleChangeHandlersForDirectBindingsShouldWork() item.Child.Color = Colors.Green; - Assert.AreEqual(1, valueChange1Count, "#1.1"); - Assert.AreEqual(1, valueChange2Count, "#1.2"); + Assert.That(valueChange1Count, Is.EqualTo(1), "#1.1"); + Assert.That(valueChange2Count, Is.EqualTo(1), "#1.2"); // setting the child to something else should re-wire all the value changed bindings to the new instance // .. and trigger the value changed item.Child = new TestObject { Color = Colors.Blue }; - Assert.AreEqual(2, valueChange1Count, "#2.1"); - Assert.AreEqual(2, valueChange2Count, "#2.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#2.1"); + Assert.That(valueChange2Count, Is.EqualTo(2), "#2.2"); // remove the first handler and ensure the second one is still active childBinding.DataValueChanged -= ValueChanged1; @@ -151,13 +151,13 @@ public void AddingMultipleChangeHandlersForDirectBindingsShouldWork() item.Child.Color = Colors.Yellow; // only hooked up to the second handler - Assert.AreEqual(2, valueChange1Count, "#3.1"); - Assert.AreEqual(3, valueChange2Count, "#3.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#3.1"); + Assert.That(valueChange2Count, Is.EqualTo(3), "#3.2"); item.Child = new TestObject { Color = Colors.White }; - Assert.AreEqual(2, valueChange1Count, "#4.1"); - Assert.AreEqual(4, valueChange2Count, "#4.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#4.1"); + Assert.That(valueChange2Count, Is.EqualTo(4), "#4.2"); childBinding.DataValueChanged -= ValueChanged2; @@ -165,8 +165,8 @@ public void AddingMultipleChangeHandlersForDirectBindingsShouldWork() item.Child = new TestObject { Color = Colors.Wheat }; // no changes as nothing should be hooked up - Assert.AreEqual(2, valueChange1Count, "#5.1"); - Assert.AreEqual(4, valueChange2Count, "#5.2"); + Assert.That(valueChange1Count, Is.EqualTo(2), "#5.1"); + Assert.That(valueChange2Count, Is.EqualTo(4), "#5.2"); } } diff --git a/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingChangedTests.cs b/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingChangedTests.cs index 5df2724a2d..4a67438dc4 100644 --- a/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingChangedTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingChangedTests.cs @@ -114,11 +114,11 @@ public void BoolPropertyShouldUpdate() { var bindObject = new BindObject { BoolProperty = true }; var binding = new ObjectBinding(bindObject, "BoolProperty"); - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = false; - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = true; - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -126,9 +126,9 @@ public void IntPropertyShouldUpdate() { var bindObject = new BindObject { IntProperty = 0 }; var binding = new ObjectBinding(bindObject, "IntProperty"); - Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value"); + Assert.That(bindObject.IntProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = 1; - Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value"); + Assert.That(bindObject.IntProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -136,9 +136,9 @@ public void DoublePropertyShouldUpdate() { var bindObject = new BindObject { DoubleProperty = 0 }; var binding = new ObjectBinding(bindObject, "DoubleProperty"); - Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value"); + Assert.That(bindObject.DoubleProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = 1.2; - Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value"); + Assert.That(bindObject.DoubleProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -146,11 +146,11 @@ public void StringPropertyShouldUpdate() { var bindObject = new BindObject { StringProperty = "Initial Value" }; var binding = new ObjectBinding(bindObject, "StringProperty"); - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = "Other Value"; - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); binding.DataValue = null; - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } } } diff --git a/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingObjectChangedTests.cs b/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingObjectChangedTests.cs index 4ab149b90c..7d11e20d4d 100644 --- a/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingObjectChangedTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Bindings/ObjectBindingObjectChangedTests.cs @@ -9,11 +9,11 @@ public void BoolPropertyShouldUpdate() { var bindObject = new BindObject { BoolProperty = true }; var binding = new ObjectBinding(bindObject, "BoolProperty"); - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.BoolProperty = false; - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.BoolProperty = true; - Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value"); + Assert.That(bindObject.BoolProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -21,9 +21,9 @@ public void IntPropertyShouldUpdate() { var bindObject = new BindObject { IntProperty = 0 }; var binding = new ObjectBinding(bindObject, "IntProperty"); - Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value"); + Assert.That(bindObject.IntProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.IntProperty = 1; - Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value"); + Assert.That(bindObject.IntProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -31,9 +31,9 @@ public void DoublePropertyShouldUpdate() { var bindObject = new BindObject { DoubleProperty = 0 }; var binding = new ObjectBinding(bindObject, "DoubleProperty"); - Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value"); + Assert.That(bindObject.DoubleProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.DoubleProperty = 1.2; - Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value"); + Assert.That(bindObject.DoubleProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } [Test] @@ -41,11 +41,11 @@ public void StringPropertyShouldUpdate() { var bindObject = new BindObject { StringProperty = "Initial Value" }; var binding = new ObjectBinding(bindObject, "StringProperty"); - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.StringProperty = "Other Value"; - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); bindObject.StringProperty = null; - Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value"); + Assert.That(bindObject.StringProperty, Is.EqualTo(binding.DataValue), "Data value should equal object value"); } } } diff --git a/test/Eto.Test/UnitTests/Forms/Bindings/PropertyBindingTests.cs b/test/Eto.Test/UnitTests/Forms/Bindings/PropertyBindingTests.cs index 32e3b9e4fe..668900e967 100644 --- a/test/Eto.Test/UnitTests/Forms/Bindings/PropertyBindingTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Bindings/PropertyBindingTests.cs @@ -14,16 +14,16 @@ public void BindingWithNameShouldUpdateProperly() int changed = 0; binding.AddValueChangedHandler(item, (sender, e) => changed++); - Assert.AreEqual(0, changed); - Assert.AreEqual(0, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(0)); + Assert.That(binding.GetValue(item), Is.EqualTo(0)); item.IntProperty = 2; - Assert.AreEqual(1, changed); - Assert.AreEqual(2, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(1)); + Assert.That(binding.GetValue(item), Is.EqualTo(2)); item.IntProperty = 4; - Assert.AreEqual(2, changed); - Assert.AreEqual(4, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(2)); + Assert.That(binding.GetValue(item), Is.EqualTo(4)); } [Test] @@ -38,20 +38,20 @@ public void ChildBindingShouldUpdateProperly() BindObject oldChild; item.ChildBindObject = oldChild = new BindObject(); - Assert.AreEqual(1, changed); - Assert.AreEqual(0, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(1)); + Assert.That(binding.GetValue(item), Is.EqualTo(0)); item.ChildBindObject.IntProperty = 2; - Assert.AreEqual(2, changed); - Assert.AreEqual(2, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(2)); + Assert.That(binding.GetValue(item), Is.EqualTo(2)); item.ChildBindObject = new BindObject { IntProperty = 3 }; - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); oldChild.IntProperty = 4; // we should not be hooked into change events of the old child, since we have a new one now! - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); } [Test] @@ -66,20 +66,20 @@ public void ChildBindingWithExpressionShouldUpdateProperly() BindObject oldChild; item.ChildBindObject = oldChild = new BindObject(); - Assert.AreEqual(1, changed); - Assert.AreEqual(0, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(1)); + Assert.That(binding.GetValue(item), Is.EqualTo(0)); item.ChildBindObject.IntProperty = 2; - Assert.AreEqual(2, changed); - Assert.AreEqual(2, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(2)); + Assert.That(binding.GetValue(item), Is.EqualTo(2)); item.ChildBindObject = new BindObject { IntProperty = 3 }; - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); oldChild.IntProperty = 4; // we should not be hooked into change events of the old child, since we have a new one now! - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); } [Test] @@ -94,20 +94,20 @@ public void ChildBindingWithNameShouldUpdateProperly() BindObject oldChild; item.ChildBindObject = oldChild = new BindObject(); - Assert.AreEqual(1, changed); - Assert.AreEqual(0, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(1)); + Assert.That(binding.GetValue(item), Is.EqualTo(0)); item.ChildBindObject.IntProperty = 2; - Assert.AreEqual(2, changed); - Assert.AreEqual(2, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(2)); + Assert.That(binding.GetValue(item), Is.EqualTo(2)); item.ChildBindObject = new BindObject { IntProperty = 3 }; - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); oldChild.IntProperty = 4; // we should not be hooked into change events of the old child, since we have a new one now! - Assert.AreEqual(3, changed); - Assert.AreEqual(3, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(3)); + Assert.That(binding.GetValue(item), Is.EqualTo(3)); } [Test] @@ -120,8 +120,8 @@ public void NonExistantPropertyShouldNotCrash() EventHandler valueChanged = (sender, e) => changed++; var changeReference = binding.AddValueChangedHandler(item, valueChanged); - Assert.AreEqual(0, changed); - Assert.AreEqual(null, binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(0)); + Assert.That(binding.GetValue(item), Is.EqualTo(null)); Assert.DoesNotThrow(() => binding.SetValue(item, 123)); binding.RemoveValueChangedHandler(changeReference, valueChanged); } @@ -136,11 +136,11 @@ public void InternalPropertyShouldBeAccessible() EventHandler valueChanged = (sender, e) => changed++; var changeReference = binding.AddValueChangedHandler(item, valueChanged); - Assert.AreEqual(0, changed); - Assert.AreEqual("some value", binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(0)); + Assert.That(binding.GetValue(item), Is.EqualTo("some value")); Assert.DoesNotThrow(() => binding.SetValue(item, "some other value")); - Assert.AreEqual(1, changed); - Assert.AreEqual("some other value", binding.GetValue(item)); + Assert.That(changed, Is.EqualTo(1)); + Assert.That(binding.GetValue(item), Is.EqualTo("some other value")); binding.RemoveValueChangedHandler(changeReference, valueChanged); } @@ -228,22 +228,22 @@ public void PropertyBindingsShouldUseDescriptors() var invalidBinding = Eto.Forms.Binding.Property("ThirdInvalidProperty"); var propertyInfoBinding = Eto.Forms.Binding.Property("NonTypeDescriptorProperty"); - Assert.AreEqual("Initial Value", stringBinding.GetValue(item)); + Assert.That(stringBinding.GetValue(item), Is.EqualTo("Initial Value")); stringBinding.SetValue(item, "Some Value"); - Assert.AreEqual("Some Value", stringBinding.GetValue(item)); + Assert.That(stringBinding.GetValue(item), Is.EqualTo("Some Value")); - Assert.AreEqual(true, boolBinding.GetValue(item)); + Assert.That(boolBinding.GetValue(item), Is.EqualTo(true)); boolBinding.SetValue(item, false); - Assert.AreEqual(false, boolBinding.GetValue(item)); + Assert.That(boolBinding.GetValue(item), Is.EqualTo(false)); - Assert.IsNull(invalidBinding.GetValue(item)); + Assert.That(invalidBinding.GetValue(item), Is.Null); invalidBinding.SetValue(item, "something"); - Assert.IsNull(invalidBinding.GetValue(item)); + Assert.That(invalidBinding.GetValue(item), Is.Null); // ensure properties can also be accessed without descriptors - Assert.AreEqual("Initial Other Value", propertyInfoBinding.GetValue(item)); + Assert.That(propertyInfoBinding.GetValue(item), Is.EqualTo("Initial Other Value")); propertyInfoBinding.SetValue(item, "Some Other Value"); - Assert.AreEqual("Some Other Value", propertyInfoBinding.GetValue(item)); + Assert.That(propertyInfoBinding.GetValue(item), Is.EqualTo("Some Other Value")); } } } diff --git a/test/Eto.Test/UnitTests/Forms/CascadingStyleTests.cs b/test/Eto.Test/UnitTests/Forms/CascadingStyleTests.cs index 473874f0b2..9a4575c149 100644 --- a/test/Eto.Test/UnitTests/Forms/CascadingStyleTests.cs +++ b/test/Eto.Test/UnitTests/Forms/CascadingStyleTests.cs @@ -14,11 +14,11 @@ public void DefaultStyleShouldApplyFromContainer() var child = new Label(); container.Content = child; - Assert.IsTrue(child.Visible); + Assert.That(child.Visible, Is.True); container.AttachNative(); // trigger load to apply styles - Assert.IsFalse(child.Visible); + Assert.That(child.Visible, Is.False); } [Test, InvokeOnUI] @@ -30,14 +30,14 @@ public void StyleShouldApplyFromContainer() var child = new Label(); container.Content = child; - Assert.IsTrue(child.Visible); + Assert.That(child.Visible, Is.True); container.AttachNative(); // trigger load to apply styles - Assert.IsTrue(child.Visible); + Assert.That(child.Visible, Is.True); child.Style = "style"; - Assert.IsFalse(child.Visible); + Assert.That(child.Visible, Is.False); } [Test, InvokeOnUI] @@ -52,22 +52,22 @@ public void StyleShouldApplyFromParentToChildOrder() var child = new Label(); container2.Content = child; - Assert.AreEqual(VerticalAlignment.Top, child.VerticalAlignment); + Assert.That(child.VerticalAlignment, Is.EqualTo(VerticalAlignment.Top)); container1.AttachNative(); // trigger load to apply styles // container1 style applies - Assert.AreEqual(VerticalAlignment.Bottom, child.VerticalAlignment); + Assert.That(child.VerticalAlignment, Is.EqualTo(VerticalAlignment.Bottom)); child.Style = "style"; // container2 style now applies - Assert.AreEqual(VerticalAlignment.Center, child.VerticalAlignment); + Assert.That(child.VerticalAlignment, Is.EqualTo(VerticalAlignment.Center)); child.Style = null; // container1 style now applies again - Assert.AreEqual(VerticalAlignment.Bottom, child.VerticalAlignment); + Assert.That(child.VerticalAlignment, Is.EqualTo(VerticalAlignment.Bottom)); } [Test, InvokeOnUI] @@ -81,11 +81,11 @@ public void StyleShouldApplyWhenControlDynamicallyAdded() var child = new Label(); child.Style = "style"; - Assert.IsTrue(child.Visible); + Assert.That(child.Visible, Is.True); container.Content = child; // styles apply now that it is a child of the container - Assert.IsFalse(child.Visible); + Assert.That(child.Visible, Is.False); } [Test, InvokeOnUI] @@ -98,11 +98,11 @@ public void DefaultStyleShouldApplyWhenControlDynamicallyAdded() container.AttachNative(); var child = new Label(); - Assert.IsTrue(child.Visible); + Assert.That(child.Visible, Is.True); container.Content = child; // styles apply now that it is a child of the container - Assert.IsFalse(child.Visible); + Assert.That(child.Visible, Is.False); } } } diff --git a/test/Eto.Test/UnitTests/Forms/ClipboardTests.cs b/test/Eto.Test/UnitTests/Forms/ClipboardTests.cs index b76fd81f53..c353eda013 100755 --- a/test/Eto.Test/UnitTests/Forms/ClipboardTests.cs +++ b/test/Eto.Test/UnitTests/Forms/ClipboardTests.cs @@ -29,7 +29,7 @@ public void GettingAndSettingTextShouldNotCrash() var clipboard = new T(); var val = "Hello" + i; clipboard.Text = val; - Assert.AreEqual(val, clipboard.Text); + Assert.That(clipboard.Text, Is.EqualTo(val)); } }); } @@ -123,41 +123,41 @@ void TestIsNull(T dataObject, DataType type) switch (type) { case DataType.Text: - Assert.IsFalse(dataObject.ContainsText); - Assert.IsNull(dataObject.Text); + Assert.That(dataObject.ContainsText, Is.False); + Assert.That(dataObject.Text, Is.Null); break; case DataType.Html: - Assert.IsFalse(dataObject.ContainsHtml); - Assert.IsNull(dataObject.Html); + Assert.That(dataObject.ContainsHtml, Is.False); + Assert.That(dataObject.Html, Is.Null); break; //case DataType.Icon: case DataType.Bitmap: - Assert.IsFalse(dataObject.ContainsImage); - Assert.IsNull(dataObject.Image); + Assert.That(dataObject.ContainsImage, Is.False); + Assert.That(dataObject.Image, Is.Null); break; case DataType.String: - CollectionAssert.DoesNotContain(SampleStringType, dataObject.Types); - Assert.IsNull(dataObject.GetString(SampleStringType)); + Assert.That(dataObject.Types, Does.Not.Contain(SampleStringType)); + Assert.That(dataObject.GetString(SampleStringType), Is.Null); break; case DataType.Data: - CollectionAssert.DoesNotContain(SampleDataType, dataObject.Types); - Assert.IsNull(dataObject.GetData(SampleDataType)); + Assert.That(dataObject.Types, Does.Not.Contain(SampleDataType)); + Assert.That(dataObject.GetData(SampleDataType), Is.Null); break; case DataType.Uris: - Assert.IsFalse(dataObject.ContainsUris); - Assert.IsNull(dataObject.Uris); + Assert.That(dataObject.ContainsUris, Is.False); + Assert.That(dataObject.Uris, Is.Null); break; case DataType.SerializableObject: - CollectionAssert.DoesNotContain(SampleSerializableObjectType, dataObject.Types); - Assert.IsNull(dataObject.GetObject(SampleSerializableObjectType)); + Assert.That(dataObject.Types, Does.Not.Contain(SampleSerializableObjectType)); + Assert.That(dataObject.GetObject(SampleSerializableObjectType), Is.Null); break; case DataType.NormalObject: - CollectionAssert.DoesNotContain(SampleObjectType, dataObject.Types); - Assert.IsNull(dataObject.GetObject(SampleObjectType)); + Assert.That(dataObject.Types, Does.Not.Contain(SampleObjectType)); + Assert.That(dataObject.GetObject(SampleObjectType), Is.Null); break; case DataType.UnsafeObject: - CollectionAssert.DoesNotContain(SampleUnsafeObjectType, dataObject.Types); - Assert.IsNull(dataObject.GetObject(SampleUnsafeObjectType)); + Assert.That(dataObject.Types, Does.Not.Contain(SampleUnsafeObjectType)); + Assert.That(dataObject.GetObject(SampleUnsafeObjectType), Is.Null); break; default: throw new NotSupportedException(); @@ -175,57 +175,57 @@ void TestValue(T dataObject, DataType type) switch (type) { case DataType.Text: - Assert.IsTrue(dataObject.ContainsText); - Assert.IsNotNull(dataObject.Text); - Assert.AreEqual(SampleText, dataObject.Text); + Assert.That(dataObject.ContainsText, Is.True); + Assert.That(dataObject.Text, Is.Not.Null); + Assert.That(dataObject.Text, Is.EqualTo(SampleText)); break; case DataType.Html: - Assert.IsTrue(dataObject.ContainsHtml); - Assert.IsNotNull(dataObject.Html); - Assert.AreEqual(SampleHtml, dataObject.Html); + Assert.That(dataObject.ContainsHtml, Is.True); + Assert.That(dataObject.Html, Is.Not.Null); + Assert.That(dataObject.Html, Is.EqualTo(SampleHtml)); break; //case DataType.Icon: - //Assert.IsNotNull(dataObject.Image); + //Assert.That(dataObject.Image, Is.Not.Null); //break; case DataType.Bitmap: - Assert.IsTrue(dataObject.ContainsImage); - Assert.IsNotNull(dataObject.Image); + Assert.That(dataObject.ContainsImage, Is.True); + Assert.That(dataObject.Image, Is.Not.Null); break; case DataType.String: - Assert.Contains(SampleStringType, dataObject.Types); - Assert.IsNotNull(dataObject.GetString(SampleStringType)); - Assert.AreEqual(SampleText, dataObject.GetString(SampleStringType)); + Assert.That(dataObject.Types, Contains.Item(SampleStringType)); + Assert.That(dataObject.GetString(SampleStringType), Is.Not.Null); + Assert.That(dataObject.GetString(SampleStringType), Is.EqualTo(SampleText)); break; case DataType.Data: - Assert.Contains(SampleDataType, dataObject.Types); - Assert.IsNotNull(dataObject.GetData(SampleDataType)); - Assert.AreEqual(SampleByteData, dataObject.GetData(SampleDataType)); + Assert.That(dataObject.Types, Contains.Item(SampleDataType)); + Assert.That(dataObject.GetData(SampleDataType), Is.Not.Null); + Assert.That(dataObject.GetData(SampleDataType), Is.EqualTo(SampleByteData)); break; case DataType.Uris: - Assert.IsTrue(dataObject.ContainsUris); - Assert.IsNotNull(dataObject.Uris); + Assert.That(dataObject.ContainsUris, Is.True); + Assert.That(dataObject.Uris, Is.Not.Null); if (Platform.Instance.IsGtk && EtoEnvironment.Platform.IsMac && dataObject.Uris.Length != SampleBothUris.Length) Assert.Warn("Gtk on macOS only returns a single URI for some reason."); else - CollectionAssert.AreEquivalent(SampleBothUris, dataObject.Uris); + Assert.That(dataObject.Uris, Is.EquivalentTo(SampleBothUris)); break; case DataType.SerializableObject: - Assert.Contains(SampleSerializableObjectType, dataObject.Types); + Assert.That(dataObject.Types, Contains.Item(SampleSerializableObjectType)); var obj = dataObject.GetObject(SampleSerializableObjectType); - Assert.IsNotNull(obj); - Assert.AreEqual(obj.SomeValue, SampleText); + Assert.That(obj, Is.Not.Null); + Assert.That(SampleText, Is.EqualTo(obj.SomeValue)); break; case DataType.NormalObject: - Assert.Contains(SampleObjectType, dataObject.Types); + Assert.That(dataObject.Types, Contains.Item(SampleObjectType)); var obj2 = dataObject.GetObject(SampleObjectType); - Assert.IsNotNull(obj2); - Assert.AreEqual(obj2.SomeValue, SampleText); + Assert.That(obj2, Is.Not.Null); + Assert.That(SampleText, Is.EqualTo(obj2.SomeValue)); break; case DataType.UnsafeObject: - Assert.Contains(SampleUnsafeObjectType, dataObject.Types); + Assert.That(dataObject.Types, Contains.Item(SampleUnsafeObjectType)); var obj3 = dataObject.GetObject(SampleUnsafeObjectType) as SomeOtherObject; - Assert.IsNotNull(obj3); - Assert.AreEqual(obj3.SomeValue, SampleText); + Assert.That(obj3, Is.Not.Null); + Assert.That(SampleText, Is.EqualTo(obj3.SomeValue)); break; default: throw new NotSupportedException(); @@ -368,13 +368,13 @@ public void SettingMultipleFormatsShouldWork() using (var clipboard = new T()) { TestIsNullExcept(clipboard); - CollectionAssert.DoesNotContain("eto-woot", clipboard.Types); - CollectionAssert.DoesNotContain("eto-byte-data", clipboard.Types); - Assert.AreEqual(null, clipboard.Text); - Assert.AreEqual(null, clipboard.Html); - Assert.AreEqual(null, clipboard.Image); - Assert.AreEqual(null, clipboard.GetString("eto-woot")); - Assert.AreEqual(null, clipboard.GetData("eto-byte-data")); + Assert.That(clipboard.Types, Does.Not.Contain("eto-woot")); + Assert.That(clipboard.Types, Does.Not.Contain("eto-byte-data")); + Assert.That(clipboard.Text, Is.EqualTo(null)); + Assert.That(clipboard.Html, Is.EqualTo(null)); + Assert.That(clipboard.Image, Is.EqualTo(null)); + Assert.That(clipboard.GetString("eto-woot"), Is.EqualTo(null)); + Assert.That(clipboard.GetData("eto-byte-data"), Is.EqualTo(null)); } }); } diff --git a/test/Eto.Test/UnitTests/Forms/ContainerTests.cs b/test/Eto.Test/UnitTests/Forms/ContainerTests.cs index 1cd0fc28cd..7d35ea0e98 100644 --- a/test/Eto.Test/UnitTests/Forms/ContainerTests.cs +++ b/test/Eto.Test/UnitTests/Forms/ContainerTests.cs @@ -13,7 +13,7 @@ public void PanelPaddingShouldWork(IContainerTypeInfo type) form => { var panel = type.CreateControl(); - Assert.IsNotNull(panel); + Assert.That(panel, Is.Not.Null); panel.Padding = 40; panel.Content = new Panel @@ -33,7 +33,7 @@ public void PanelPaddingBottomRightShouldWork(IContainerTypeInfo type) form => { var panel = type.CreateControl(); - Assert.IsNotNull(panel); + Assert.That(panel, Is.Not.Null); panel.Padding = new Padding(0, 0, 40, 40); panel.Content = new Panel @@ -80,34 +80,34 @@ public void EnabledShouldAffectChildControls(IContainerTypeInfo conta enabledChild.Enabled = true; // default values - Assert.IsTrue(container.Enabled, "#1.1"); - Assert.IsTrue(enabledChild.Enabled, "#1.2"); - Assert.IsFalse(disabledChild.Enabled, "#1.3"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#1.4"); + Assert.That(container.Enabled, Is.True, "#1.1"); + Assert.That(enabledChild.Enabled, Is.True, "#1.2"); + Assert.That(disabledChild.Enabled, Is.False, "#1.3"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#1.4"); // setting container to disabled container.Enabled = false; - Assert.IsFalse(container.Enabled, "#2.1"); - Assert.IsFalse(enabledChild.Enabled, "#2.2"); - Assert.IsFalse(disabledChild.Enabled, "#2.3"); - Assert.IsFalse(neutralChild.Enabled, "#2.4"); + Assert.That(container.Enabled, Is.False, "#2.1"); + Assert.That(enabledChild.Enabled, Is.False, "#2.2"); + Assert.That(disabledChild.Enabled, Is.False, "#2.3"); + Assert.That(neutralChild.Enabled, Is.False, "#2.4"); // set child to enabled when parent is disabled, should still stay disabled enabledChild.Enabled = true; - Assert.IsFalse(container.Enabled, "#3.1"); - Assert.IsFalse(enabledChild.Enabled, "#3.2"); - Assert.IsFalse(disabledChild.Enabled, "#3.3"); - Assert.IsFalse(neutralChild.Enabled, "#3.4"); + Assert.That(container.Enabled, Is.False, "#3.1"); + Assert.That(enabledChild.Enabled, Is.False, "#3.2"); + Assert.That(disabledChild.Enabled, Is.False, "#3.3"); + Assert.That(neutralChild.Enabled, Is.False, "#3.4"); // set container back to enabled container.Enabled = true; - Assert.IsTrue(container.Enabled, "#4.1"); - Assert.IsTrue(enabledChild.Enabled, "#4.2"); - Assert.IsFalse(disabledChild.Enabled, "#4.3"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#4.4"); + Assert.That(container.Enabled, Is.True, "#4.1"); + Assert.That(enabledChild.Enabled, Is.True, "#4.2"); + Assert.That(disabledChild.Enabled, Is.False, "#4.3"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#4.4"); }); } @@ -139,18 +139,18 @@ public void EnabledShouldAffectChildControlsWhenDynamicallyAdded(IContainerTypeI enabledChild.Enabled = true; // default values - Assert.IsTrue(container.Enabled, "#1.1"); - Assert.IsTrue(enabledChild.Enabled, "#1.2"); - Assert.IsFalse(disabledChild.Enabled, "#1.3"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#1.4"); + Assert.That(container.Enabled, Is.True, "#1.1"); + Assert.That(enabledChild.Enabled, Is.True, "#1.2"); + Assert.That(disabledChild.Enabled, Is.False, "#1.3"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#1.4"); addControls(); // default values after added to the container - Assert.IsTrue(container.Enabled, "#2.1"); - Assert.IsTrue(enabledChild.Enabled, "#2.2"); - Assert.IsFalse(disabledChild.Enabled, "#2.3"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#2.4"); + Assert.That(container.Enabled, Is.True, "#2.1"); + Assert.That(enabledChild.Enabled, Is.True, "#2.2"); + Assert.That(disabledChild.Enabled, Is.False, "#2.3"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#2.4"); removeControls(); @@ -158,40 +158,40 @@ public void EnabledShouldAffectChildControlsWhenDynamicallyAdded(IContainerTypeI container.Enabled = false; // default values after removed from the container (and container set to disabled) - Assert.IsTrue(enabledChild.Enabled, "#3.1"); - Assert.IsFalse(disabledChild.Enabled, "#3.2"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#3.3"); + Assert.That(enabledChild.Enabled, Is.True, "#3.1"); + Assert.That(disabledChild.Enabled, Is.False, "#3.2"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#3.3"); addControls(); // values after adding back to the container - Assert.IsFalse(container.Enabled, "#4.1"); - Assert.IsFalse(enabledChild.Enabled, "#4.2"); - Assert.IsFalse(disabledChild.Enabled, "#4.3"); - Assert.IsFalse(neutralChild.Enabled, "#4.4"); + Assert.That(container.Enabled, Is.False, "#4.1"); + Assert.That(enabledChild.Enabled, Is.False, "#4.2"); + Assert.That(disabledChild.Enabled, Is.False, "#4.3"); + Assert.That(neutralChild.Enabled, Is.False, "#4.4"); // set child to enabled when parent is disabled, should still stay disabled enabledChild.Enabled = true; - Assert.IsFalse(container.Enabled, "#5.1"); - Assert.IsFalse(enabledChild.Enabled, "#5.2"); - Assert.IsFalse(disabledChild.Enabled, "#5.3"); - Assert.IsFalse(neutralChild.Enabled, "#5.4"); + Assert.That(container.Enabled, Is.False, "#5.1"); + Assert.That(enabledChild.Enabled, Is.False, "#5.2"); + Assert.That(disabledChild.Enabled, Is.False, "#5.3"); + Assert.That(neutralChild.Enabled, Is.False, "#5.4"); removeControls(); // default values after removed from the container (again) - Assert.IsTrue(enabledChild.Enabled, "#6.1"); - Assert.IsFalse(disabledChild.Enabled, "#6.2"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#6.3"); + Assert.That(enabledChild.Enabled, Is.True, "#6.1"); + Assert.That(disabledChild.Enabled, Is.False, "#6.2"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#6.3"); // set container back to enabled container.Enabled = true; addControls(); - Assert.IsTrue(container.Enabled, "#7.1"); - Assert.IsTrue(enabledChild.Enabled, "#7.2"); - Assert.IsFalse(disabledChild.Enabled, "#7.3"); - Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#7.4"); + Assert.That(container.Enabled, Is.True, "#7.1"); + Assert.That(enabledChild.Enabled, Is.True, "#7.2"); + Assert.That(disabledChild.Enabled, Is.False, "#7.3"); + Assert.That(neutralChild.Enabled, Is.EqualTo(neutralEnabled), "#7.4"); }); } @@ -207,18 +207,18 @@ public void EnabledShouldTriggerChangedEventsOnChildren(IControlTypeInfo label.Text = $"EnabledChanged->radio.Enabled({radio.Enabled})"; radio.Enabled = initiallyEnabled; - Assert.AreEqual(initiallyEnabled, radio.Enabled, "#1.1"); + Assert.That(radio.Enabled, Is.EqualTo(initiallyEnabled), "#1.1"); check.CheckedChanged += (sender, e) => { var isChecked = check.Checked == true; radio.Enabled = isChecked; @@ -301,9 +301,9 @@ public void EnabledShouldBeToggleable(bool initiallyEnabled) return new TableLayout { Rows = { check, radio, label } }; }); - Assert.AreEqual(0, incorrectTableLayoutEnabledState, "#2.1 - internal TableLayout did not have the correct enabled state"); - Assert.GreaterOrEqual(changedCount, 2, "#2.2 - The check box was not toggled at least twice"); - Assert.IsTrue(initialStateMatchesInitiallyEnabled, "#2.3 - initial state of radio button did not match"); + Assert.That(incorrectTableLayoutEnabledState, Is.EqualTo(0), "#2.1 - internal TableLayout did not have the correct enabled state"); + Assert.That(changedCount, Is.GreaterThanOrEqualTo(2), "#2.2 - The check box was not toggled at least twice"); + Assert.That(initialStateMatchesInitiallyEnabled, Is.True, "#2.3 - initial state of radio button did not match"); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/CalendarTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/CalendarTests.cs index a3a02d4f86..8b59471687 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/CalendarTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/CalendarTests.cs @@ -10,11 +10,11 @@ public void InitialValuesShouldBeCorrect() TestBase.Invoke(() => { var calendar = new Calendar(); - Assert.AreEqual(CalendarMode.Single, calendar.Mode, "Calendar should default to single mode"); - Assert.AreEqual(DateTime.Today, calendar.SelectedDate, "Initial SelectedDate should be Today"); - Assert.AreEqual(new Range(DateTime.Today), calendar.SelectedRange, "Initial SelectedRange should be Today"); - Assert.AreEqual(DateTime.MinValue, calendar.MinDate, "Initial MinDate should be DateTime.MinValue"); - Assert.AreEqual(DateTime.MaxValue, calendar.MaxDate, "Initial MaxDate should be DateTime.MaxValue"); + Assert.That(calendar.Mode, Is.EqualTo(CalendarMode.Single), "Calendar should default to single mode"); + Assert.That(calendar.SelectedDate, Is.EqualTo(DateTime.Today), "Initial SelectedDate should be Today"); + Assert.That(calendar.SelectedRange, Is.EqualTo(new Range(DateTime.Today)), "Initial SelectedRange should be Today"); + Assert.That(calendar.MinDate, Is.EqualTo(DateTime.MinValue), "Initial MinDate should be DateTime.MinValue"); + Assert.That(calendar.MaxDate, Is.EqualTo(DateTime.MaxValue), "Initial MaxDate should be DateTime.MaxValue"); }); } @@ -31,27 +31,27 @@ public void SelectedDateShouldTriggerChange() DateTime date = DateTime.Today; calendar.SelectedDate = date; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to the initial value"); - Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not fire when date is set to the initial value"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not fire when set to the initial value"); + Assert.That(rangeCount, Is.EqualTo(0), "SelectedRangeChanged should not fire when date is set to the initial value"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should retain its value"); date = DateTime.Today.AddDays(10); calendar.SelectedDate = date; - Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a value"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing SelectedDate"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should fire when set to a value"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing SelectedDate"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should retain its value"); dateCount = rangeCount = 0; calendar.SelectedDate = date; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when set to the same date"); - Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not be fired when set to the same date"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not be fired when set to the same date"); + Assert.That(rangeCount, Is.EqualTo(0), "SelectedRangeChanged should not be fired when set to the same date"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should retain its value"); dateCount = rangeCount = 0; calendar.SelectedDate = date = DateTime.Today.AddDays(20); - Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a specific date"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing SelectedDate"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should fire when set to a specific date"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing SelectedDate"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should retain its value"); }); } @@ -69,40 +69,40 @@ public void SelectedRangeShouldTriggerChange() rangeCount = dateCount = 0; var range = new Range(DateTime.Today); calendar.SelectedRange = range; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to initial value of null"); - Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should fire when set to initial value of null"); - Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); - Assert.AreEqual(range.Start, calendar.SelectedDate, "SelectedDate should be null when range is set to null"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not fire when set to initial value of null"); + Assert.That(rangeCount, Is.EqualTo(0), "SelectedRangeChanged should fire when set to initial value of null"); + Assert.That(calendar.SelectedRange, Is.EqualTo(range), "SelectedRange should retain its value"); + Assert.That(calendar.SelectedDate, Is.EqualTo(range.Start), "SelectedDate should be null when range is set to null"); rangeCount = dateCount = 0; range = new Range(DateTime.Today.AddDays(1), DateTime.Today.AddDays(10)); calendar.SelectedRange = range; - Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a specific date"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set"); - Assert.AreEqual(range, calendar.SelectedRange, "SelectedDate should retain its value"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should fire when set to a specific date"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should fire when set"); + Assert.That(calendar.SelectedRange, Is.EqualTo(range), "SelectedDate should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when set to the same date"); - Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not be fired when set to the same date"); - Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not be fired when set to the same date"); + Assert.That(rangeCount, Is.EqualTo(0), "SelectedRangeChanged should not be fired when set to the same date"); + Assert.That(calendar.SelectedRange, Is.EqualTo(range), "SelectedRange should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to the same value"); - Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not fire when set to the same value"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not fire when set to the same value"); + Assert.That(rangeCount, Is.EqualTo(0), "SelectedRangeChanged should not fire when set to the same value"); rangeCount = dateCount = 0; calendar.SelectedRange = range = new Range(DateTime.Today.AddDays(1), DateTime.Today.AddDays(11)); - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when range's start date hasn't changed"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set to a different date"); - Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not fire when range's start date hasn't changed"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should fire when set to a different date"); + Assert.That(calendar.SelectedRange, Is.EqualTo(range), "SelectedRange should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range = new Range(DateTime.Today.AddDays(2), DateTime.Today.AddDays(10)); - Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when range's start date hasn't changed"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set to a different range"); - Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should fire when range's start date hasn't changed"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should fire when set to a different range"); + Assert.That(calendar.SelectedRange, Is.EqualTo(range), "SelectedRange should retain its value"); }); } @@ -121,9 +121,9 @@ public void MinDateShouldChangeSelectedDate() dateCount = rangeCount = 0; var date = DateTime.Today.AddDays(10); calendar.MinDate = date; - Assert.AreEqual(1, dateCount, "SelectedDateChanged should be fired when changing the min date"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the min date"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should be changed to the MinDate"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should be fired when changing the min date"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing the min date"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should be changed to the MinDate"); }); } @@ -142,9 +142,9 @@ public void MaxDateShouldChangeSelectedDate() dateCount = rangeCount = 0; var date = DateTime.Today.AddDays(-10); calendar.MaxDate = date; - Assert.AreEqual(1, dateCount, "SelectedDateChanged should be fired when changing the min date"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the min date"); - Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should be changed to the MaxDate"); + Assert.That(dateCount, Is.EqualTo(1), "SelectedDateChanged should be fired when changing the min date"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing the min date"); + Assert.That(calendar.SelectedDate, Is.EqualTo(date), "SelectedDate should be changed to the MaxDate"); }); } @@ -160,20 +160,20 @@ public void ModeShouldUpdateDateWhenChangingFromRangeToSingle() calendar.SelectedDateChanged += (sender, e) => dateCount++; calendar.SelectedRangeChanged += (sender, e) => rangeCount++; - Assert.AreEqual(initialRange, calendar.SelectedRange, "SelectedRange is not set to the initial value"); + Assert.That(calendar.SelectedRange, Is.EqualTo(initialRange), "SelectedRange is not set to the initial value"); calendar.Mode = CalendarMode.Single; - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when changing the mode"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the mode when the range changes"); - Assert.AreEqual(initialRange.Start, calendar.SelectedDate, "SelectedDate should be the start of the original range"); - Assert.AreEqual(initialRange.Start, calendar.SelectedRange.Start, "SelectedRange.End should be the same date"); - Assert.AreEqual(initialRange.Start, calendar.SelectedRange.End, "SelectedRange.End should be the same date"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not be fired when changing the mode"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing the mode when the range changes"); + Assert.That(calendar.SelectedDate, Is.EqualTo(initialRange.Start), "SelectedDate should be the start of the original range"); + Assert.That(calendar.SelectedRange.Start, Is.EqualTo(initialRange.Start), "SelectedRange.End should be the same date"); + Assert.That(calendar.SelectedRange.End, Is.EqualTo(initialRange.Start), "SelectedRange.End should be the same date"); dateCount = rangeCount = 0; calendar.Mode = CalendarMode.Range; - Assert.AreEqual(initialRange.End, calendar.SelectedRange.End, "SelectedRange.End should be the original end date when changing back to range mode"); - Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when changing the mode"); - Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the mode when the range changes"); + Assert.That(calendar.SelectedRange.End, Is.EqualTo(initialRange.End), "SelectedRange.End should be the original end date when changing back to range mode"); + Assert.That(dateCount, Is.EqualTo(0), "SelectedDateChanged should not be fired when changing the mode"); + Assert.That(rangeCount, Is.EqualTo(1), "SelectedRangeChanged should be fired when changing the mode when the range changes"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/ComboBoxTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/ComboBoxTests.cs index 7e72f4e68c..f0ba010dc1 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/ComboBoxTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/ComboBoxTests.cs @@ -11,9 +11,9 @@ public void InitialValuesShouldBeCorrect() Invoke(() => { var comboBox = new ComboBox(); - Assert.IsFalse(comboBox.AutoComplete, "AutoComplete should be false"); - Assert.IsFalse(comboBox.ReadOnly, "Should not be initially read only"); - Assert.IsTrue(comboBox.Enabled, "Should be enabled"); + Assert.That(comboBox.AutoComplete, Is.False, "AutoComplete should be false"); + Assert.That(comboBox.ReadOnly, Is.False, "Should not be initially read only"); + Assert.That(comboBox.Enabled, Is.True, "Should be enabled"); }); } @@ -25,11 +25,11 @@ public void TextNotMatchingItemsShouldNotHaveSelectedItem() int selectedIndexChanged = 0; var comboBox = new ComboBox { Items = { "Item 1", "Item 2", "Item 3" } }; comboBox.SelectedIndexChanged += (sender, args) => selectedIndexChanged++; - Assert.AreEqual(-1, comboBox.SelectedIndex, "Should not have an initially selected item"); + Assert.That(comboBox.SelectedIndex, Is.EqualTo(-1), "Should not have an initially selected item"); comboBox.Text = "Item Not In List"; - Assert.AreEqual(0, selectedIndexChanged, "Setting text to something not in list should not fire SelectedIndexChanged event"); + Assert.That(selectedIndexChanged, Is.EqualTo(0), "Setting text to something not in list should not fire SelectedIndexChanged event"); comboBox.Text = "Item 1"; - Assert.AreEqual(1, selectedIndexChanged, "Setting text to an item in the list should fire a SelectedIndexChanged event"); + Assert.That(selectedIndexChanged, Is.EqualTo(1), "Setting text to an item in the list should fire a SelectedIndexChanged event"); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/ControlTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/ControlTests.cs index cd40957599..31a246dc44 100755 --- a/test/Eto.Test/UnitTests/Forms/Controls/ControlTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/ControlTests.cs @@ -44,10 +44,10 @@ public void ControlShouldFireShownEvent(IControlTypeInfo controlType) }); }; form.Content = TableLayout.AutoSized(ctl); - Assert.AreEqual(0, shownCount); + Assert.That(shownCount, Is.EqualTo(0)); }); - Assert.AreEqual(1, shownCount); - Assert.AreEqual(expectedVisualShown, visualControlShownCount, "Visual controls didn't get Shown event triggered"); + Assert.That(shownCount, Is.EqualTo(1)); + Assert.That(visualControlShownCount, Is.EqualTo(expectedVisualShown), "Visual controls didn't get Shown event triggered"); } [TestCaseSource(nameof(GetControlTypes))] @@ -83,7 +83,7 @@ public void ControlShouldFireShownEventWhenAddedDynamically(IControlTypeInfo Application.Instance.AsyncInvoke(() => { initialShownCount = shownCount; @@ -114,8 +114,8 @@ public void ControlShouldFireShownEventWhenVisibleChanged(IControlTypeInfo info) var control = info.CreateControl(); if (control is CommonControl commonControl) { - Assert.IsNotNull(commonControl.Font); + Assert.That(commonControl.Font, Is.Not.Null); } else if (control is GroupBox groupBox) { - Assert.IsNotNull(groupBox.Font); + Assert.That(groupBox.Font, Is.Not.Null); } else { @@ -304,7 +304,7 @@ public void PointToScreenShouldWorkOnSecondaryScreen() ManualForm("The Form with the button should be above the text box exactly.\nClick the button to pass the test, close the window to fail.", form => { var screens = Screen.Screens.ToArray(); - Assert.GreaterOrEqual(screens.Length, 2, "You must have a secondary monitor for this test"); + Assert.That(screens.Length, Is.GreaterThanOrEqualTo(2), "You must have a secondary monitor for this test"); form.Location = Point.Round(screens[1].Bounds.Location) + new Size(50, 50); form.ClientSize = new Size(200, 200); @@ -362,8 +362,8 @@ public void PointToScreenShouldWorkOnSecondaryScreen() if (childForm != null) Application.Instance.Invoke(() => childForm.Close()); } - Assert.AreEqual(controlPoint, rountripPoint, "Point could not round trip to screen then back"); - Assert.IsTrue(wasClicked, "The test completed without clicking the button"); + Assert.That(rountripPoint, Is.EqualTo(controlPoint), "Point could not round trip to screen then back"); + Assert.That(wasClicked, Is.True, "The test completed without clicking the button"); } [TestCaseSource(nameof(GetControlTypes)), InvokeOnUI] @@ -372,8 +372,8 @@ public void ControlsShouldHavePreferredSize(IControlTypeInfo info) var control = info.CreatePopulatedControl(); var size = control.GetPreferredSize(); Console.WriteLine($"PreferredSize for {info.Type}: {size}"); - Assert.Greater(size.Width, 0, "#1.1 - Preferred width should be greater than zero"); - Assert.Greater(size.Height, 0, "#1.2 - Preferred height should be greater than zero"); + Assert.That(size.Width, Is.GreaterThan(0), "#1.1 - Preferred width should be greater than zero"); + Assert.That(size.Height, Is.GreaterThan(0), "#1.2 - Preferred height should be greater than zero"); var padding = new Padding(10); var container = new Panel { Content = control, Padding = padding }; var containerSize = container.GetPreferredSize(); @@ -443,11 +443,11 @@ public void ControlsShouldNotGetMouseOrFocusEventsWhenParentDisabled(IControlTyp panel.Enabled = false; return panel; }); - Assert.IsFalse(gotFocus, "#1.1 - Control should not be able to get focus"); - Assert.IsFalse(gotMouseEnter, "#1.2 - Got MouseEnter"); - Assert.IsFalse(gotMouseLeave, "#1.3 - Got MouseLeave"); - Assert.IsFalse(gotMouseDown, "#1.4 - Got MouseDown"); - Assert.IsFalse(gotMouseUp, "#1.5 - Got MouseUp"); + Assert.That(gotFocus, Is.False, "#1.1 - Control should not be able to get focus"); + Assert.That(gotMouseEnter, Is.False, "#1.2 - Got MouseEnter"); + Assert.That(gotMouseLeave, Is.False, "#1.3 - Got MouseLeave"); + Assert.That(gotMouseDown, Is.False, "#1.4 - Got MouseDown"); + Assert.That(gotMouseUp, Is.False, "#1.5 - Got MouseUp"); } [ManualTest] @@ -498,14 +498,14 @@ public void ControlShouldFireMouseLeaveIfEnteredThenDisabled(IControlTypeInfo in }; return control; }); - Assert.AreEqual(1, mouseEnterCalled, "#1.1 - MouseEnter should be called exactly once"); - Assert.AreEqual(1, mouseLeaveCalled, "#1.2 - MouseLeave should be called exactly once"); - Assert.IsFalse(mouseLeaveCalledBeforeMouseDown, "#1.3 - MouseLeave should not have been called before MouseDown"); - Assert.AreEqual(1, mouseDownCalled, "#1.5 - MouseDown should get called exactly once. Did you click the control?"); - Assert.IsFalse(mouseLeaveCalledAfterFormClosed, "#1.6 - MouseLeave should be called immediately when clicked, not when the form is closed"); + Assert.That(mouseEnterCalled, Is.EqualTo(1), "#1.1 - MouseEnter should be called exactly once"); + Assert.That(mouseLeaveCalled, Is.EqualTo(1), "#1.2 - MouseLeave should be called exactly once"); + Assert.That(mouseLeaveCalledBeforeMouseDown, Is.False, "#1.3 - MouseLeave should not have been called before MouseDown"); + Assert.That(mouseDownCalled, Is.EqualTo(1), "#1.5 - MouseDown should get called exactly once. Did you click the control?"); + Assert.That(mouseLeaveCalledAfterFormClosed, Is.False, "#1.6 - MouseLeave should be called immediately when clicked, not when the form is closed"); } } } \ No newline at end of file diff --git a/test/Eto.Test/UnitTests/Forms/Controls/DocumentControlTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/DocumentControlTests.cs index cb10dbc323..14b505ab4f 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/DocumentControlTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/DocumentControlTests.cs @@ -12,13 +12,13 @@ public void LogicalParentShouldChangeWhenAddedOrRemoved() var ctl = new DocumentControl(); var child = new Panel { Size = new Size(100, 100) }; var page = new DocumentPage(child); - Assert.AreEqual(page, child.Parent, "#1"); + Assert.That(child.Parent, Is.EqualTo(page), "#1"); ctl.Pages.Add(page); - Assert.AreEqual(page.Parent, ctl, "#2"); + Assert.That(ctl, Is.EqualTo(page.Parent), "#2"); ctl.Pages.RemoveAt(0); - Assert.IsNull(page.Parent, "#3"); + Assert.That(page.Parent, Is.Null, "#3"); page.Content = null; - Assert.IsNull(child.Parent, "#4"); + Assert.That(child.Parent, Is.Null, "#4"); }); } @@ -37,25 +37,25 @@ public void LoadedEventsShouldPropegate() child1 = new Panel { Size = new Size(100, 100) }; ctl.Pages.Add(page1 = new DocumentPage(child1) { Text = "Page 1" }); - Assert.IsFalse(child1.Loaded, "#1"); + Assert.That(child1.Loaded, Is.False, "#1"); child2 = new Panel { Size = new Size(100, 100) }; ctl.Pages.Add(page2 = new DocumentPage(child2)); - Assert.IsFalse(child2.Loaded, "#2"); + Assert.That(child2.Loaded, Is.False, "#2"); return ctl; }, ctl => { - Assert.IsTrue(child1.Loaded, "#3"); + Assert.That(child1.Loaded, Is.True, "#3"); page1.Content = new Panel(); - Assert.IsFalse(child1.Loaded, "#4"); + Assert.That(child1.Loaded, Is.False, "#4"); ctl.SelectedIndex = 1; - Assert.IsTrue(child2.Loaded, "#5"); + Assert.That(child2.Loaded, Is.True, "#5"); ctl.Pages.RemoveAt(1); - Assert.IsFalse(child2.Loaded, "#6"); - Assert.IsFalse(page2.Loaded, "#7"); + Assert.That(child2.Loaded, Is.False, "#6"); + Assert.That(page2.Loaded, Is.False, "#7"); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/DrawableTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/DrawableTests.cs index d56d3710b1..15f1c98e31 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/DrawableTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/DrawableTests.cs @@ -41,8 +41,8 @@ public void DrawableWithCanFocusShouldGetFirstMouseDownOnInactiveWindow() form.Owner = Application.Instance.MainForm; }, -1); - Assert.IsTrue(wasClicked, "#1 Drawable didn't get clicked"); - Assert.IsFalse(gotFocusBeforeClick, "#2 Form should not have got focus before MouseDown event"); + Assert.That(wasClicked, Is.True, "#1 Drawable didn't get clicked"); + Assert.That(gotFocusBeforeClick, Is.False, "#2 Form should not have got focus before MouseDown event"); } [Test] @@ -69,9 +69,9 @@ public void DrawableWithWrappedLabelShouldAutoSizeToConstraints() }, () => { - Assert.GreaterOrEqual(labelThatShouldWrap.Height, 20, "#1 - Label should have wrapped!"); + Assert.That(labelThatShouldWrap.Height, Is.GreaterThanOrEqualTo(20), "#1 - Label should have wrapped!"); - Assert.AreEqual(100, form.Width, "#2 - Form width should be 100"); + Assert.That(form.Width, Is.EqualTo(100), "#2 - Form width should be 100"); } ); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/DropDownTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/DropDownTests.cs index 57cf735060..0cdc742f25 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/DropDownTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/DropDownTests.cs @@ -21,35 +21,35 @@ static void TestDropDownSelection(DropDown dropDown, object item1, object item2, else dropDown.SelectedValue = item2; - Assert.AreEqual(1, dropDown.SelectedIndex); - Assert.AreEqual(item2, dropDown.SelectedValue); - Assert.AreEqual(1, selectedIndexChanged); - Assert.AreEqual(1, selectedValueChanged); - Assert.AreEqual(1, selectedKeyChanged); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(1)); + Assert.That(dropDown.SelectedValue, Is.EqualTo(item2)); + Assert.That(selectedIndexChanged, Is.EqualTo(1)); + Assert.That(selectedValueChanged, Is.EqualTo(1)); + Assert.That(selectedKeyChanged, Is.EqualTo(1)); // change the list dropDown.DataStore = new[] { item1, item3, item2 }; - Assert.AreEqual(2, dropDown.SelectedIndex); - Assert.AreEqual(item2, dropDown.SelectedValue); - Assert.AreEqual(2, selectedIndexChanged); - Assert.AreEqual(1, selectedValueChanged); - Assert.AreEqual(1, selectedKeyChanged); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(2)); + Assert.That(dropDown.SelectedValue, Is.EqualTo(item2)); + Assert.That(selectedIndexChanged, Is.EqualTo(2)); + Assert.That(selectedValueChanged, Is.EqualTo(1)); + Assert.That(selectedKeyChanged, Is.EqualTo(1)); // change again, but selected value does not exist dropDown.DataStore = new[] { item1, item3 }; - Assert.AreEqual(-1, dropDown.SelectedIndex); - Assert.IsNull(dropDown.SelectedValue); - Assert.AreEqual(3, selectedIndexChanged); - Assert.AreEqual(2, selectedValueChanged); - Assert.AreEqual(2, selectedKeyChanged); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(-1)); + Assert.That(dropDown.SelectedValue, Is.Null); + Assert.That(selectedIndexChanged, Is.EqualTo(3)); + Assert.That(selectedValueChanged, Is.EqualTo(2)); + Assert.That(selectedKeyChanged, Is.EqualTo(2)); // add it back, still should not be selected now that it was deselected! dropDown.DataStore = new[] { item2, item1, item3 }; - Assert.AreEqual(-1, dropDown.SelectedIndex); - Assert.IsNull(dropDown.SelectedValue); - Assert.AreEqual(3, selectedIndexChanged); - Assert.AreEqual(2, selectedValueChanged); - Assert.AreEqual(2, selectedKeyChanged); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(-1)); + Assert.That(dropDown.SelectedValue, Is.Null); + Assert.That(selectedIndexChanged, Is.EqualTo(3)); + Assert.That(selectedValueChanged, Is.EqualTo(2)); + Assert.That(selectedKeyChanged, Is.EqualTo(2)); } [Test] @@ -116,11 +116,11 @@ public void SettingDataStoreToNullWithSelectedItemShouldNotCrash() dropDown.DataStore = items; dropDown.SelectedIndex = 1; // sanity check - Assert.AreEqual(items[1], dropDown.SelectedValue, "#1"); + Assert.That(dropDown.SelectedValue, Is.EqualTo(items[1]), "#1"); dropDown.DataStore = null; - Assert.AreEqual(-1, dropDown.SelectedIndex, "#2.1"); - Assert.IsNull(dropDown.SelectedValue, "#2.2"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(-1), "#2.1"); + Assert.That(dropDown.SelectedValue, Is.Null, "#2.2"); }); } @@ -152,28 +152,28 @@ public void SelectedIndexShouldOnlyFireIfIndexChanges() dropDown.SelectedIndexChanged += (sender, e) => selectedIndexChangedCount++; dropDown.DataStore = list; dropDown.SelectedIndex = 1; - Assert.AreEqual(1, selectedIndexChangedCount, "#1"); + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#1"); form.Content = dropDown; return dropDown; }, dropDown => { - Assert.AreEqual(1, dropDown.SelectedIndex, "#2.1"); - Assert.AreEqual("bbb", dropDown.SelectedValue, "#2.2"); - Assert.AreEqual(1, selectedIndexChangedCount, "#2.3"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(1), "#2.1"); + Assert.That(dropDown.SelectedValue, Is.EqualTo("bbb"), "#2.2"); + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#2.3"); // set to same list instance, should not fire a changed event dropDown.DataStore = list; - Assert.AreEqual(1, dropDown.SelectedIndex, "#3.1"); - Assert.AreEqual("bbb", dropDown.SelectedValue, "#3.2"); - Assert.AreEqual(1, selectedIndexChangedCount, "#3.3"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(1), "#3.1"); + Assert.That(dropDown.SelectedValue, Is.EqualTo("bbb"), "#3.2"); + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#3.3"); // set to new list instance with same index for selected item, should not fire a changed event list = new List(list); list.Add("ddd"); - Assert.AreEqual(1, dropDown.SelectedIndex, "#4.1"); - Assert.AreEqual("bbb", dropDown.SelectedValue, "#4.2"); - Assert.AreEqual(1, selectedIndexChangedCount, "#4.3"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(1), "#4.1"); + Assert.That(dropDown.SelectedValue, Is.EqualTo("bbb"), "#4.2"); + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#4.3"); // create a copy and insert to make the index differnet, should now fire a changed event list = new List(list); @@ -181,9 +181,9 @@ public void SelectedIndexShouldOnlyFireIfIndexChanges() dropDown.DataStore = list; // now we should get a change event, since the index of the previously selected item is now different. - Assert.AreEqual(2, dropDown.SelectedIndex, "#5.1"); - Assert.AreEqual("bbb", dropDown.SelectedValue, "#5.2"); - Assert.AreEqual(2, selectedIndexChangedCount, "#5.3"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(2), "#5.1"); + Assert.That(dropDown.SelectedValue, Is.EqualTo("bbb"), "#5.2"); + Assert.That(selectedIndexChangedCount, Is.EqualTo(2), "#5.3"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs index 5fd00d576f..4dae9f50e9 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridTests.cs @@ -273,7 +273,7 @@ public void SettingWidthShouldDisableAutosize() }; control.Columns.Add(column); - Assert.IsFalse(column.AutoSize, "#1"); + Assert.That(column.AutoSize, Is.False, "#1"); var dd = new TreeGridItemCollection(); for (int i = 0; i < 1000; i++) @@ -426,8 +426,8 @@ public void CustomCellShouldGetMouseEvents() window.Content = grid; }, -1); - Assert.NotZero(mouseMoved, "MouseMove was never fired!"); - Assert.AreEqual(4, mode, "Mode should be 4 after going through all steps"); + Assert.That(mouseMoved, Is.Not.Zero, "MouseMove was never fired!"); + Assert.That(mode, Is.EqualTo(4), "Mode should be 4 after going through all steps"); } [ManualTest] @@ -533,8 +533,8 @@ public void ReloadingFocusedItemShouldKeepFocus() form.Close(); }; }); - Assert.IsTrue(hasFocusBefore, "Grid did not have focus before reloading"); - Assert.IsTrue(hasFocusAfter, "Grid did not have focus after reloading"); + Assert.That(hasFocusBefore, Is.True, "Grid did not have focus before reloading"); + Assert.That(hasFocusAfter, Is.True, "Grid did not have focus after reloading"); } [Test] @@ -573,8 +573,8 @@ public void ReloadingDataShouldKeepFocus() form.Close(); }; }); - Assert.IsTrue(hasFocusBefore, "Grid did not have focus before reloading"); - Assert.IsTrue(hasFocusAfter, "Grid did not have focus after reloading"); + Assert.That(hasFocusBefore, Is.True, "Grid did not have focus before reloading"); + Assert.That(hasFocusAfter, Is.True, "Grid did not have focus after reloading"); } } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridViewFilterTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridViewFilterTests.cs index 081006026e..09047d04d3 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridViewFilterTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridViewFilterTests.cs @@ -44,7 +44,7 @@ public void InsertItemShouldNotChangeSelection() grid.SelectRow(0); var selectedItem = grid.SelectedItem; model.Insert(0, new DataItem(model.Count)); - Assert.AreEqual(selectedItem, grid.SelectedItem); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem)); }); } @@ -61,9 +61,9 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = 0; i < initialCount / 2; i++) grid.SelectRow(i); - Assert.AreEqual(initialCount / 2, grid.SelectedRows.Count(), "Number of selected items should be half of the items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 2), "Number of selected items should be half of the items"); - Assert.AreEqual(initialCount / 2, selectionChangedCount, "SelectionChanged event should fire for each item selected"); + Assert.That(selectionChangedCount, Is.EqualTo(initialCount / 2), "SelectionChanged event should fire for each item selected"); // reset to test events fired when removing selectionChangedCount = 0; @@ -72,13 +72,13 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = initialCount - 1; i >= 0; i -= 2) model.RemoveAt(i); - Assert.AreEqual(initialCount / 4, grid.SelectedRows.Count(), "Number of selected items should be quarter of the original items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 4), "Number of selected items should be quarter of the original items"); var expectedSelectedItemIds = new List(); for (var i = 0; i < initialCount / 2; i += 2) expectedSelectedItemIds.Add(i); - Assert.IsTrue(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), "Items don't match"); + Assert.That(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), Is.True, "Items don't match"); - Assert.AreEqual(initialCount / 4, selectionChangedCount, "SelectionChanged event should fire for each selected item removed"); + Assert.That(selectionChangedCount, Is.EqualTo(initialCount / 4), "SelectionChanged event should fire for each selected item removed"); }); } @@ -92,17 +92,17 @@ public void SortItemsShouldNotChangeSelection(int rowToSelect) grid.SelectRow(rowToSelect); var selectedItem = filtered[rowToSelect]; - Assert.AreEqual(1, grid.SelectedRows.Count(), "The row was not selected"); - Assert.AreEqual(selectedItem, grid.SelectedItem, "The correct item was not selected"); - Assert.AreEqual(1, selectionChangedCount, "SelectionChanged event should fire once for the selected row"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(1), "The row was not selected"); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem), "The correct item was not selected"); + Assert.That(selectionChangedCount, Is.EqualTo(1), "SelectionChanged event should fire once for the selected row"); selectionChangedCount = 0; // reset the count filtered.Sort = GridViewUtils.SortItemsDescending; - Assert.AreEqual(1, grid.SelectedRows.Count(), "There should still only be a single selected row"); - Assert.AreEqual(selectedItem, grid.SelectedItem, "The selected item should remain the same"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(1), "There should still only be a single selected row"); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem), "The selected item should remain the same"); - Assert.AreEqual(0, selectionChangedCount, "SelectionChanged event should not fire when changing the Sort"); + Assert.That(selectionChangedCount, Is.EqualTo(0), "SelectionChanged event should not fire when changing the Sort"); }); } @@ -120,13 +120,13 @@ public void FilterItemsShouldUnselectFilteredItems() selectionChangedCount = 0; // reset the count filtered.Filter = GridViewUtils.KeepOddItemsFilter; - Assert.AreEqual(model.Count / 4, grid.SelectedRows.Count(), "A quarter of the items should be selected"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(model.Count / 4), "A quarter of the items should be selected"); var selectedItems = grid.SelectedItems.OfType().OrderBy(r => r.Id).ToList(); var expectedItems = model.Where((item, row) => row < model.Count / 2 && (row % 2) == 1).ToList(); - Assert.IsTrue(expectedItems.SequenceEqual(selectedItems), "Selected items should only contain items left after filtering"); + Assert.That(expectedItems.SequenceEqual(selectedItems), Is.True, "Selected items should only contain items left after filtering"); - Assert.AreEqual(1, selectionChangedCount, "SelectionChanged event should fire when changing the Filter which removes items"); + Assert.That(selectionChangedCount, Is.EqualTo(1), "SelectionChanged event should fire when changing the Filter which removes items"); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectTests.cs index 274dd20a4a..076d76f10a 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectTests.cs @@ -37,8 +37,8 @@ public void SelectFirstRowShouldSelectFirstRow() TestBase.Invoke(() => { grid.SelectRow(0); - Assert.AreEqual(model[0], grid.SelectedItem); - Assert.AreEqual(0, grid.SelectedRows.First()); + Assert.That(grid.SelectedItem, Is.EqualTo(model[0])); + Assert.That(grid.SelectedRows.First(), Is.EqualTo(0)); }); } @@ -49,7 +49,7 @@ public void SelectAllShouldSelectAllRows() { grid.AllowMultipleSelection = true; grid.SelectAll(); - Assert.AreEqual(model.Count, grid.SelectedRows.Count()); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(model.Count)); }); } @@ -61,7 +61,7 @@ public void InsertItemShouldNotChangeSelection() grid.SelectRow(0); var selectedItem = grid.SelectedItem; model.Insert(0, new DataItem(model.Count)); - Assert.AreEqual(selectedItem, grid.SelectedItem); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem)); }); } @@ -77,17 +77,17 @@ public void UnselectAllShouldUnselectAllRows() for (var i = 0; i < initialCount; i += 2) grid.SelectRow(i); - Assert.AreEqual(initialCount / 2, grid.SelectedRows.Count(), "Number of selected items should be half of the items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 2), "Number of selected items should be half of the items"); - Assert.AreEqual(initialCount / 2, selectionChangedCount, "SelectionChanged event should fire for each item selected"); + Assert.That(selectionChangedCount, Is.EqualTo(initialCount / 2), "SelectionChanged event should fire for each item selected"); selectionChangedCount = 0; grid.UnselectAll(); - Assert.AreEqual(0, grid.SelectedRows.Count(), "There should be zero selected items after UnselectAll"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(0), "There should be zero selected items after UnselectAll"); - Assert.AreEqual(1, selectionChangedCount, "SelectionChanged event should fire once after UnselectAll"); + Assert.That(selectionChangedCount, Is.EqualTo(1), "SelectionChanged event should fire once after UnselectAll"); }); } @@ -104,9 +104,9 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = 0; i < initialCount / 2; i++) grid.SelectRow(i); - Assert.AreEqual(initialCount / 2, grid.SelectedRows.Count(), "Number of selected items should be half of the items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 2), "Number of selected items should be half of the items"); - Assert.AreEqual(initialCount / 2, selectionChangedCount, "SelectionChanged event should fire for each item selected"); + Assert.That(selectionChangedCount, Is.EqualTo(initialCount / 2), "SelectionChanged event should fire for each item selected"); // reset to test events fired when removing selectionChangedCount = 0; @@ -115,13 +115,13 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = initialCount - 1; i >= 0; i -= 2) model.RemoveAt(i); - Assert.AreEqual(initialCount / 4, grid.SelectedRows.Count(), "Number of selected items should be quarter of the original items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 4), "Number of selected items should be quarter of the original items"); var expectedSelectedItemIds = new List(); for (var i = 0; i < initialCount / 2; i += 2) expectedSelectedItemIds.Add(i); - Assert.IsTrue(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), "Items don't match"); + Assert.That(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), Is.True, "Items don't match"); - Assert.AreEqual(initialCount / 4, selectionChangedCount, "SelectionChanged event should fire for each selected item removed"); + Assert.That(selectionChangedCount, Is.EqualTo(initialCount / 4), "SelectionChanged event should fire for each selected item removed"); }); } @@ -138,7 +138,7 @@ public void UnselectingInMultipleModeThenSwitchingToSingleModeShouldNotBreakSele grid.UnselectAll(); grid.AllowMultipleSelection = false; grid.SelectRow(1); - Assert.AreEqual(1, grid.SelectedRow); + Assert.That(grid.SelectedRow, Is.EqualTo(1)); }); } @@ -152,7 +152,7 @@ public void SwitchingToSingleModeDoesNotBreakUnselecting() grid.SelectRow(1); grid.AllowMultipleSelection = false; grid.UnselectAll(); - Assert.AreEqual(-1, grid.SelectedRow); + Assert.That(grid.SelectedRow, Is.EqualTo(-1)); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectableFilterTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectableFilterTests.cs index 0513d48919..e28d0ff1ac 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectableFilterTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridViewSelectableFilterTests.cs @@ -45,7 +45,7 @@ public void InsertItemShouldNotChangeSelection() grid.SelectRow(0); var selectedItem = grid.SelectedItem; model.Insert(0, new DataItem(model.Count)); - Assert.AreEqual(selectedItem, grid.SelectedItem); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem)); }); } @@ -62,9 +62,9 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = 0; i < initialCount / 2; i++) grid.SelectRow(i); - Assert.AreEqual(initialCount / 2, grid.SelectedRows.Count(), "Number of selected items should be half of the items"); - Assert.AreEqual(initialCount / 2, viewSelectionChangedCount, "View SelectionChanged event should fire for each item selected"); - Assert.AreEqual(initialCount / 2, modelSelectionChangedCount, "Model SelectionChanged event should fire for each item selected"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 2), "Number of selected items should be half of the items"); + Assert.That(viewSelectionChangedCount, Is.EqualTo(initialCount / 2), "View SelectionChanged event should fire for each item selected"); + Assert.That(modelSelectionChangedCount, Is.EqualTo(initialCount / 2), "Model SelectionChanged event should fire for each item selected"); // reset to test events fired when removing modelSelectionChangedCount = viewSelectionChangedCount = 0; @@ -73,14 +73,14 @@ public void DeleteSelectedItemsShouldRemoveSelectedItems() for (var i = initialCount - 1; i >= 0; i -= 2) model.RemoveAt(i); - Assert.AreEqual(initialCount / 4, grid.SelectedRows.Count(), "Number of selected items should be quarter of the original items"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(initialCount / 4), "Number of selected items should be quarter of the original items"); var expectedSelectedItemIds = new List(); for (var i = 0; i < initialCount / 2; i += 2) expectedSelectedItemIds.Add(i); - Assert.IsTrue(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), "Items don't match"); + Assert.That(expectedSelectedItemIds.SequenceEqual(grid.SelectedItems.OfType().Select(x => x.Id).OrderBy(r => r)), Is.True, "Items don't match"); - Assert.AreEqual(initialCount / 4, viewSelectionChangedCount, "View SelectionChanged event should fire for each selected item removed"); - Assert.AreEqual(initialCount / 4, modelSelectionChangedCount, "Model SelectionChanged event should fire for each selected item removed"); + Assert.That(viewSelectionChangedCount, Is.EqualTo(initialCount / 4), "View SelectionChanged event should fire for each selected item removed"); + Assert.That(modelSelectionChangedCount, Is.EqualTo(initialCount / 4), "Model SelectionChanged event should fire for each selected item removed"); }); } @@ -94,17 +94,17 @@ public void SortItemsShouldNotChangeSelection(int rowToSelect) grid.SelectRow(rowToSelect); var selectedItem = filtered[rowToSelect]; - Assert.AreEqual(1, grid.SelectedRows.Count(), "The row was not selected"); - Assert.AreEqual(selectedItem, grid.SelectedItem, "The correct item was not selected"); - Assert.AreEqual(1, viewSelectionChangedCount, "SelectionChanged event should fire once for the selected row"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(1), "The row was not selected"); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem), "The correct item was not selected"); + Assert.That(viewSelectionChangedCount, Is.EqualTo(1), "SelectionChanged event should fire once for the selected row"); viewSelectionChangedCount = 0; // reset the count filtered.Sort = GridViewUtils.SortItemsDescending; - Assert.AreEqual(1, grid.SelectedRows.Count(), "There should still only be a single selected row"); - Assert.AreEqual(selectedItem, grid.SelectedItem, "The selected item should remain the same"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(1), "There should still only be a single selected row"); + Assert.That(grid.SelectedItem, Is.EqualTo(selectedItem), "The selected item should remain the same"); - Assert.AreEqual(0, viewSelectionChangedCount, "SelectionChanged event should not fire when changing the Sort"); + Assert.That(viewSelectionChangedCount, Is.EqualTo(0), "SelectionChanged event should not fire when changing the Sort"); }); } @@ -122,19 +122,19 @@ public void FilterItemsShouldNotChangeSelection() viewSelectionChangedCount = modelSelectionChangedCount = 0; // reset the counts filtered.Filter = GridViewUtils.KeepOddItemsFilter; - Assert.AreEqual(model.Count / 4, grid.SelectedRows.Count(), "A quarter of the items should be selected"); + Assert.That(grid.SelectedRows.Count(), Is.EqualTo(model.Count / 4), "A quarter of the items should be selected"); // view's selected items should change var selectedItems = grid.SelectedItems.OfType().OrderBy(r => r.Id).ToList(); var expectedItems = model.Where((item, row) => row < model.Count / 2 && (row % 2) == 1).ToList(); - Assert.IsTrue(expectedItems.SequenceEqual(selectedItems), "Selected items should only contain items left after filtering"); - Assert.AreEqual(1, viewSelectionChangedCount, "View SelectionChanged event should fire when changing the Filter which removes items"); + Assert.That(expectedItems.SequenceEqual(selectedItems), Is.True, "Selected items should only contain items left after filtering"); + Assert.That(viewSelectionChangedCount, Is.EqualTo(1), "View SelectionChanged event should fire when changing the Filter which removes items"); // model's selected items should not have changed selectedItems = filtered.SelectedItems.OfType().OrderBy(r => r.Id).ToList(); expectedItems = model.Where((item, row) => row < model.Count / 2).ToList(); - Assert.IsTrue(expectedItems.SequenceEqual(selectedItems), "Model's selected items should not have changed"); - Assert.AreEqual(0, modelSelectionChangedCount, "Model SelectionChanged event should not fire when changing filter"); + Assert.That(expectedItems.SequenceEqual(selectedItems), Is.True, "Model's selected items should not have changed"); + Assert.That(modelSelectionChangedCount, Is.EqualTo(0), "Model SelectionChanged event should not fire when changing filter"); }); } @@ -173,9 +173,9 @@ public void SortedCollectionShouldGetCorrectRow() form.Content = grid; }, () => { - Assert.AreEqual(3, grid.SelectedRow, "#1"); - Assert.NotNull(grid.SelectedItem, "#2"); - Assert.AreEqual("Of", ((GridItem)grid.SelectedItem).Values[0], "#3"); + Assert.That(grid.SelectedRow, Is.EqualTo(3), "#1"); + Assert.That(grid.SelectedItem, Is.Not.Null, "#2"); + Assert.That(((GridItem)grid.SelectedItem).Values[0], Is.EqualTo("Of"), "#3"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs index 03e92fd9d8..9c51ae1d3b 100755 --- a/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GridViewTests.cs @@ -82,38 +82,38 @@ public void CellClickShouldHaveMouseInformation() switch (step) { case 0: - Assert.AreEqual(0, e.Column); - Assert.AreEqual(0, e.Row); - Assert.AreEqual(MouseButtons.Primary, e.Buttons); - Assert.AreEqual(Keys.None, e.Modifiers); - Assert.AreEqual(Point.Round(Mouse.Position / 4f), Point.Round(gv.PointToScreen(e.Location) / 4f)); + Assert.That(e.Column, Is.EqualTo(0)); + Assert.That(e.Row, Is.EqualTo(0)); + Assert.That(e.Buttons, Is.EqualTo(MouseButtons.Primary)); + Assert.That(e.Modifiers, Is.EqualTo(Keys.None)); + Assert.That(Point.Round(gv.PointToScreen(e.Location) / 4f), Is.EqualTo(Point.Round(Mouse.Position / 4f))); label.Text = "Now, left click on 1, 0"; step = 1; break; case 1: - Assert.AreEqual(1, e.Column); - Assert.AreEqual(0, e.Row); - Assert.AreEqual(MouseButtons.Primary, e.Buttons); - Assert.AreEqual(Keys.None, e.Modifiers); - Assert.AreEqual(Mouse.Position, gv.PointToScreen(e.Location)); + Assert.That(e.Column, Is.EqualTo(1)); + Assert.That(e.Row, Is.EqualTo(0)); + Assert.That(e.Buttons, Is.EqualTo(MouseButtons.Primary)); + Assert.That(e.Modifiers, Is.EqualTo(Keys.None)); + Assert.That(gv.PointToScreen(e.Location), Is.EqualTo(Mouse.Position)); label.Text = "Now, right click on 1, 1"; step = 2; break; case 2: - Assert.AreEqual(1, e.Column); - Assert.AreEqual(1, e.Row); - Assert.AreEqual(MouseButtons.Alternate, e.Buttons); - Assert.AreEqual(Keys.None, e.Modifiers); - Assert.AreEqual(Mouse.Position, gv.PointToScreen(e.Location)); + Assert.That(e.Column, Is.EqualTo(1)); + Assert.That(e.Row, Is.EqualTo(1)); + Assert.That(e.Buttons, Is.EqualTo(MouseButtons.Alternate)); + Assert.That(e.Modifiers, Is.EqualTo(Keys.None)); + Assert.That(gv.PointToScreen(e.Location), Is.EqualTo(Mouse.Position)); label.Text = "Now, right click on 1, 2 with the shift key pressed"; step = 3; break; case 3: - Assert.AreEqual(1, e.Column); - Assert.AreEqual(2, e.Row); - Assert.AreEqual(MouseButtons.Alternate, e.Buttons); - Assert.AreEqual(Keys.Shift, e.Modifiers); - Assert.AreEqual(Mouse.Position, gv.PointToScreen(e.Location)); + Assert.That(e.Column, Is.EqualTo(1)); + Assert.That(e.Row, Is.EqualTo(2)); + Assert.That(e.Buttons, Is.EqualTo(MouseButtons.Alternate)); + Assert.That(e.Modifiers, Is.EqualTo(Keys.Shift)); + Assert.That(gv.PointToScreen(e.Location), Is.EqualTo(Mouse.Position)); step = 4; form.Close(); break; diff --git a/test/Eto.Test/UnitTests/Forms/Controls/GroupBoxTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/GroupBoxTests.cs index 8323da4516..f6eb1cdb69 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/GroupBoxTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/GroupBoxTests.cs @@ -15,7 +15,7 @@ public void GroupBoxShouldHaveCorrectlySizedContent() return TableLayout.AutoSized(groupBox); }, c => { - Assert.AreEqual(new Size(200, 200), groupBox.Content.Size, "#1 Content Size should auto size to its desired size"); + Assert.That(groupBox.Content.Size, Is.EqualTo(new Size(200, 200)), "#1 Content Size should auto size to its desired size"); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/ImageViewTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/ImageViewTests.cs index 7fca83deba..6957a09d60 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/ImageViewTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/ImageViewTests.cs @@ -109,7 +109,7 @@ public void ImageSizeShouldUpdateImageViewSize(ImageSizeTestCase imageInfo) { var imageView = new ImageView(); imageView.Image = imageInfo.StartImage?.Invoke(); - Assert.AreEqual(new Size(-1, -1), imageView.Size, "#1"); + Assert.That(imageView.Size, Is.EqualTo(new Size(-1, -1)), "#1"); form.ClientSize = new Size(200, 200); form.Content = new StackLayout { Items = { imageView } }; @@ -121,7 +121,7 @@ public void ImageSizeShouldUpdateImageViewSize(ImageSizeTestCase imageInfo) { try { - Assert.AreEqual(imageInfo.UpdateSize(), imageView.Size); + Assert.That(imageView.Size, Is.EqualTo(imageInfo.UpdateSize())); form.Close(); } catch (Exception ex) @@ -131,7 +131,7 @@ public void ImageSizeShouldUpdateImageViewSize(ImageSizeTestCase imageInfo) } }; - Assert.AreEqual(imageInfo.StartSize(), imageView.Size); + Assert.That(imageView.Size, Is.EqualTo(imageInfo.StartSize())); imageView.Image = imageInfo.UpdateImage?.Invoke(); } catch (Exception ex) diff --git a/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs index e61f2143fe..be46f59f96 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs @@ -78,16 +78,16 @@ public void ChangingSelectedIndexMultipleTimesBeforeLoadShouldTriggerChanged() list.SelectedIndexChanged += (sender, e) => changed++; list.DataStore = new [] { "Item 1", "Item 2", "Item 3" }; - Assert.AreEqual(0, changed, "1.1 - Setting data store should not fire selected index"); - Assert.AreEqual(-1, list.SelectedIndex, "1.2"); + Assert.That(changed, Is.EqualTo(0), "1.1 - Setting data store should not fire selected index"); + Assert.That(list.SelectedIndex, Is.EqualTo(-1), "1.2"); list.SelectedIndex = 0; - Assert.AreEqual(1, changed, "2.1 - Setting selected index should trigger event"); - Assert.AreEqual(0, list.SelectedIndex, "2.2"); + Assert.That(changed, Is.EqualTo(1), "2.1 - Setting selected index should trigger event"); + Assert.That(list.SelectedIndex, Is.EqualTo(0), "2.2"); list.SelectedIndex = 1; - Assert.AreEqual(2, changed, "3.1 - Setting selected index again should trigger event again"); - Assert.AreEqual(1, list.SelectedIndex, "3.2"); + Assert.That(changed, Is.EqualTo(2), "3.1 - Setting selected index again should trigger event again"); + Assert.That(list.SelectedIndex, Is.EqualTo(1), "3.2"); } [Test, ManualTest] diff --git a/test/Eto.Test/UnitTests/Forms/Controls/NumericStepperTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/NumericStepperTests.cs index 14a36c24c6..1e7a103862 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/NumericStepperTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/NumericStepperTests.cs @@ -14,11 +14,11 @@ public void DefaultValuesShouldBeCorrect() int valueChanged = 0; numeric.ValueChanged += (sender, e) => valueChanged++; - Assert.AreEqual(double.MinValue, numeric.MinValue, "MinValue should be double.MinValue"); - Assert.AreEqual(double.MaxValue, numeric.MaxValue, "MaxValue should be double.MaxValue"); - Assert.AreEqual(0, numeric.Value, "initial value should be 0"); + Assert.That(numeric.MinValue, Is.EqualTo(double.MinValue), "MinValue should be double.MinValue"); + Assert.That(numeric.MaxValue, Is.EqualTo(double.MaxValue), "MaxValue should be double.MaxValue"); + Assert.That(numeric.Value, Is.EqualTo(0), "initial value should be 0"); - Assert.AreEqual(0, valueChanged, "ValueChanged event should not fire when setting to default values"); + Assert.That(valueChanged, Is.EqualTo(0), "ValueChanged event should not fire when setting to default values"); }); } @@ -34,19 +34,19 @@ public void MinMaxShouldRetainValue() numeric.MinValue = 100; numeric.MaxValue = 1000; - Assert.AreEqual(100, numeric.MinValue, "MinValue should return the same value as set"); - Assert.AreEqual(1000, numeric.MaxValue, "MaxValue should return the same value as set"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event should fire when changing the MinValue"); + Assert.That(numeric.MinValue, Is.EqualTo(100), "MinValue should return the same value as set"); + Assert.That(numeric.MaxValue, Is.EqualTo(1000), "MaxValue should return the same value as set"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event should fire when changing the MinValue"); numeric.MinValue = double.MinValue; numeric.MaxValue = double.MaxValue; numeric.Value = 0; - Assert.AreEqual(double.MinValue, numeric.MinValue, "MinValue should be double.MinValue"); - Assert.AreEqual(double.MaxValue, numeric.MaxValue, "MaxValue should be double.MaxValue"); - Assert.AreEqual(0, numeric.Value, "Value should be back to 0"); + Assert.That(numeric.MinValue, Is.EqualTo(double.MinValue), "MinValue should be double.MinValue"); + Assert.That(numeric.MaxValue, Is.EqualTo(double.MaxValue), "MaxValue should be double.MaxValue"); + Assert.That(numeric.Value, Is.EqualTo(0), "Value should be back to 0"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event should fire when changing the MinValue"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event should fire when changing the MinValue"); }); } @@ -62,33 +62,33 @@ public void ValueShouldBeLimitedToMinMax() numeric.MinValue = 0; numeric.MaxValue = 2000; - Assert.AreEqual(0, numeric.MinValue, "Could not correctly set MinValue"); - Assert.AreEqual(2000, numeric.MaxValue, "Could not correctly set MaxValue"); + Assert.That(numeric.MinValue, Is.EqualTo(0), "Could not correctly set MinValue"); + Assert.That(numeric.MaxValue, Is.EqualTo(2000), "Could not correctly set MaxValue"); numeric.MinValue = 100; - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); - Assert.AreEqual(100, numeric.Value, "Value should be set after MinValue is set"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(100), "Value should be set after MinValue is set"); numeric.Value = 1000; - Assert.AreEqual(1000, numeric.Value, "Could not correctly set Value after Min/Max is set"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(1000), "Could not correctly set Value after Min/Max is set"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); numeric.Value = 2001; - Assert.AreEqual(2000, numeric.Value, "Value should be limited to Min/Max value"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(2000), "Value should be limited to Min/Max value"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); numeric.Value = -1000; - Assert.AreEqual(100, numeric.Value, "Value should be limited to Min/Max value"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(100), "Value should be limited to Min/Max value"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); numeric.MinValue = 1000; - Assert.AreEqual(1000, numeric.Value, "Value should be changed to match new MinValue"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(1000), "Value should be changed to match new MinValue"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); numeric.MinValue = 0; numeric.MaxValue = 500; - Assert.AreEqual(500, numeric.Value, "Value should be changed to match new MaxValue"); - Assert.AreEqual(++currentValueChanged, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(500), "Value should be changed to match new MaxValue"); + Assert.That(valueChanged, Is.EqualTo(++currentValueChanged), "ValueChanged event was not fired the correct number of times"); }); } @@ -107,10 +107,10 @@ public void FractionalMaxValueShouldSetValueCorrectly(double value, double maxVa numeric.DecimalPlaces = decimalPlaces; numeric.Value = value; - Assert.AreEqual(1, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(valueChanged, Is.EqualTo(1), "ValueChanged event was not fired the correct number of times"); numeric.MaxValue = maxValue; - Assert.AreEqual(newValue, numeric.Value, "Value should be changed to match new MaxValue"); - Assert.AreEqual(2, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(newValue), "Value should be changed to match new MaxValue"); + Assert.That(valueChanged, Is.EqualTo(2), "ValueChanged event was not fired the correct number of times"); }); } @@ -130,8 +130,8 @@ public void FractionalMinValueShouldSetValueCorrectly(double value, double minVa numeric.Value = value; numeric.MinValue = minValue; - Assert.AreEqual(newValue, numeric.Value, "Value should be changed to match new MaxValue"); - Assert.AreEqual(2, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(newValue), "Value should be changed to match new MaxValue"); + Assert.That(valueChanged, Is.EqualTo(2), "ValueChanged event was not fired the correct number of times"); }); } @@ -149,8 +149,8 @@ public void ValueShouldBeRoundedToDecimalPlaces(double value, double newValue, i numeric.DecimalPlaces = decimalPlaces; numeric.Value = value; - Assert.AreEqual(newValue, numeric.Value, "Value should be be rounded to the number of decimal places"); - Assert.AreEqual(1, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(newValue), "Value should be be rounded to the number of decimal places"); + Assert.That(valueChanged, Is.EqualTo(1), "ValueChanged event was not fired the correct number of times"); }); } @@ -166,12 +166,12 @@ public void ValueShouldBeRoundedToDecimalPlacesWhenSetAfter(double value, double numeric.ValueChanged += (sender, e) => valueChanged++; numeric.Value = value; - Assert.AreEqual(Math.Round(value, 0), numeric.Value, "Value should be set to the initial value"); + Assert.That(numeric.Value, Is.EqualTo(Math.Round(value, 0)), "Value should be set to the initial value"); numeric.DecimalPlaces = decimalPlaces; - Assert.AreEqual(newValue, numeric.Value, "Value should be be rounded to the number of decimal places"); - Assert.AreEqual(1, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(newValue), "Value should be be rounded to the number of decimal places"); + Assert.That(valueChanged, Is.EqualTo(1), "ValueChanged event was not fired the correct number of times"); }); } @@ -199,12 +199,12 @@ public void MaximumDecimalPlacesShouldAllowMorePreciseNumbers(double value, doub numeric.ValueChanged += (sender, e) => valueChanged++; numeric.Value = value; - Assert.AreEqual(Math.Round(value, maxDecimalPlaces), numeric.Value, "Value should be set to the initial value"); + Assert.That(numeric.Value, Is.EqualTo(Math.Round(value, maxDecimalPlaces)), "Value should be set to the initial value"); numeric.DecimalPlaces = decimalPlaces; - Assert.AreEqual(newValue, numeric.Value, "Value should be rounded to the maximum number of decimal places"); - Assert.AreEqual(1, valueChanged, "ValueChanged event was not fired the correct number of times"); + Assert.That(numeric.Value, Is.EqualTo(newValue), "Value should be rounded to the maximum number of decimal places"); + Assert.That(valueChanged, Is.EqualTo(1), "ValueChanged event was not fired the correct number of times"); }); } @@ -216,25 +216,25 @@ public void MaximumDecimalPlacesShouldUpdateWhenDecimalPlacesIsChanged() var numeric = new NumericStepper(); numeric.DecimalPlaces = 3; - Assert.AreEqual(3, numeric.DecimalPlaces, "DecimalPlaces isn't roundtripping set values"); - Assert.AreEqual(3, numeric.MaximumDecimalPlaces, "MaximumDecimalPlaces should be changed to at minimum DecimalPlaces"); + Assert.That(numeric.DecimalPlaces, Is.EqualTo(3), "DecimalPlaces isn't roundtripping set values"); + Assert.That(numeric.MaximumDecimalPlaces, Is.EqualTo(3), "MaximumDecimalPlaces should be changed to at minimum DecimalPlaces"); numeric.DecimalPlaces = 2; - Assert.AreEqual(2, numeric.DecimalPlaces, "DecimalPlaces isn't roundtripping set values"); - Assert.AreEqual(3, numeric.MaximumDecimalPlaces, "MaximumDecimalPlaces should only be changed when DecimalPlaces is greater than its current value"); + Assert.That(numeric.DecimalPlaces, Is.EqualTo(2), "DecimalPlaces isn't roundtripping set values"); + Assert.That(numeric.MaximumDecimalPlaces, Is.EqualTo(3), "MaximumDecimalPlaces should only be changed when DecimalPlaces is greater than its current value"); numeric.MaximumDecimalPlaces = 2; - Assert.AreEqual(2, numeric.DecimalPlaces, "DecimalPlaces should keep its original value"); - Assert.AreEqual(2, numeric.MaximumDecimalPlaces, "MaximumDecimalPlaces wasn't updated to the new value"); + Assert.That(numeric.DecimalPlaces, Is.EqualTo(2), "DecimalPlaces should keep its original value"); + Assert.That(numeric.MaximumDecimalPlaces, Is.EqualTo(2), "MaximumDecimalPlaces wasn't updated to the new value"); numeric.MaximumDecimalPlaces = 1; - Assert.AreEqual(1, numeric.DecimalPlaces, "DecimalPlaces should be updated to the new value of MaximumDecimalPlaces when its current value is greater"); - Assert.AreEqual(1, numeric.MaximumDecimalPlaces, "MaximumDecimalPlaces wasn't updated to the new value"); + Assert.That(numeric.DecimalPlaces, Is.EqualTo(1), "DecimalPlaces should be updated to the new value of MaximumDecimalPlaces when its current value is greater"); + Assert.That(numeric.MaximumDecimalPlaces, Is.EqualTo(1), "MaximumDecimalPlaces wasn't updated to the new value"); numeric.MaximumDecimalPlaces = 0; - Assert.AreEqual(0, numeric.DecimalPlaces, "DecimalPlaces should be updated to the new value of MaximumDecimalPlaces when its current value is greater"); - Assert.AreEqual(0, numeric.MaximumDecimalPlaces, "MaximumDecimalPlaces wasn't updated to the new value"); + Assert.That(numeric.DecimalPlaces, Is.EqualTo(0), "DecimalPlaces should be updated to the new value of MaximumDecimalPlaces when its current value is greater"); + Assert.That(numeric.MaximumDecimalPlaces, Is.EqualTo(0), "MaximumDecimalPlaces wasn't updated to the new value"); }); } @@ -253,9 +253,9 @@ public void SettingValueInChangedHandlerShouldStick() }, () => { - Assert.AreEqual(0, numericStepper.Value); + Assert.That(numericStepper.Value, Is.EqualTo(0)); numericStepper.Value = 2; - Assert.AreEqual(10, numericStepper.Value); + Assert.That(numericStepper.Value, Is.EqualTo(10)); }); } [Test, ManualTest] @@ -267,7 +267,7 @@ public void SettingValueInChangedHandlerShouldStickWhenTyped() { var label = new Label(); var numericStepper = new NumericStepper(); - Assert.AreEqual(0, numericStepper.Value, "#1"); + Assert.That(numericStepper.Value, Is.EqualTo(0), "#1"); var changedCount = 0; numericStepper.ValueChanged += (sender, e) => { @@ -277,13 +277,13 @@ public void SettingValueInChangedHandlerShouldStickWhenTyped() { changedCount++; if (changedCount == 1) - Assert.AreEqual(2, numericStepper.Value, "#2"); + Assert.That(numericStepper.Value, Is.EqualTo(2), "#2"); else if (changedCount == 2) - Assert.AreEqual(10, numericStepper.Value, "#3"); + Assert.That(numericStepper.Value, Is.EqualTo(10), "#3"); else if (changedCount > 2) Assert.Fail($"#4. ValueChanged should only fire twice. New value is '{numericStepper.Value}' but should stay at 10."); numericStepper.Value = 10; - Assert.AreEqual(10, numericStepper.Value, "#5"); + Assert.That(numericStepper.Value, Is.EqualTo(10), "#5"); Application.Instance.AsyncInvoke(() => label.Text = $"Value is {numericStepper.Value}. ValueChanged called {changedCount} times."); } catch (Exception ex) diff --git a/test/Eto.Test/UnitTests/Forms/Controls/PanelTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/PanelTests.cs index 0c22cc293b..159749b012 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/PanelTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/PanelTests.cs @@ -14,16 +14,16 @@ public void ParentShouldBeSet() var label = new Label { Text = "Label" }; panel1.Content = label; - Assert.AreSame(panel1, label.Parent, "#1"); - Assert.AreSame(panel1, label.VisualParent, "#2"); + Assert.That(panel1, Is.SameAs(label.Parent), "#1"); + Assert.That(panel1, Is.SameAs(label.VisualParent), "#2"); panel1.Content = null; - Assert.AreSame(null, label.Parent, "#2"); - Assert.AreSame(null, label.VisualParent, "#3"); + Assert.That(null, Is.SameAs(label.Parent), "#2"); + Assert.That(null, Is.SameAs(label.VisualParent), "#3"); panel2.Content = label; - Assert.AreSame(panel2, label.Parent, "#3"); - Assert.AreSame(panel2, label.VisualParent, "#4"); + Assert.That(panel2, Is.SameAs(label.Parent), "#3"); + Assert.That(panel2, Is.SameAs(label.VisualParent), "#4"); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonListTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonListTests.cs index ae0661db0d..033447e4a4 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonListTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonListTests.cs @@ -14,21 +14,21 @@ public void ShouldBeAbleToUnselectAll() Items = { "Item 1", "Item 2", "Item 3" }, SelectedIndex = 1 }; - Assert.AreEqual(1, rbl.SelectedIndex, "#1.1"); + Assert.That(rbl.SelectedIndex, Is.EqualTo(1), "#1.1"); return rbl; }, rbl => { - Assert.AreEqual(1, rbl.SelectedIndex, "#2.1"); + Assert.That(rbl.SelectedIndex, Is.EqualTo(1), "#2.1"); rbl.SelectedIndex = -1; - Assert.AreEqual(-1, rbl.SelectedIndex, "#3.1"); + Assert.That(rbl.SelectedIndex, Is.EqualTo(-1), "#3.1"); rbl.SelectedKey = "Item 3"; - Assert.AreEqual(2, rbl.SelectedIndex, "#3.1"); + Assert.That(rbl.SelectedIndex, Is.EqualTo(2), "#3.1"); rbl.SelectedKey = null; - Assert.AreEqual(-1, rbl.SelectedIndex, "#3.1"); + Assert.That(rbl.SelectedIndex, Is.EqualTo(-1), "#3.1"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonTests.cs index ebe8e1b926..c1619f97ca 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/RadioButtonTests.cs @@ -47,7 +47,7 @@ public void RadioButtonGroupsShouldOperateTogether(bool useSeparateContainers) } }); - Assert.IsTrue(success, "Checked values are incorrect"); + Assert.That(success, Is.True, "Checked values are incorrect"); } [Test, ManualTest] @@ -122,30 +122,30 @@ public void RadioButtonGroupsShouldWorkProgrammatically(bool useSeparateContaine }, () => { // none checked is valid - Assert.IsFalse(rb1.Checked, "#1.1"); - Assert.IsFalse(rb2.Checked, "#1.2"); - Assert.IsFalse(rb3.Checked, "#1.3"); - Assert.AreEqual(0, rb1changed, "#1.4"); - Assert.AreEqual(0, rb2changed, "#1.5"); - Assert.AreEqual(0, rb3changed, "#1.6"); + Assert.That(rb1.Checked, Is.False, "#1.1"); + Assert.That(rb2.Checked, Is.False, "#1.2"); + Assert.That(rb3.Checked, Is.False, "#1.3"); + Assert.That(rb1changed, Is.EqualTo(0), "#1.4"); + Assert.That(rb2changed, Is.EqualTo(0), "#1.5"); + Assert.That(rb3changed, Is.EqualTo(0), "#1.6"); rb2.Checked = true; - Assert.IsFalse(rb1.Checked, "#2.1"); - Assert.IsTrue(rb2.Checked, "#2.2"); - Assert.IsFalse(rb3.Checked, "#2.3"); - Assert.AreEqual(0, rb1changed, "#2.4"); - Assert.AreEqual(1, rb2changed, "#2.5"); - Assert.AreEqual(0, rb3changed, "#2.6"); + Assert.That(rb1.Checked, Is.False, "#2.1"); + Assert.That(rb2.Checked, Is.True, "#2.2"); + Assert.That(rb3.Checked, Is.False, "#2.3"); + Assert.That(rb1changed, Is.EqualTo(0), "#2.4"); + Assert.That(rb2changed, Is.EqualTo(1), "#2.5"); + Assert.That(rb3changed, Is.EqualTo(0), "#2.6"); rb3.Checked = true; - Assert.IsFalse(rb1.Checked, "#3.1"); - Assert.IsFalse(rb2.Checked, "#3.2"); - Assert.IsTrue(rb3.Checked, "#3.3"); - Assert.AreEqual(0, rb1changed, "#3.4"); - Assert.AreEqual(2, rb2changed, "#3.5"); - Assert.AreEqual(1, rb3changed, "#3.6"); + Assert.That(rb1.Checked, Is.False, "#3.1"); + Assert.That(rb2.Checked, Is.False, "#3.2"); + Assert.That(rb3.Checked, Is.True, "#3.3"); + Assert.That(rb1changed, Is.EqualTo(0), "#3.4"); + Assert.That(rb2changed, Is.EqualTo(2), "#3.5"); + Assert.That(rb3changed, Is.EqualTo(1), "#3.6"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/RichTextAreaTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/RichTextAreaTests.cs index be70602ad6..a97122707f 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/RichTextAreaTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/RichTextAreaTests.cs @@ -22,38 +22,38 @@ public void CheckSelectionTextCaretAfterSettingRtf() textArea.TextChanged += (sender, e) => textChanged++; textArea.SelectionChanged += (sender, e) => selectionChanged++; textArea.CaretIndexChanged += (sender, e) => caretChanged++; - Assert.AreEqual(Range.FromLength(0, 0), textArea.Selection, "#1"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(0, 0)), "#1"); textArea.Rtf = @"{\rtf1\ansi {Hello \ul Underline \i Italic \b Bold \strike Strike}}"; - Assert.AreEqual(val = "Hello Underline Italic Bold Strike", textArea.Text.TrimEnd(), "#2-1"); - Assert.AreEqual(Range.FromLength(val.Length, 0), textArea.Selection, "#2-2"); - Assert.AreEqual(val.Length, textArea.CaretIndex, "#2-3"); - Assert.AreEqual(1, textChanged, "#2-4"); - Assert.AreEqual(1, selectionChanged, "#2-5"); - Assert.AreEqual(1, caretChanged, "#2-6"); + Assert.That(textArea.Text.TrimEnd(), Is.EqualTo(val = "Hello Underline Italic Bold Strike"), "#2-1"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(val.Length, 0)), "#2-2"); + Assert.That(textArea.CaretIndex, Is.EqualTo(val.Length), "#2-3"); + Assert.That(textChanged, Is.EqualTo(1), "#2-4"); + Assert.That(selectionChanged, Is.EqualTo(1), "#2-5"); + Assert.That(caretChanged, Is.EqualTo(1), "#2-6"); textArea.Selection = Range.FromLength(6, 5); - Assert.AreEqual(Range.FromLength(6, 5), textArea.Selection, "#3-1"); - Assert.AreEqual(6, textArea.CaretIndex, "#3-2"); - Assert.AreEqual(1, textChanged, "#3-3"); - Assert.AreEqual(2, selectionChanged, "#3-4"); - Assert.AreEqual(2, caretChanged, "#3-5"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(6, 5)), "#3-1"); + Assert.That(textArea.CaretIndex, Is.EqualTo(6), "#3-2"); + Assert.That(textChanged, Is.EqualTo(1), "#3-3"); + Assert.That(selectionChanged, Is.EqualTo(2), "#3-4"); + Assert.That(caretChanged, Is.EqualTo(2), "#3-5"); textArea.Rtf = @"{\rtf1\ansi {Some \b other \i text}}"; - Assert.AreEqual(val = "Some other text", textArea.Text.TrimEnd(), "#4-1"); - Assert.AreEqual(Range.FromLength(val.Length, 0), textArea.Selection, "#4-2"); - Assert.AreEqual(val.Length, textArea.CaretIndex, "#4-3"); - Assert.AreEqual(2, textChanged, "#4-4"); - Assert.AreEqual(3, selectionChanged, "#4-5"); - Assert.AreEqual(3, caretChanged, "#4-6"); + Assert.That(textArea.Text.TrimEnd(), Is.EqualTo(val = "Some other text"), "#4-1"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(val.Length, 0)), "#4-2"); + Assert.That(textArea.CaretIndex, Is.EqualTo(val.Length), "#4-3"); + Assert.That(textChanged, Is.EqualTo(2), "#4-4"); + Assert.That(selectionChanged, Is.EqualTo(3), "#4-5"); + Assert.That(caretChanged, Is.EqualTo(3), "#4-6"); } public static void TestSelectionAttributes(RichTextArea richText, string tag, bool italic = false, bool underline = false, bool bold = false, bool strikethrough = false) { - Assert.AreEqual(italic, richText.SelectionItalic, tag + "-1"); - Assert.AreEqual(underline, richText.SelectionUnderline, tag + "-2"); - Assert.AreEqual(bold, richText.SelectionBold, tag + "-3"); - Assert.AreEqual(strikethrough, richText.SelectionStrikethrough, tag + "-4"); + Assert.That(richText.SelectionItalic, Is.EqualTo(italic), tag + "-1"); + Assert.That(richText.SelectionUnderline, Is.EqualTo(underline), tag + "-2"); + Assert.That(richText.SelectionBold, Is.EqualTo(bold), tag + "-3"); + Assert.That(richText.SelectionStrikethrough, Is.EqualTo(strikethrough), tag + "-4"); } [Test] @@ -66,7 +66,7 @@ public void SelectionAttributesShouldBeCorrectWithLoadedRtf() var richText = new RichTextArea(); richText.Rtf = @"{\rtf1\ansi {Hello \ul Underline \i Italic \b Bold \strike Strike}}"; - Assert.AreEqual("Hello Underline Italic Bold Strike", richText.Text.TrimEnd(), "#1"); + Assert.That(richText.Text.TrimEnd(), Is.EqualTo("Hello Underline Italic Bold Strike"), "#1"); richText.CaretIndex = 5; TestSelectionAttributes(richText, "#2"); richText.CaretIndex = 7; @@ -91,11 +91,11 @@ public void NewLineAtEndShouldNotBeRemoved() { // why does WPF always add a newline even when the content doesn't have a newline? richText.Text = val = $"This is{nl}some text"; - Assert.AreEqual(val, richText.Text, "#1"); + Assert.That(richText.Text, Is.EqualTo(val), "#1"); } richText.Text = val = $"This is{nl}some text{nl}"; - Assert.AreEqual(val, richText.Text, "#2"); + Assert.That(richText.Text, Is.EqualTo(val), "#2"); } [Test] @@ -108,15 +108,15 @@ public void SelectionRangeShouldIncludeNewlines() var text = "Hello\nThere\nThis is some text"; richText.Text = text; - Assert.AreEqual(text, richText.Text.TrimEnd(), "#1"); + Assert.That(richText.Text.TrimEnd(), Is.EqualTo(text), "#1"); richText.Selection = range = GetRange(text, "There"); - Assert.AreEqual("There", richText.SelectedText, "#2.2"); - Assert.AreEqual(range, richText.Selection, "#2.1"); + Assert.That(richText.SelectedText, Is.EqualTo("There"), "#2.2"); + Assert.That(richText.Selection, Is.EqualTo(range), "#2.1"); richText.Selection = range = GetRange(text, "is some text"); - Assert.AreEqual("is some text", richText.SelectedText, "#3.2"); - Assert.AreEqual(range, richText.Selection, "#3.1"); + Assert.That(richText.SelectedText, Is.EqualTo("is some text"), "#3.2"); + Assert.That(richText.Selection, Is.EqualTo(range), "#3.1"); } public class FontVariantInfo @@ -418,24 +418,24 @@ public void FontVariantsShouldCorrectlySaveToRtf(FontVariantInfo info) var richText = new RichTextArea(); richText.Text = text; - Assert.AreEqual(text, richText.Text.TrimEnd(), "#1"); + Assert.That(richText.Text.TrimEnd(), Is.EqualTo(text), "#1"); richText.Selection = GetRange(text, "Font Variant"); - Assert.AreEqual("Font Variant", richText.SelectedText, "#2"); + Assert.That(richText.SelectedText, Is.EqualTo("Font Variant"), "#2"); if (info.BaseTypeface != null) { // test base typeface (non-bold/italic) richText.SelectionTypeface = info.BaseTypeface; - Assert.AreEqual(info.BaseTypeface.Name, richText.SelectionTypeface.Name, "#3.1"); - Assert.AreEqual(info.BaseTypeface.Name, richText.SelectionFont.Typeface.Name, "#3.2"); + Assert.That(richText.SelectionTypeface.Name, Is.EqualTo(info.BaseTypeface.Name), "#3.1"); + Assert.That(richText.SelectionFont.Typeface.Name, Is.EqualTo(info.BaseTypeface.Name), "#3.2"); } else { richText.SelectionTypeface = info.Typeface; } - Assert.AreEqual(info.Family.Name, richText.SelectionFamily.Name, "#3.3"); - Assert.AreEqual(info.Family.Name, richText.SelectionFont.FamilyName, "#3.4"); + Assert.That(richText.SelectionFamily.Name, Is.EqualTo(info.Family.Name), "#3.3"); + Assert.That(richText.SelectionFont.FamilyName, Is.EqualTo(info.Family.Name), "#3.4"); // setting these should not affect font name in RTF as it uses \b and \i to specify that if (info.WithBold) @@ -445,15 +445,15 @@ public void FontVariantsShouldCorrectlySaveToRtf(FontVariantInfo info) richText.SelectionItalic = true; // test it is using the right typeface - Assert.AreEqual(info.Typeface.Name, richText.SelectionTypeface.Name, "#4.1"); - Assert.AreEqual(info.Typeface.Name, richText.SelectionFont.Typeface.Name, "#4.2"); + Assert.That(richText.SelectionTypeface.Name, Is.EqualTo(info.Typeface.Name), "#4.1"); + Assert.That(richText.SelectionFont.Typeface.Name, Is.EqualTo(info.Typeface.Name), "#4.2"); // ensure the generated RTF contains the correct font variant name var rtf = richText.Rtf; Console.WriteLine($"Generated RTF:"); Console.WriteLine(rtf); var reg = $@"(?<={{\\fonttbl.*)\\f\d+[^}};]* ({info.RegexFontName});"; - Assert.IsTrue(Regex.IsMatch(rtf, reg), $"#5 - Variant '{info}' does not exist in RTF:\n{rtf}"); + Assert.That(Regex.IsMatch(rtf, reg), Is.True, $"#5 - Variant '{info}' does not exist in RTF:\n{rtf}"); } /// @@ -486,16 +486,16 @@ public void FontVariantsShouldCorrectlyLoadFromRtf(FontVariantInfo info) var richText = new RichTextArea(); richText.Rtf = rtf; - Assert.AreEqual(text, richText.Text.TrimEnd(), "#1"); + Assert.That(richText.Text.TrimEnd(), Is.EqualTo(text), "#1"); // select Font Variant text and ensure it is correctly set richText.Selection = GetRange(text, "Font Variant"); - Assert.AreEqual("Font Variant", richText.SelectedText, "#2"); + Assert.That(richText.SelectedText, Is.EqualTo("Font Variant"), "#2"); - Assert.AreEqual(info.Family.Name, richText.SelectionFamily.Name, "#3.1"); - Assert.AreEqual(info.Family.Name, richText.SelectionFont.FamilyName, "#3.2"); - Assert.AreEqual(info.Typeface.Name, richText.SelectionTypeface.Name, "#3.3"); - Assert.AreEqual(info.Typeface.Name, richText.SelectionFont.Typeface.Name, "#3.4"); + Assert.That(richText.SelectionFamily.Name, Is.EqualTo(info.Family.Name), "#3.1"); + Assert.That(richText.SelectionFont.FamilyName, Is.EqualTo(info.Family.Name), "#3.2"); + Assert.That(richText.SelectionTypeface.Name, Is.EqualTo(info.Typeface.Name), "#3.3"); + Assert.That(richText.SelectionFont.Typeface.Name, Is.EqualTo(info.Typeface.Name), "#3.4"); } [Test] @@ -509,49 +509,49 @@ public void SelectionBoldItalicUnderlineShouldTriggerTextChanged() string text = "This is some underline, strikethrough, bold, and italic text. This is green, background blue text."; richText.Text = text; - Assert.AreEqual(1, textChangedCount); + Assert.That(textChangedCount, Is.EqualTo(1)); richText.Selection = GetRange(text, "underline"); richText.SelectionUnderline = true; - Assert.AreEqual(2, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionUnderline"); - Assert.AreEqual(true, richText.SelectionUnderline); - Assert.AreEqual(false, richText.SelectionStrikethrough); - Assert.AreEqual(false, richText.SelectionBold); - Assert.AreEqual(false, richText.SelectionItalic); + Assert.That(textChangedCount, Is.EqualTo(2), "RichTextArea.TextChanged did not fire when setting SelectionUnderline"); + Assert.That(richText.SelectionUnderline, Is.EqualTo(true)); + Assert.That(richText.SelectionStrikethrough, Is.EqualTo(false)); + Assert.That(richText.SelectionBold, Is.EqualTo(false)); + Assert.That(richText.SelectionItalic, Is.EqualTo(false)); richText.Selection = GetRange(text, "strikethrough"); richText.SelectionStrikethrough = true; - Assert.AreEqual(3, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionStrikethrough"); - Assert.AreEqual(false, richText.SelectionUnderline); - Assert.AreEqual(true, richText.SelectionStrikethrough); - Assert.AreEqual(false, richText.SelectionBold); - Assert.AreEqual(false, richText.SelectionItalic); + Assert.That(textChangedCount, Is.EqualTo(3), "RichTextArea.TextChanged did not fire when setting SelectionStrikethrough"); + Assert.That(richText.SelectionUnderline, Is.EqualTo(false)); + Assert.That(richText.SelectionStrikethrough, Is.EqualTo(true)); + Assert.That(richText.SelectionBold, Is.EqualTo(false)); + Assert.That(richText.SelectionItalic, Is.EqualTo(false)); richText.Selection = GetRange(text, "bold"); richText.SelectionBold = true; - Assert.AreEqual(4, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionBold"); - Assert.AreEqual(false, richText.SelectionUnderline); - Assert.AreEqual(false, richText.SelectionStrikethrough); - Assert.AreEqual(true, richText.SelectionBold); - Assert.AreEqual(false, richText.SelectionItalic); + Assert.That(textChangedCount, Is.EqualTo(4), "RichTextArea.TextChanged did not fire when setting SelectionBold"); + Assert.That(richText.SelectionUnderline, Is.EqualTo(false)); + Assert.That(richText.SelectionStrikethrough, Is.EqualTo(false)); + Assert.That(richText.SelectionBold, Is.EqualTo(true)); + Assert.That(richText.SelectionItalic, Is.EqualTo(false)); richText.Selection = GetRange(text, "italic"); richText.SelectionItalic = true; - Assert.AreEqual(5, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionItalic"); - Assert.AreEqual(false, richText.SelectionUnderline); - Assert.AreEqual(false, richText.SelectionStrikethrough); - Assert.AreEqual(false, richText.SelectionBold); - Assert.AreEqual(true, richText.SelectionItalic); + Assert.That(textChangedCount, Is.EqualTo(5), "RichTextArea.TextChanged did not fire when setting SelectionItalic"); + Assert.That(richText.SelectionUnderline, Is.EqualTo(false)); + Assert.That(richText.SelectionStrikethrough, Is.EqualTo(false)); + Assert.That(richText.SelectionBold, Is.EqualTo(false)); + Assert.That(richText.SelectionItalic, Is.EqualTo(true)); richText.Selection = GetRange(text, "green"); richText.SelectionForeground = Colors.Green; - Assert.AreEqual(6, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionForeground"); - Assert.AreEqual(Colors.Green, richText.SelectionForeground); + Assert.That(textChangedCount, Is.EqualTo(6), "RichTextArea.TextChanged did not fire when setting SelectionForeground"); + Assert.That(richText.SelectionForeground, Is.EqualTo(Colors.Green)); richText.Selection = GetRange(text, "green"); richText.SelectionBackground = Colors.Blue; - Assert.AreEqual(7, textChangedCount, "RichTextArea.TextChanged did not fire when setting SelectionBackground"); - Assert.AreEqual(Colors.Blue, richText.SelectionBackground); + Assert.That(textChangedCount, Is.EqualTo(7), "RichTextArea.TextChanged did not fire when setting SelectionBackground"); + Assert.That(richText.SelectionBackground, Is.EqualTo(Colors.Blue)); } [TestCase(true)] @@ -575,7 +575,7 @@ public void PlainTextShouldInheritBaseFont(bool withFont) richText.Selection = GetRange(text, "Hello"); - Assert.AreEqual(expectedFontSize, richText.SelectionFont.Size); + Assert.That(richText.SelectionFont.Size, Is.EqualTo(expectedFontSize)); } static Range GetRange(string text, string s) => Range.FromLength(text.IndexOf(s, StringComparison.Ordinal), s.Length); @@ -593,9 +593,9 @@ public void ItalicTypefaceShouldApply() var rtf = @"{\rtf1\deff0{\fonttbl{\f0 Arial;}{\f1 Arial Black;}}\fs40 {\f1\i Some Text}\par}"; richText.Rtf = rtf; richText.Selection = GetRange(text, "Text"); - Assert.IsTrue(richText.SelectionItalic, "#1"); - Assert.AreEqual("Arial", richText.SelectionFamily.Name, "#2"); - Assert.AreEqual("Black Oblique", richText.SelectionTypeface.Name, "#3"); + Assert.That(richText.SelectionItalic, Is.True, "#1"); + Assert.That(richText.SelectionFamily.Name, Is.EqualTo("Arial"), "#2"); + Assert.That(richText.SelectionTypeface.Name, Is.EqualTo("Black Oblique"), "#3"); } [Test] @@ -610,7 +610,7 @@ public void EmptyRtfShouldNotCrash() const string rtf = @"{\rtf1\ansi\ansicpg1252{\fonttbl}{\colortbl;\red255\green255\blue255;}}"; richText.Rtf = rtf; - Assert.AreEqual(string.Empty, richText.Text); + Assert.That(richText.Text, Is.EqualTo(string.Empty)); } } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/SegmentedButtonTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/SegmentedButtonTests.cs index e451e23030..14b4fb00c6 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/SegmentedButtonTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/SegmentedButtonTests.cs @@ -36,7 +36,7 @@ public void ClickingSelectedSegmentShouldNotTriggerSelectionChanged() Application.Instance.AsyncInvoke(form.Close); }; - Assert.IsTrue(itemExpected.Selected, "#1.1"); + Assert.That(itemExpected.Selected, Is.True, "#1.1"); form.Content = new StackLayout { @@ -50,13 +50,13 @@ public void ClickingSelectedSegmentShouldNotTriggerSelectionChanged() }; }, -1); - Assert.AreEqual(0, selectedIndexesChangedCount, "#2.1"); - Assert.AreEqual(1, itemClickCount, "#2.2"); - Assert.AreEqual(1, clickCount, "#2.3"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#2.1"); + Assert.That(itemClickCount, Is.EqualTo(1), "#2.2"); + Assert.That(clickCount, Is.EqualTo(1), "#2.3"); - Assert.IsNotNull(itemExpected, "#3.1"); - Assert.AreSame(itemExpected, itemClicked, "#3.2"); - Assert.AreSame(itemExpected, itemItemClicked, "#3.3"); + Assert.That(itemExpected, Is.Not.Null, "#3.1"); + Assert.That(itemExpected, Is.SameAs(itemClicked), "#3.2"); + Assert.That(itemExpected, Is.SameAs(itemItemClicked), "#3.3"); } [Test, InvokeOnUI] @@ -89,33 +89,33 @@ public void SettingMultipleSelectedInSingleModeShouldOnlyHaveOneSelectedItem() segmentedButton.SelectedIndexesChanged += (sender, e) => selectedIndexesChangedCount++; segmentedButton.Items.Add(item1); - Assert.AreEqual(1, selectedIndexesChangedCount, "#1.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#1.1"); segmentedButton.Items.Add(item2); - Assert.AreEqual(2, selectedIndexesChangedCount, "#1.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(2), "#1.2"); segmentedButton.Items.Add(item3); - Assert.AreEqual(3, selectedIndexesChangedCount, "#1.3"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(3), "#1.3"); - Assert.AreEqual(2, segmentedButton.SelectedIndex, "#2.1"); - Assert.AreSame(item3, segmentedButton.SelectedItem, "#2.2"); - CollectionAssert.AreEqual(new[] { item3 }, segmentedButton.SelectedItems, "#2.3"); - CollectionAssert.AreEqual(new[] { 2 }, segmentedButton.SelectedIndexes, "#2.4"); - Assert.AreEqual(3, selectedIndexesChangedCount, "#2.5"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(2), "#2.1"); + Assert.That(item3, Is.SameAs(segmentedButton.SelectedItem), "#2.2"); + Assert.That(segmentedButton.SelectedItems, Is.EqualTo(new[] { item3 }), "#2.3"); + Assert.That(segmentedButton.SelectedIndexes, Is.EqualTo(new[] { 2 }), "#2.4"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(3), "#2.5"); item1.Selected = true; - Assert.AreEqual(0, segmentedButton.SelectedIndex, "#3.1"); - Assert.AreSame(item1, segmentedButton.SelectedItem, "#3.2"); - CollectionAssert.AreEqual(new[] { item1 }, segmentedButton.SelectedItems, "#3.3"); - CollectionAssert.AreEqual(new[] { 0 }, segmentedButton.SelectedIndexes, "#3.4"); - Assert.AreEqual(4, selectedIndexesChangedCount, "#3.5"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(0), "#3.1"); + Assert.That(item1, Is.SameAs(segmentedButton.SelectedItem), "#3.2"); + Assert.That(segmentedButton.SelectedItems, Is.EqualTo(new[] { item1 }), "#3.3"); + Assert.That(segmentedButton.SelectedIndexes, Is.EqualTo(new[] { 0 }), "#3.4"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(4), "#3.5"); item1.Selected = false; - Assert.AreEqual(-1, segmentedButton.SelectedIndex, "#4.1"); - Assert.IsNull(segmentedButton.SelectedItem, "#4.2"); - CollectionAssert.AreEqual(new SegmentedItem[0], segmentedButton.SelectedItems, "#4.3"); - CollectionAssert.AreEqual(new int[0], segmentedButton.SelectedIndexes, "#4.4"); - Assert.AreEqual(5, selectedIndexesChangedCount, "#4.5"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(-1), "#4.1"); + Assert.That(segmentedButton.SelectedItem, Is.Null, "#4.2"); + Assert.That(segmentedButton.SelectedItems, Is.EqualTo(new SegmentedItem[0]), "#4.3"); + Assert.That(segmentedButton.SelectedIndexes, Is.EqualTo(new int[0]), "#4.4"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(5), "#4.5"); } [Test, InvokeOnUI] @@ -134,28 +134,28 @@ public void AddingAndRemovingSelectedItemShouldChangeSelection() // add non-selected item segmentedButton.Items.Add(item1); - Assert.AreEqual(0, selectedIndexesChangedCount, "#1.1"); - Assert.AreEqual(-1, segmentedButton.SelectedIndex, "#1.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#1.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(-1), "#1.2"); // add item that was selected (selection now changed to that item!) segmentedButton.Items.Add(item2); - Assert.AreEqual(1, selectedIndexesChangedCount, "#2.1"); - Assert.AreEqual(1, segmentedButton.SelectedIndex, "#2.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#2.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(1), "#2.2"); // add another item (no change) segmentedButton.Items.Add(item3); - Assert.AreEqual(1, selectedIndexesChangedCount, "#3.1"); - Assert.AreEqual(1, segmentedButton.SelectedIndex, "#3.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#3.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(1), "#3.2"); // remove a non-selected item (no change) segmentedButton.Items.Remove(item3); - Assert.AreEqual(1, selectedIndexesChangedCount, "#4.1"); - Assert.AreEqual(1, segmentedButton.SelectedIndex, "#4.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#4.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(1), "#4.2"); // remove the selected item (change!) segmentedButton.Items.Remove(item2); - Assert.AreEqual(2, selectedIndexesChangedCount, "#5.1"); - Assert.AreEqual(-1, segmentedButton.SelectedIndex, "#5.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(2), "#5.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(-1), "#5.2"); } [Test, InvokeOnUI] @@ -175,29 +175,29 @@ public void ChangingModesShouldUpdateSelection() segmentedButton.SelectedIndexesChanged += (sender, e) => selectedIndexesChangedCount++; // sanity check, in multiple selection last selected is returned - Assert.AreEqual(0, segmentedButton.SelectedIndex, "#1.1"); - Assert.AreEqual(item1, segmentedButton.SelectedItem, "#1.2"); - CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, segmentedButton.SelectedIndexes, "#1.3"); - CollectionAssert.AreEquivalent(new[] { item1, item2, item3 }, segmentedButton.SelectedItems, "#1.4"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(0), "#1.1"); + Assert.That(segmentedButton.SelectedItem, Is.EqualTo(item1), "#1.2"); + Assert.That(segmentedButton.SelectedIndexes, Is.EquivalentTo(new[] { 0, 1, 2 }), "#1.3"); + Assert.That(segmentedButton.SelectedItems, Is.EquivalentTo(new[] { item1, item2, item3 }), "#1.4"); // change mode to single segmentedButton.SelectionMode = SegmentedSelectionMode.Single; - Assert.AreEqual(1, selectedIndexesChangedCount, "#2.1"); - Assert.AreEqual(0, segmentedButton.SelectedIndex, "#2.2"); - Assert.AreEqual(item1, segmentedButton.SelectedItem, "#2.3"); - CollectionAssert.AreEquivalent(new[] { 0 }, segmentedButton.SelectedIndexes, "#2.4"); - CollectionAssert.AreEquivalent(new[] { item1 }, segmentedButton.SelectedItems, "#2.5"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#2.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(0), "#2.2"); + Assert.That(segmentedButton.SelectedItem, Is.EqualTo(item1), "#2.3"); + Assert.That(segmentedButton.SelectedIndexes, Is.EquivalentTo(new[] { 0 }), "#2.4"); + Assert.That(segmentedButton.SelectedItems, Is.EquivalentTo(new[] { item1 }), "#2.5"); // accessing selected items shouldn't trigger anything - Assert.AreEqual(1, selectedIndexesChangedCount, "#3.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#3.1"); // change mode to none segmentedButton.SelectionMode = SegmentedSelectionMode.None; - Assert.AreEqual(2, selectedIndexesChangedCount, "#4.1"); - Assert.AreEqual(-1, segmentedButton.SelectedIndex, "#4.2"); - Assert.AreEqual(null, segmentedButton.SelectedItem, "#4.3"); - CollectionAssert.IsEmpty(segmentedButton.SelectedIndexes, "#4.4"); - CollectionAssert.IsEmpty(segmentedButton.SelectedItems, "#4.5"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(2), "#4.1"); + Assert.That(segmentedButton.SelectedIndex, Is.EqualTo(-1), "#4.2"); + Assert.That(segmentedButton.SelectedItem, Is.EqualTo(null), "#4.3"); + Assert.That(segmentedButton.SelectedIndexes, Is.Empty, "#4.4"); + Assert.That(segmentedButton.SelectedItems, Is.Empty, "#4.5"); } class SegmentedButtonSubclass : SegmentedButton @@ -216,11 +216,11 @@ public void SelectedIndexOverrideShouldTriggerEvent() { var control = new SegmentedButtonSubclass { Items = { "Item1", "Item2", "Item3" }, SelectionMode = SegmentedSelectionMode.Single }; - Assert.AreEqual(0, control.SelectedIndexChangedCount, "#1"); + Assert.That(control.SelectedIndexChangedCount, Is.EqualTo(0), "#1"); control.SelectedIndex = 0; - Assert.AreEqual(1, control.SelectedIndexChangedCount, "#2"); + Assert.That(control.SelectedIndexChangedCount, Is.EqualTo(1), "#2"); } [Test, InvokeOnUI] @@ -233,17 +233,17 @@ public void ChangingSelectionWhenModeIsNoneShouldNotRaiseChangedEvents() control.Items.Add("Item2"); control.Items.Add("Item3"); - Assert.AreEqual(0, selectedIndexesChangedCount, "#1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#1"); control.SelectedIndex = 0; - Assert.AreEqual(-1, control.SelectedIndex, "#2.1"); - Assert.AreEqual(0, selectedIndexesChangedCount, "#2.2"); - CollectionAssert.IsEmpty(control.SelectedIndexes, "#2.3"); + Assert.That(control.SelectedIndex, Is.EqualTo(-1), "#2.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#2.2"); + Assert.That(control.SelectedIndexes, Is.Empty, "#2.3"); control.SelectedIndexes = new[] { 1, 2 }; - Assert.AreEqual(-1, control.SelectedIndex, "#3.1"); - Assert.AreEqual(0, selectedIndexesChangedCount, "#3.2"); - CollectionAssert.IsEmpty(control.SelectedIndexes, "#3.3"); + Assert.That(control.SelectedIndex, Is.EqualTo(-1), "#3.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#3.2"); + Assert.That(control.SelectedIndexes, Is.Empty, "#3.3"); } [Test, ManualTest] @@ -280,15 +280,15 @@ public void ClickingAnItemWhenModeIsNoneShouldNotRaiseChangedEvents() return control; }, allowPass: false); - Assert.AreEqual(1, itemClickWasRaised, "#1.1"); // ensure user actually clicked an item. - Assert.AreEqual(0, selectedIndexesChangedCount, "#1.2"); - CollectionAssert.IsEmpty(selectedItems, "#1.3"); - Assert.AreEqual(-1, selectedIndex, "#1.4"); + Assert.That(itemClickWasRaised, Is.EqualTo(1), "#1.1"); // ensure user actually clicked an item. + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#1.2"); + Assert.That(selectedItems, Is.Empty, "#1.3"); + Assert.That(selectedIndex, Is.EqualTo(-1), "#1.4"); // check item events - Assert.AreEqual(1, itemWasClicked, "#2.1"); - Assert.AreEqual(0, itemSelectedWasChanged, "#2.2"); - Assert.IsFalse(itemIsSelected, "#2.3"); + Assert.That(itemWasClicked, Is.EqualTo(1), "#2.1"); + Assert.That(itemSelectedWasChanged, Is.EqualTo(0), "#2.2"); + Assert.That(itemIsSelected, Is.False, "#2.3"); } class SegmentedModel @@ -344,14 +344,14 @@ public void ClickingAnItemShouldRaiseChangedEvents(SegmentedSelectionMode select control.SelectionMode = selectionMode; control.BindDataContext(c => c.SelectedIndex, (SegmentedModel m) => m.SelectedIndex, DualBindingMode.OneWayToSource); - Assert.AreEqual(1, model.SelectedIndexChangedCount, "#1.1"); // set when binding + Assert.That(model.SelectedIndexChangedCount, Is.EqualTo(1), "#1.1"); // set when binding control.SelectedIndexesChanged += (sender, e) => selectedIndexesChangedCount++; control.SelectedIndexChanged += (sender, e) => selectedIndexChangedCount++; control.Items.Add("Item1"); var item2 = new ButtonSegmentedItem { Text = "Click Me" }; item2.BindDataContext(r => r.Selected, (SegmentedModel m) => m.ItemIsSelected, DualBindingMode.OneWayToSource); - Assert.AreEqual(0, model.ItemIsSelectedChangedCount, "#1.2"); + Assert.That(model.ItemIsSelectedChangedCount, Is.EqualTo(0), "#1.2"); item2.Selected = initiallySelected; item2.Click += (sender, e) => { @@ -378,51 +378,51 @@ public void ClickingAnItemShouldRaiseChangedEvents(SegmentedSelectionMode select Assert.Multiple(() => { // check events on the segmented button control - Assert.AreEqual(1, itemClickWasRaised, "#2.1"); // ensure user actually clicked an item. - Assert.AreEqual(selectedIndex, model.SelectedIndex, "#2.2"); + Assert.That(itemClickWasRaised, Is.EqualTo(1), "#2.1"); // ensure user actually clicked an item. + Assert.That(model.SelectedIndex, Is.EqualTo(selectedIndex), "#2.2"); // check events on the item itself - Assert.AreEqual(1, itemWasClicked, "#2.3"); + Assert.That(itemWasClicked, Is.EqualTo(1), "#2.3"); if (selectionMode == SegmentedSelectionMode.Multiple) { if (initiallySelected) { - Assert.AreEqual(2, selectedIndexChangedCount, "#3.1.1"); - Assert.AreEqual(2, selectedIndexesChangedCount, "#3.1.2"); - Assert.IsFalse(selectedIndex >= 0, "#3.1.3"); - Assert.AreEqual(3, model.SelectedIndexChangedCount, "#3.1.4"); // one for binding, one when item is added, and one when it actually changes. - Assert.IsFalse(model.ItemIsSelected, "#3.1.5"); - Assert.AreEqual(3, model.ItemIsSelectedChangedCount, "#3.1.6"); // one for binding, one when it is set, and one when it actually changes. + Assert.That(selectedIndexChangedCount, Is.EqualTo(2), "#3.1.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(2), "#3.1.2"); + Assert.That(selectedIndex >= 0, Is.False, "#3.1.3"); + Assert.That(model.SelectedIndexChangedCount, Is.EqualTo(3), "#3.1.4"); // one for binding, one when item is added, and one when it actually changes. + Assert.That(model.ItemIsSelected, Is.False, "#3.1.5"); + Assert.That(model.ItemIsSelectedChangedCount, Is.EqualTo(3), "#3.1.6"); // one for binding, one when it is set, and one when it actually changes. } else { - Assert.AreEqual(1, selectedIndexChangedCount, "#3.2.1"); - Assert.AreEqual(1, selectedIndexesChangedCount, "#3.2.2"); - Assert.IsTrue(selectedIndex >= 0, "#3.2.3"); - Assert.AreEqual(2, model.SelectedIndexChangedCount, "#3.2.4"); // one for binding, one when it actually changes. - Assert.IsTrue(model.ItemIsSelected, "#3.2.5"); - Assert.AreEqual(2, model.ItemIsSelectedChangedCount, "#3.2.6"); // one for binding, and one when it actually changes. + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#3.2.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#3.2.2"); + Assert.That(selectedIndex >= 0, Is.True, "#3.2.3"); + Assert.That(model.SelectedIndexChangedCount, Is.EqualTo(2), "#3.2.4"); // one for binding, one when it actually changes. + Assert.That(model.ItemIsSelected, Is.True, "#3.2.5"); + Assert.That(model.ItemIsSelectedChangedCount, Is.EqualTo(2), "#3.2.6"); // one for binding, and one when it actually changes. } - Assert.AreEqual(1, itemSelectedWasChanged, "#3.3.1"); - Assert.AreNotEqual(itemIsSelected, initiallySelected, "#3.3.2"); + Assert.That(itemSelectedWasChanged, Is.EqualTo(1), "#3.3.1"); + Assert.That(itemIsSelected, Is.Not.EqualTo(initiallySelected), "#3.3.2"); } else { - Assert.AreEqual(1, selectedIndexChangedCount, "#4.1.1"); - Assert.AreEqual(1, selectedIndexesChangedCount, "#4.1.2"); - Assert.IsTrue(selectedIndex >= 0, "#4.1.3"); - Assert.AreEqual(2, model.SelectedIndexChangedCount, "#4.1.4"); // one for binding, one when it actually changes. - Assert.IsTrue(model.ItemIsSelected, "#4.1.5"); - Assert.AreEqual(2, model.ItemIsSelectedChangedCount, "#4.1.6"); // set when binding + Assert.That(selectedIndexChangedCount, Is.EqualTo(1), "#4.1.1"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#4.1.2"); + Assert.That(selectedIndex >= 0, Is.True, "#4.1.3"); + Assert.That(model.SelectedIndexChangedCount, Is.EqualTo(2), "#4.1.4"); // one for binding, one when it actually changes. + Assert.That(model.ItemIsSelected, Is.True, "#4.1.5"); + Assert.That(model.ItemIsSelectedChangedCount, Is.EqualTo(2), "#4.1.6"); // set when binding if (initiallySelected) - Assert.AreEqual(0, itemSelectedWasChanged, "#4.2.1"); + Assert.That(itemSelectedWasChanged, Is.EqualTo(0), "#4.2.1"); else - Assert.AreEqual(1, itemSelectedWasChanged, "#4.2.2"); + Assert.That(itemSelectedWasChanged, Is.EqualTo(1), "#4.2.2"); - Assert.IsTrue(itemIsSelected, "#4.2.3"); + Assert.That(itemIsSelected, Is.True, "#4.2.3"); } }); } @@ -446,72 +446,72 @@ public void SelectAllAndClearSelectionShouldTriggerSelectedChanges() item2.Selected = true; var item3 = new ButtonSegmentedItem { Text = "Item3" }; item3.SelectedChanged += (sender, e) => item3SelectedChanged++; - CollectionAssert.IsEmpty(control.SelectedIndexes, "#1.1"); - Assert.AreEqual(-1, control.SelectedIndex, "#1.2"); - Assert.AreEqual(0, selectedIndexesChangedCount, "#1.3"); - Assert.IsFalse(item1.Selected, "#1.4"); - Assert.IsTrue(item2.Selected, "#1.5"); - Assert.IsFalse(item3.Selected, "#1.6"); - Assert.AreEqual(0, item1SelectedChanged, "#1.7.1"); - Assert.AreEqual(1, item2SelectedChanged, "#1.7.2"); - Assert.AreEqual(0, item3SelectedChanged, "#1.7.3"); + Assert.That(control.SelectedIndexes, Is.Empty, "#1.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(-1), "#1.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#1.3"); + Assert.That(item1.Selected, Is.False, "#1.4"); + Assert.That(item2.Selected, Is.True, "#1.5"); + Assert.That(item3.Selected, Is.False, "#1.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(0), "#1.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(1), "#1.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(0), "#1.7.3"); control.Items.Add(item1); - CollectionAssert.IsEmpty(control.SelectedIndexes, "#2.1"); - Assert.AreEqual(-1, control.SelectedIndex, "#2.2"); - Assert.AreEqual(0, selectedIndexesChangedCount, "#2.3"); - Assert.IsFalse(item1.Selected, "#2.4"); - Assert.IsTrue(item2.Selected, "#2.5"); - Assert.IsFalse(item3.Selected, "#2.6"); - Assert.AreEqual(0, item1SelectedChanged, "#2.7.1"); - Assert.AreEqual(1, item2SelectedChanged, "#2.7.2"); - Assert.AreEqual(0, item3SelectedChanged, "#2.7.3"); + Assert.That(control.SelectedIndexes, Is.Empty, "#2.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(-1), "#2.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(0), "#2.3"); + Assert.That(item1.Selected, Is.False, "#2.4"); + Assert.That(item2.Selected, Is.True, "#2.5"); + Assert.That(item3.Selected, Is.False, "#2.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(0), "#2.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(1), "#2.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(0), "#2.7.3"); control.Items.Add(item2); - CollectionAssert.AreEqual(new[] { 1 }, control.SelectedIndexes, "#3.1"); - Assert.AreEqual(1, control.SelectedIndex, "#3.2"); - Assert.AreEqual(1, selectedIndexesChangedCount, "#3.3"); - Assert.IsFalse(item1.Selected, "#3.4"); - Assert.IsTrue(item2.Selected, "#3.5"); - Assert.IsFalse(item3.Selected, "#3.6"); - Assert.AreEqual(0, item1SelectedChanged, "#3.7.1"); - Assert.AreEqual(1, item2SelectedChanged, "#3.7.2"); - Assert.AreEqual(0, item3SelectedChanged, "#3.7.3"); + Assert.That(control.SelectedIndexes, Is.EqualTo(new[] { 1 }), "#3.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(1), "#3.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#3.3"); + Assert.That(item1.Selected, Is.False, "#3.4"); + Assert.That(item2.Selected, Is.True, "#3.5"); + Assert.That(item3.Selected, Is.False, "#3.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(0), "#3.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(1), "#3.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(0), "#3.7.3"); control.Items.Add(item3); // no change - CollectionAssert.AreEqual(new[] { 1 }, control.SelectedIndexes, "#4.1"); - Assert.AreEqual(1, control.SelectedIndex, "#4.2"); - Assert.AreEqual(1, selectedIndexesChangedCount, "#4.3"); - Assert.IsFalse(item1.Selected, "#4.4"); - Assert.IsTrue(item2.Selected, "#4.5"); - Assert.IsFalse(item3.Selected, "#4.6"); - Assert.AreEqual(0, item1SelectedChanged, "#4.7.1"); - Assert.AreEqual(1, item2SelectedChanged, "#4.7.2"); - Assert.AreEqual(0, item3SelectedChanged, "#4.7.3"); + Assert.That(control.SelectedIndexes, Is.EqualTo(new[] { 1 }), "#4.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(1), "#4.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(1), "#4.3"); + Assert.That(item1.Selected, Is.False, "#4.4"); + Assert.That(item2.Selected, Is.True, "#4.5"); + Assert.That(item3.Selected, Is.False, "#4.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(0), "#4.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(1), "#4.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(0), "#4.7.3"); control.SelectAll(); - CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, control.SelectedIndexes, "#5.1"); - Assert.AreEqual(0, control.SelectedIndex, "#5.2"); - Assert.AreEqual(2, selectedIndexesChangedCount, "#5.3"); - Assert.IsTrue(item1.Selected, "#5.4"); - Assert.IsTrue(item2.Selected, "#5.5"); - Assert.IsTrue(item3.Selected, "#5.6"); - Assert.AreEqual(1, item1SelectedChanged, "#5.7.1"); - Assert.AreEqual(1, item2SelectedChanged, "#5.7.2"); - Assert.AreEqual(1, item3SelectedChanged, "#5.7.3"); + Assert.That(control.SelectedIndexes, Is.EquivalentTo(new[] { 0, 1, 2 }), "#5.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(0), "#5.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(2), "#5.3"); + Assert.That(item1.Selected, Is.True, "#5.4"); + Assert.That(item2.Selected, Is.True, "#5.5"); + Assert.That(item3.Selected, Is.True, "#5.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(1), "#5.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(1), "#5.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(1), "#5.7.3"); control.ClearSelection(); - CollectionAssert.IsEmpty(control.SelectedIndexes, "#6.1"); - Assert.AreEqual(-1, control.SelectedIndex, "#6.2"); - Assert.AreEqual(3, selectedIndexesChangedCount, "#6.3"); - Assert.IsFalse(item1.Selected, "#6.4"); - Assert.IsFalse(item2.Selected, "#6.5"); - Assert.IsFalse(item3.Selected, "#6.6"); - Assert.AreEqual(2, item1SelectedChanged, "#6.7.1"); - Assert.AreEqual(2, item2SelectedChanged, "#6.7.2"); - Assert.AreEqual(2, item3SelectedChanged, "#6.7.3"); + Assert.That(control.SelectedIndexes, Is.Empty, "#6.1"); + Assert.That(control.SelectedIndex, Is.EqualTo(-1), "#6.2"); + Assert.That(selectedIndexesChangedCount, Is.EqualTo(3), "#6.3"); + Assert.That(item1.Selected, Is.False, "#6.4"); + Assert.That(item2.Selected, Is.False, "#6.5"); + Assert.That(item3.Selected, Is.False, "#6.6"); + Assert.That(item1SelectedChanged, Is.EqualTo(2), "#6.7.1"); + Assert.That(item2SelectedChanged, Is.EqualTo(2), "#6.7.2"); + Assert.That(item3SelectedChanged, Is.EqualTo(2), "#6.7.3"); } [Test] diff --git a/test/Eto.Test/UnitTests/Forms/Controls/SliderTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/SliderTests.cs index 3f5b564f3a..14d4c8b9af 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/SliderTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/SliderTests.cs @@ -11,11 +11,11 @@ public void TickFrequencyShouldAllowZero() { var slider = new Slider(); slider.TickFrequency = 0; - Assert.AreEqual(0, slider.TickFrequency); + Assert.That(slider.TickFrequency, Is.EqualTo(0)); slider.Value = 10; slider.TickFrequency = 20; - Assert.AreEqual(20, slider.TickFrequency); - Assert.AreEqual(10, slider.Value); + Assert.That(slider.TickFrequency, Is.EqualTo(20)); + Assert.That(slider.Value, Is.EqualTo(10)); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/SplitterTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/SplitterTests.cs index d846835d8b..9d5d2b0fb7 100755 --- a/test/Eto.Test/UnitTests/Forms/Controls/SplitterTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/SplitterTests.cs @@ -39,7 +39,7 @@ public void PositionShouldNotChange(Orientation orient, SplitterFixedPanel fix) }, it => { - Assert.AreEqual(50, it.Position, "Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.Position, Is.EqualTo(50), $"Fix: {fix}; {orient} [replay={replay}]"); if (ReplayTests) replay = !replay; }, replay: ReplayTests); @@ -68,7 +68,7 @@ public void RelativePositionShouldNotChange(Orientation orient, SplitterFixedPan }, it => { - Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.RelativePosition, Is.EqualTo(pos).Within(1e-2), $"Fix: {fix}; {orient} [replay={replay}]"); if (ReplayTests) replay = !replay; }, @@ -99,36 +99,36 @@ public void NoPositionShouldAutoSizeBasic(Orientation orient, SplitterFixedPanel it => { if (orient == Orientation.Horizontal) - Assert.AreEqual(it.Panel1.Height, it.Panel2.Height, - "Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.Panel1.Height, Is.EqualTo(it.Panel2.Height), + $"Height! Fix: {fix}; {orient} [replay={replay}]"); else - Assert.AreEqual(it.Panel1.Width, it.Panel2.Width, - "Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.Panel1.Width, Is.EqualTo(it.Panel2.Width), + $"Width! Fix: {fix}; {orient} [replay={replay}]"); switch (fix) { case SplitterFixedPanel.Panel1: if (orient == Orientation.Horizontal) - Assert.AreEqual(sz.Width, it.Panel1.Width, - "P1.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(sz.Width, Is.EqualTo(it.Panel1.Width), + $"P1.Width! Fix: {fix}; {orient} [replay={replay}]"); else - Assert.AreEqual(sz.Height, it.Panel1.Height, - "P1.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(sz.Height, Is.EqualTo(it.Panel1.Height), + $"P1.Height! Fix: {fix}; {orient} [replay={replay}]"); break; case SplitterFixedPanel.Panel2: if (orient == Orientation.Horizontal) - Assert.AreEqual(sz.Width, it.Panel2.Width, - "P2.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(sz.Width, Is.EqualTo(it.Panel2.Width), + $"P2.Width! Fix: {fix}; {orient} [replay={replay}]"); else - Assert.AreEqual(sz.Height, it.Panel2.Height, - "P2.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(sz.Height, Is.EqualTo(it.Panel2.Height), + $"P2.Height! Fix: {fix}; {orient} [replay={replay}]"); break; case SplitterFixedPanel.None: if (orient == Orientation.Horizontal) - Assert.AreEqual(it.Panel1.Width, it.Panel2.Width, 1, - "Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.Panel1.Width, Is.EqualTo(it.Panel2.Width).Within(1), + $"Width! Fix: {fix}; {orient} [replay={replay}]"); else - Assert.AreEqual(it.Panel1.Height, it.Panel2.Height, 1, - "Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.Panel1.Height, Is.EqualTo(it.Panel2.Height).Within(1), + $"Height! Fix: {fix}; {orient} [replay={replay}]"); break; } if (ReplayTests) @@ -184,10 +184,10 @@ public void NoPositionShouldAutoSizeComplexTest1(Orientation orient, SplitterFix }, it => { - Assert.AreEqual(40, it.Position, $"#1 {fix}; {orient}; Replay:{replay}"); - Assert.AreEqual(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4, it.RelativePosition, "{0}; {1}", $"#2 {fix}; {orient}; Replay:{replay}"); + Assert.That(it.Position, Is.EqualTo(40), $"#1 {fix}; {orient}; Replay:{replay}"); + Assert.That(it.RelativePosition, Is.EqualTo(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4), "{0}; {1}", $"#2 {fix}; {orient}; Replay:{replay}"); var sz = orient == Orientation.Horizontal ? new Size(100 + it.SplitterWidth, 60) : new Size(60, 100 + it.SplitterWidth); - Assert.AreEqual(sz, it.Size, $"#3 {fix}; {orient}; Replay:{replay}"); + Assert.That(it.Size, Is.EqualTo(sz), $"#3 {fix}; {orient}; Replay:{replay}"); if (ReplayTests) replay = !replay; }, replay: ReplayTests); @@ -237,10 +237,10 @@ public void NoPositionShouldAutoSizeComplexTest2(Orientation orient, SplitterFix }, it => { - Assert.AreEqual(40, it.Position, "{0}; {1}", fix, orient); - Assert.AreEqual(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4, it.RelativePosition, "{0}; {1}", fix, orient); + Assert.That(it.Position, Is.EqualTo(40), $"{fix}; {orient}"); + Assert.That(it.RelativePosition, Is.EqualTo(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4), $"{fix}; {orient}"); var sz = orient == Orientation.Horizontal ? new Size(100 + it.SplitterWidth, 60) : new Size(60, 100 + it.SplitterWidth); - Assert.AreEqual(sz, it.Size, "{0}; {1}", fix, orient); + Assert.That(it.Size, Is.EqualTo(sz), $"{fix}; {orient}"); }, replay: ReplayTests); } @@ -273,7 +273,7 @@ public void PositionShouldTrackInitialResize(Orientation orient, SplitterFixedPa it => { double pos = fix == SplitterFixedPanel.None ? 0.5 : 50.0; - Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay); + Assert.That(it.RelativePosition, Is.EqualTo(pos).Within(1e-2), $"Fix: {fix}; {orient} [replay={replay}]"); if (ReplayTests) replay = !replay; }, @@ -368,7 +368,7 @@ public void SplitterShouldRegisterChangeNotifications() } }; }, -1); - Assert.IsTrue(success, message); + Assert.That(success, Is.True, message); } [Test, ManualTest] @@ -437,7 +437,7 @@ public void SplitterChangingShouldAllowRestrictingWithoutArtifacts() return splitter; }); - Assert.IsNull(outOfBounds, $"#1 - Position went out of bounds 100-200, was {outOfBounds}"); + Assert.That(outOfBounds, Is.Null, $"#1 - Position went out of bounds 100-200, was {outOfBounds}"); } [Test, ManualTest] @@ -465,7 +465,7 @@ public void SplitterShouldNotMoveWhenChangingCancelled() }; return splitter; }); - Assert.AreEqual(0, positionChanged, $"#1 - PositionChanged should not fire"); + Assert.That(positionChanged, Is.EqualTo(0), $"#1 - PositionChanged should not fire"); } [TestCase(Orientation.Horizontal)] diff --git a/test/Eto.Test/UnitTests/Forms/Controls/TextAreaTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/TextAreaTests.cs index 1a4149706b..5c37cb71fa 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/TextAreaTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/TextAreaTests.cs @@ -44,25 +44,25 @@ public void CheckSelectionTextCaretAfterSettingText() var textArea = new T(); textArea.TextChanged += (sender, e) => textChanged++; textArea.SelectionChanged += (sender, e) => selectionChanged++; - Assert.AreEqual(Range.FromLength(0, 0), textArea.Selection, "#1"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(0, 0)), "#1"); textArea.Text = val = "Hello there"; - Assert.AreEqual(Range.FromLength(val.Length, 0), textArea.Selection, "#2"); - Assert.AreEqual(val.Length, textArea.CaretIndex, "#3"); - Assert.AreEqual(1, textChanged, "#4"); - Assert.AreEqual(1, selectionChanged, "#5"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(val.Length, 0)), "#2"); + Assert.That(textArea.CaretIndex, Is.EqualTo(val.Length), "#3"); + Assert.That(textChanged, Is.EqualTo(1), "#4"); + Assert.That(selectionChanged, Is.EqualTo(1), "#5"); textArea.Selection = Range.FromLength(6, 5); - Assert.AreEqual(Range.FromLength(6, 5), textArea.Selection, "#6"); - Assert.AreEqual(6, textArea.CaretIndex, "#7"); - Assert.AreEqual(1, textChanged, "#8"); - Assert.AreEqual(2, selectionChanged, "#9"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(6, 5)), "#6"); + Assert.That(textArea.CaretIndex, Is.EqualTo(6), "#7"); + Assert.That(textChanged, Is.EqualTo(1), "#8"); + Assert.That(selectionChanged, Is.EqualTo(2), "#9"); textArea.Text = val = "Some other text"; - Assert.AreEqual(Range.FromLength(val.Length, 0), textArea.Selection, "#10"); - Assert.AreEqual(val.Length, textArea.CaretIndex, "#11"); - Assert.AreEqual(2, textChanged, "#12"); - Assert.AreEqual(3, selectionChanged, "#13"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(val.Length, 0)), "#10"); + Assert.That(textArea.CaretIndex, Is.EqualTo(val.Length), "#11"); + Assert.That(textChanged, Is.EqualTo(2), "#12"); + Assert.That(selectionChanged, Is.EqualTo(3), "#13"); }); } @@ -72,14 +72,14 @@ public void EnabledShouldNotAffectReadOnly() Invoke(() => { var textArea = new T(); - Assert.IsTrue(textArea.Enabled, "#1"); - Assert.IsFalse(textArea.ReadOnly, "#2"); + Assert.That(textArea.Enabled, Is.True, "#1"); + Assert.That(textArea.ReadOnly, Is.False, "#2"); textArea.Enabled = false; - Assert.IsFalse(textArea.Enabled, "#3"); - Assert.IsFalse(textArea.ReadOnly, "#4"); + Assert.That(textArea.Enabled, Is.False, "#3"); + Assert.That(textArea.ReadOnly, Is.False, "#4"); textArea.Enabled = true; - Assert.IsTrue(textArea.Enabled, "#5"); - Assert.IsFalse(textArea.ReadOnly, "#6"); + Assert.That(textArea.Enabled, Is.True, "#5"); + Assert.That(textArea.ReadOnly, Is.False, "#6"); }); } @@ -94,36 +94,36 @@ public void SettingSelectedTextShouldTriggerTextChanged() textArea.TextChanged += (sender, e) => textChangedCount++; textArea.SelectionChanged += (sender, e) => selectionChangedCount++; textArea.Text = "Hello there friend"; - Assert.AreEqual(1, textChangedCount, "#1-1"); - Assert.AreEqual(Range.FromLength(textArea.Text.TrimEnd().Length, 0), textArea.Selection, "#1-2"); - Assert.AreEqual(1, selectionChangedCount, "#1-3"); + Assert.That(textChangedCount, Is.EqualTo(1), "#1-1"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(textArea.Text.TrimEnd().Length, 0)), "#1-2"); + Assert.That(selectionChangedCount, Is.EqualTo(1), "#1-3"); textArea.Selection = Range.FromLength(6, 5); - Assert.AreEqual(1, textChangedCount, "#2-1"); - Assert.AreEqual(2, selectionChangedCount, "#2-2"); - Assert.AreEqual(Range.FromLength(6, 5), textArea.Selection, "#2-3"); + Assert.That(textChangedCount, Is.EqualTo(1), "#2-1"); + Assert.That(selectionChangedCount, Is.EqualTo(2), "#2-2"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(6, 5)), "#2-3"); return textArea; }, textArea => { - Assert.AreEqual(1, textChangedCount, "#4-1"); - Assert.AreEqual(2, selectionChangedCount, "#4-2"); + Assert.That(textChangedCount, Is.EqualTo(1), "#4-1"); + Assert.That(selectionChangedCount, Is.EqualTo(2), "#4-2"); textArea.SelectedText = "my"; - Assert.AreEqual(2, textChangedCount, "#5-1"); - Assert.AreEqual(3, selectionChangedCount, "#5-2"); - Assert.AreEqual("Hello my friend", textArea.Text.TrimEnd(), "#5-3"); - Assert.AreEqual(Range.FromLength(6, 2), textArea.Selection, "#5-4"); + Assert.That(textChangedCount, Is.EqualTo(2), "#5-1"); + Assert.That(selectionChangedCount, Is.EqualTo(3), "#5-2"); + Assert.That(textArea.Text.TrimEnd(), Is.EqualTo("Hello my friend"), "#5-3"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(6, 2)), "#5-4"); textArea.Selection = textArea.Selection.WithLength(textArea.Selection.Length() + 1); - Assert.AreEqual(4, selectionChangedCount, "#6"); + Assert.That(selectionChangedCount, Is.EqualTo(4), "#6"); textArea.SelectedText = null; - Assert.AreEqual(3, textChangedCount, "#7-1"); - Assert.AreEqual(5, selectionChangedCount, "#7-2"); - Assert.AreEqual("Hello friend", textArea.Text.TrimEnd(), "#7-3"); - Assert.AreEqual(Range.FromLength(6, 0), textArea.Selection, "#7-4"); + Assert.That(textChangedCount, Is.EqualTo(3), "#7-1"); + Assert.That(selectionChangedCount, Is.EqualTo(5), "#7-2"); + Assert.That(textArea.Text.TrimEnd(), Is.EqualTo("Hello friend"), "#7-3"); + Assert.That(textArea.Selection, Is.EqualTo(Range.FromLength(6, 0)), "#7-4"); }); } @@ -133,9 +133,9 @@ public void InitialValueOfSelectedTextShouldBeEmptyInsteadOfNull() Invoke(() => { var textArea = new T(); - Assert.AreEqual(string.Empty, textArea.SelectedText, "SelectedText should be empty not null before setting any text"); + Assert.That(textArea.SelectedText, Is.EqualTo(string.Empty), "SelectedText should be empty not null before setting any text"); textArea.Text = "Hello!"; - Assert.AreEqual(string.Empty, textArea.SelectedText, "SelectedText should *still* be empty not null after setting text"); + Assert.That(textArea.SelectedText, Is.EqualTo(string.Empty), "SelectedText should *still* be empty not null after setting text"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/TextBoxTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/TextBoxTests.cs index 9266353723..5f2044220b 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/TextBoxTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/TextBoxTests.cs @@ -42,8 +42,8 @@ public void CaretIndexShouldStartInInitialPosition() var textBox = new T(); textBox.Text = "Hello"; textBox.CaretIndex = 2; - Assert.AreEqual(2, textBox.CaretIndex, "#1"); - Assert.AreEqual(new Range(2, 1), textBox.Selection, "#2"); + Assert.That(textBox.CaretIndex, Is.EqualTo(2), "#1"); + Assert.That(textBox.Selection, Is.EqualTo(new Range(2, 1)), "#2"); return textBox; }); } @@ -56,13 +56,13 @@ public void CaretIndexShouldRetainPositionOnInitialLoad() var textBox = new T(); textBox.Text = "Hello"; textBox.CaretIndex = 2; - Assert.AreEqual(2, textBox.CaretIndex, "#1"); - Assert.AreEqual(new Range(2, 1), textBox.Selection, "#2"); + Assert.That(textBox.CaretIndex, Is.EqualTo(2), "#1"); + Assert.That(textBox.Selection, Is.EqualTo(new Range(2, 1)), "#2"); return textBox; }, textBox => { - Assert.AreEqual(2, textBox.CaretIndex, "#3"); - Assert.AreEqual(new Range(2, 1), textBox.Selection, "#4"); + Assert.That(textBox.CaretIndex, Is.EqualTo(2), "#3"); + Assert.That(textBox.Selection, Is.EqualTo(new Range(2, 1)), "#4"); }); } @@ -76,8 +76,8 @@ public void SelectionShouldStartInInitialPosition() var textBox = new T(); textBox.Text = text; textBox.Selection = selection; - Assert.AreEqual(selection, textBox.Selection, "#1"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#2"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#1"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#2"); return textBox; }); } @@ -92,13 +92,13 @@ public void SelectionShouldRetainPositionOnInitialLoad() var textBox = new T(); textBox.Text = text; textBox.Selection = selection; - Assert.AreEqual(selection, textBox.Selection, "#1"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#2"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#1"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#2"); return textBox; }, textBox => { - Assert.AreEqual(selection, textBox.Selection, "#3"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#4"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#3"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#4"); }); } @@ -113,19 +113,19 @@ public void SelectionShouldBeSetAfterFocus() textBox = new T(); textBox.Text = text; textBox.Selection = selection; - Assert.AreEqual(selection, textBox.Selection, "#1"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#2"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#1"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#2"); form.Content = new TableLayout( new TextBox(), textBox ); }, () => { - Assert.AreEqual(selection, textBox.Selection, "#3"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#4"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#3"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#4"); textBox.Focus(); - Assert.AreEqual(selection, textBox.Selection, "#5"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#6"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#5"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#6"); }); } @@ -139,19 +139,19 @@ public void CaretIndexShouldUpdateSelection() var textBox = new T(); textBox.Text = text; textBox.Selection = selection; - Assert.AreEqual(selection, textBox.Selection, "#1"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#2"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#1"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#2"); textBox.CaretIndex = 2; - Assert.AreEqual(new Range(2, 1), textBox.Selection, "#3"); - Assert.AreEqual(2, textBox.CaretIndex, "#4"); + Assert.That(textBox.Selection, Is.EqualTo(new Range(2, 1)), "#3"); + Assert.That(textBox.CaretIndex, Is.EqualTo(2), "#4"); return textBox; }, textBox => { - Assert.AreEqual(new Range(2, 1), textBox.Selection, "#5"); - Assert.AreEqual(2, textBox.CaretIndex, "#6"); + Assert.That(textBox.Selection, Is.EqualTo(new Range(2, 1)), "#5"); + Assert.That(textBox.CaretIndex, Is.EqualTo(2), "#6"); textBox.Selection = selection; - Assert.AreEqual(selection, textBox.Selection, "#7"); - Assert.AreEqual(selection.Start, textBox.CaretIndex, "#8"); + Assert.That(textBox.Selection, Is.EqualTo(selection), "#7"); + Assert.That(textBox.CaretIndex, Is.EqualTo(selection.Start), "#8"); }); } @@ -167,11 +167,11 @@ public void TextChangingShouldReturnCorrectResults(string oldText, string newTex tb.TextChanging += (sender, e) => args = e; tb.Text = newText; - Assert.IsNotNull(args, "#1"); - Assert.AreEqual(oldText ?? string.Empty, args.OldText, "#2"); - Assert.AreEqual(newText ?? string.Empty, args.NewText, "#3"); - Assert.AreEqual(text, args.Text, "#4"); - Assert.AreEqual(Range.FromLength(rangeStart, rangeLength), args.Range, "#5"); + Assert.That(args, Is.Not.Null, "#1"); + Assert.That(args.OldText, Is.EqualTo(oldText ?? string.Empty), "#2"); + Assert.That(args.NewText, Is.EqualTo(newText ?? string.Empty), "#3"); + Assert.That(args.Text, Is.EqualTo(text), "#4"); + Assert.That(args.Range, Is.EqualTo(Range.FromLength(rangeStart, rangeLength)), "#5"); }); } @@ -197,7 +197,7 @@ public void InsertingTextShouldFireTextChanging(string oldText, string newText, }; tb.Focus(); - Assert.AreEqual(textToSelect, tb.SelectedText, "#1"); + Assert.That(tb.SelectedText, Is.EqualTo(textToSelect), "#1"); new Clipboard().Text = text; @@ -214,11 +214,11 @@ public void InsertingTextShouldFireTextChanging(string oldText, string newText, }; }, -1); - Assert.IsNotNull(args, "#2.1"); - Assert.AreEqual(oldText ?? string.Empty, args.OldText, "#2.2"); - Assert.AreEqual(newText ?? string.Empty, args.NewText, "#2.3"); - Assert.AreEqual(text, args.Text, "#2.4"); - Assert.AreEqual(Range.FromLength(rangeStart, rangeLength), args.Range, "#2.5"); + Assert.That(args, Is.Not.Null, "#2.1"); + Assert.That(args.OldText, Is.EqualTo(oldText ?? string.Empty), "#2.2"); + Assert.That(args.NewText, Is.EqualTo(newText ?? string.Empty), "#2.3"); + Assert.That(args.Text, Is.EqualTo(text), "#2.4"); + Assert.That(args.Range, Is.EqualTo(Range.FromLength(rangeStart, rangeLength)), "#2.5"); } [Test, ManualTest] @@ -267,7 +267,7 @@ public void ManyUpdatesShouldNotCauseHangs() return layout; }); - Assert.Less(maxElapsed, TimeSpan.FromSeconds(1), "There were long pauses in the UI"); + Assert.That(maxElapsed, Is.LessThan(TimeSpan.FromSeconds(1)), "There were long pauses in the UI"); } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/TextChangingEventArgsTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/TextChangingEventArgsTests.cs index 493c25f14a..8e6d24df7d 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/TextChangingEventArgsTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/TextChangingEventArgsTests.cs @@ -24,10 +24,10 @@ public void OldAndNewTextShouldCalculateRangeAndText(string oldText, string newT { var args = new TextChangingEventArgs(oldText, newText, false); - Assert.AreEqual(oldText ?? string.Empty, args.OldText, "#1"); - Assert.AreEqual(newText ?? string.Empty, args.NewText, "#2"); - Assert.AreEqual(Range.FromLength(rangeStart, rangeLength), args.Range, "#3"); - Assert.AreEqual(text, args.Text, "#4"); + Assert.That(args.OldText, Is.EqualTo(oldText ?? string.Empty), "#1"); + Assert.That(args.NewText, Is.EqualTo(newText ?? string.Empty), "#2"); + Assert.That(args.Range, Is.EqualTo(Range.FromLength(rangeStart, rangeLength)), "#3"); + Assert.That(args.Text, Is.EqualTo(text), "#4"); } [TestCaseSource(nameof(GetTextChangingCases))] @@ -35,10 +35,10 @@ public void OldAndRangeShouldCalculateNewText(string oldText, string newText, st { var args = new TextChangingEventArgs(text, Range.FromLength(rangeStart, rangeLength), oldText, false); - Assert.AreEqual(oldText ?? string.Empty, args.OldText, "#1"); - Assert.AreEqual(newText ?? string.Empty, args.NewText, "#2"); - Assert.AreEqual(Range.FromLength(rangeStart, rangeLength), args.Range, "#3"); - Assert.AreEqual(text, args.Text, "#4"); + Assert.That(args.OldText, Is.EqualTo(oldText ?? string.Empty), "#1"); + Assert.That(args.NewText, Is.EqualTo(newText ?? string.Empty), "#2"); + Assert.That(args.Range, Is.EqualTo(Range.FromLength(rangeStart, rangeLength)), "#3"); + Assert.That(args.Text, Is.EqualTo(text), "#4"); } } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/TreeGridViewTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/TreeGridViewTests.cs index 03bf654e47..3a8968a590 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/TreeGridViewTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/TreeGridViewTests.cs @@ -15,8 +15,8 @@ public void SelectedItemsShouldNotCrash() tree.DataStore = new TreeGridItemCollection(); var items = tree.SelectedItems.ToList(); - Assert.IsNotNull(items); - Assert.AreEqual(0, items.Count); + Assert.That(items, Is.Not.Null); + Assert.That(items.Count, Is.EqualTo(0)); }); } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/WebViewTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/WebViewTests.cs index 552912fa83..4745aef977 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/WebViewTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/WebViewTests.cs @@ -54,7 +54,7 @@ public void ExecuteScriptShouldReturnValue() webView => { var value = webView.ExecuteScript("return 'hello';"); - Assert.AreEqual("hello", value, "#1"); + Assert.That(value, Is.EqualTo("hello"), "#1"); }); } @@ -69,7 +69,7 @@ public void ExecuteScriptAsyncShouldReturnValue() async webView => { var value = await webView.ExecuteScriptAsync("return 'hello';"); - Assert.AreEqual("hello", value, "#1"); + Assert.That(value, Is.EqualTo("hello"), "#1"); }); } diff --git a/test/Eto.Test/UnitTests/Forms/DataContextTests.cs b/test/Eto.Test/UnitTests/Forms/DataContextTests.cs index 754d21c1d5..7caa218f04 100644 --- a/test/Eto.Test/UnitTests/Forms/DataContextTests.cs +++ b/test/Eto.Test/UnitTests/Forms/DataContextTests.cs @@ -41,33 +41,33 @@ protected override void Initialize() base.Content = content; - Assert.AreEqual(0, dataContextChanged); - Assert.AreEqual(0, contentDataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(0)); + Assert.That(contentDataContextChanged, Is.EqualTo(0)); Control.DataContext = new MyViewModel2(); // this shouldn't fire data context changes for logical children - Assert.AreEqual(1, dataContextChanged); - Assert.AreEqual(1, contentDataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(contentDataContextChanged, Is.EqualTo(1)); } public override void OnLoad(EventArgs e) { base.OnLoad(e); - Assert.IsInstanceOf(Control.DataContext); - Assert.IsInstanceOf(content.DataContext); + Assert.That(Control.DataContext, Is.InstanceOf()); + Assert.That(content.DataContext, Is.InstanceOf()); Control.DataContext = new MyViewModel2(); // this shouldn't fire data context changes for logical children - Assert.AreEqual(2, dataContextChanged); - Assert.AreEqual(2, contentDataContextChanged); - Assert.IsInstanceOf(Control.DataContext); - Assert.IsInstanceOf(content.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(2)); + Assert.That(contentDataContextChanged, Is.EqualTo(2)); + Assert.That(Control.DataContext, Is.InstanceOf()); + Assert.That(content.DataContext, Is.InstanceOf()); } public override void OnLoadComplete(EventArgs e) { base.OnLoadComplete(e); - Assert.AreEqual(2, dataContextChanged); - Assert.AreEqual(2, contentDataContextChanged); - Assert.IsInstanceOf(Control.DataContext); - Assert.IsInstanceOf(content.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(2)); + Assert.That(contentDataContextChanged, Is.EqualTo(2)); + Assert.That(Control.DataContext, Is.InstanceOf()); + Assert.That(content.DataContext, Is.InstanceOf()); } } @@ -110,12 +110,12 @@ public void DataContextChangedShouldNotFireWhenNoContext() var c = new Panel(); c.DataContextChanged += (sender, e) => dataContextChanged++; form.Content = c; - Assert.AreEqual(0, dataContextChanged); - Assert.IsNull(form.DataContext); - Assert.IsNull(c.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(0)); + Assert.That(form.DataContext, Is.Null); + Assert.That(c.DataContext, Is.Null); }, () => { - Assert.AreEqual(0, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(0)); }); } @@ -129,20 +129,20 @@ public void DataContextChangedShouldFireAfterSet() var c = new Panel(); c.DataContextChanged += (sender, e) => dataContextChanged++; c.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.IsInstanceOf(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(c.DataContext)); c.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(2, dataContextChanged); - Assert.IsInstanceOf(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(2)); + Assert.That(c.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(c.DataContext)); form.Content = c; - Assert.AreEqual(2, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(2)); }, () => { - Assert.AreEqual(2, dataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(2)); }); } @@ -160,21 +160,21 @@ public void DataContextChangedShouldFireForThemedControl() expander.Content = c; form.Content = expander; form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.IsInstanceOf(c.DataContext); - Assert.IsInstanceOf(form.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); - Assert.AreSame(dataContext, form.Content.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.InstanceOf()); + Assert.That(form.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); + Assert.That(dataContext, Is.SameAs(form.Content.DataContext)); return form; }, form => { - Assert.AreEqual(1, dataContextChanged); - Assert.IsInstanceOf(c?.DataContext); - Assert.IsInstanceOf(form.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); - Assert.AreSame(dataContext, form.Content.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c?.DataContext, Is.InstanceOf()); + Assert.That(form.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); + Assert.That(dataContext, Is.SameAs(form.Content.DataContext)); }); } @@ -188,27 +188,27 @@ public void DataContextChangedShouldFireWhenSettingContentAfterLoaded() { form.DataContextChanged += (sender, e) => dataContextChanged++; form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.IsInstanceOf(form.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(form.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(form.DataContext)); return form; }, form => { var c = new Panel(); c.DataContextChanged += (sender, e) => contentDataContextChanged++; form.Content = c; - Assert.AreEqual(1, contentDataContextChanged); - Assert.AreEqual(1, dataContextChanged); - Assert.IsInstanceOf(c.DataContext); - Assert.IsInstanceOf(form.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(contentDataContextChanged, Is.EqualTo(1)); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.InstanceOf()); + Assert.That(form.DataContext, Is.InstanceOf()); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(2, contentDataContextChanged); - Assert.AreEqual(2, dataContextChanged); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(contentDataContextChanged, Is.EqualTo(2)); + Assert.That(dataContextChanged, Is.EqualTo(2)); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); }); } @@ -222,24 +222,24 @@ public void DataContextChangedShouldFireWhenSettingContentAfterLoadedWithThemedC { form.DataContextChanged += (sender, e) => dataContextChanged++; form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); return form; }, form => { var c = new Panel(); c.DataContextChanged += (sender, e) => contentDataContextChanged++; form.Content = new CustomExpander { Content = c }; - Assert.AreEqual(1, contentDataContextChanged); - Assert.AreEqual(1, dataContextChanged); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(contentDataContextChanged, Is.EqualTo(1)); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(2, contentDataContextChanged); - Assert.AreEqual(2, dataContextChanged); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(contentDataContextChanged, Is.EqualTo(2)); + Assert.That(dataContextChanged, Is.EqualTo(2)); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); }); } @@ -255,8 +255,8 @@ public void DataContextChangedShouldFireForChildWithCustomModel() var container = new Panel(); container.DataContextChanged += (sender, e) => dataContextChanged++; container.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.AreSame(dataContext, container.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(dataContext, Is.SameAs(container.DataContext)); var child = new Panel(); child.DataContextChanged += (sender, e) => childDataContextChanged++; @@ -264,13 +264,13 @@ public void DataContextChangedShouldFireForChildWithCustomModel() container.Content = child; form.Content = container; - Assert.AreEqual(1, childDataContextChanged); - Assert.AreSame(dataContext, container.DataContext); - Assert.AreSame(childDataContext, child.DataContext); + Assert.That(childDataContextChanged, Is.EqualTo(1)); + Assert.That(dataContext, Is.SameAs(container.DataContext)); + Assert.That(childDataContext, Is.SameAs(child.DataContext)); }, () => { - Assert.AreEqual(1, dataContextChanged); - Assert.AreEqual(1, childDataContextChanged); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(childDataContextChanged, Is.EqualTo(1)); }); } @@ -291,17 +291,17 @@ public void DataContextChangeShouldFireForControlInStackLayout() Items = { c } }; form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.IsNotNull(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.Not.Null); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); return form; }, form => { - Assert.AreEqual(1, dataContextChanged); - Assert.IsNotNull(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.Not.Null); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); }); } @@ -321,17 +321,17 @@ public void DataContextChangeShouldFireForControlInTableLayout() Rows = { c } }; form.DataContext = dataContext = new MyViewModel(); - Assert.AreEqual(1, dataContextChanged); - Assert.IsNotNull(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.Not.Null); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); return form; }, form => { - Assert.AreEqual(1, dataContextChanged); - Assert.IsNotNull(c.DataContext); - Assert.AreSame(dataContext, c.DataContext); - Assert.AreSame(dataContext, form.DataContext); + Assert.That(dataContextChanged, Is.EqualTo(1)); + Assert.That(c.DataContext, Is.Not.Null); + Assert.That(dataContext, Is.SameAs(c.DataContext)); + Assert.That(dataContext, Is.SameAs(form.DataContext)); }); } @@ -350,31 +350,32 @@ public void DataContextInSubChildShouldNotBeChangedWhenParentIsSet() var parent = new Panel(); parent.DataContextChanged += (sender, e) => parentChanged++; parent.DataContext = new MyViewModel { ID = 1 }; - Assert.AreEqual(1, parentChanged); + Assert.That(parentChanged, Is.EqualTo(1)); var subChild = new Panel(); subChild.DataContextChanged += (sender, e) => subChildChanged++; subChild.DataContext = new MyViewModel { ID = 2 }; - Assert.AreEqual(1, subChildChanged); + Assert.That(subChildChanged, Is.EqualTo(1)); var child = new Panel(); child.DataContextChanged += (sender, e) => childChanged++; - Assert.AreEqual(0, childChanged); + Assert.That(childChanged, Is.EqualTo(0)); child.Content = subChild; - Assert.AreEqual(1, subChildChanged); - Assert.AreEqual(0, childChanged); + Assert.That(subChildChanged, Is.EqualTo(1)); + Assert.That(childChanged, Is.EqualTo(0)); parent.Content = child; - Assert.AreEqual(1, childChanged); - Assert.AreEqual(1, subChildChanged); - Assert.AreEqual(1, parentChanged); - - Assert.IsInstanceOf(parent.DataContext); - Assert.AreEqual(1, ((MyViewModel)parent.DataContext).ID); - Assert.IsInstanceOf(child.DataContext); - Assert.AreEqual(1, ((MyViewModel)child.DataContext).ID); - Assert.IsInstanceOf(subChild.DataContext); - Assert.AreEqual(2, ((MyViewModel)subChild.DataContext).ID); + Assert.That(childChanged, Is.EqualTo(1)); + Assert.That(subChildChanged, Is.EqualTo(1)); + Assert.That(parentChanged, Is.EqualTo(1)); + + Assert.That(parent.DataContext, Is.InstanceOf()); + Assert.That(parent.DataContext, Is.InstanceOf()); + Assert.That(((MyViewModel)parent.DataContext).ID, Is.EqualTo(1)); + Assert.That(child.DataContext, Is.InstanceOf()); + Assert.That(((MyViewModel)child.DataContext).ID, Is.EqualTo(1)); + Assert.That(subChild.DataContext, Is.InstanceOf()); + Assert.That(((MyViewModel)subChild.DataContext).ID, Is.EqualTo(2)); }); } @@ -388,14 +389,14 @@ public void DataContextWithEqualsShouldSet() panel.DataContextChanged += (sender, e) => changed++; panel.DataContext = new MyViewModelWithEquals { ID = 10 }; - Assert.AreEqual(1, changed); + Assert.That(changed, Is.EqualTo(1)); // should be set again, even though they are equal panel.DataContext = new MyViewModelWithEquals { ID = 10 }; - Assert.AreEqual(2, changed); + Assert.That(changed, Is.EqualTo(2)); panel.DataContext = new MyViewModelWithEquals { ID = 20 }; - Assert.AreEqual(3, changed); + Assert.That(changed, Is.EqualTo(3)); }); } @@ -423,7 +424,7 @@ public void ChangingDataContextShouldNotSetValues() => Shown( SelectedIndex = 0 }; dropDown.DataContext = model1; - Assert.AreEqual(0, dropDown.SelectedIndex, "#1"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(0), "#1"); var model2 = new DropDownViewModel { @@ -431,10 +432,10 @@ public void ChangingDataContextShouldNotSetValues() => Shown( SelectedIndex = 1 }; dropDown.DataContext = model2; - Assert.AreEqual(1, dropDown.SelectedIndex, "#2"); + Assert.That(dropDown.SelectedIndex, Is.EqualTo(1), "#2"); - Assert.AreEqual(0, model1.SelectedIndex, "#3 - Model 1 was changed"); - Assert.AreEqual(1, model2.SelectedIndex, "#4 - Model 2 was changed"); + Assert.That(model1.SelectedIndex, Is.EqualTo(0), "#3 - Model 1 was changed"); + Assert.That(model2.SelectedIndex, Is.EqualTo(1), "#4 - Model 2 was changed"); }); [Test] @@ -446,19 +447,19 @@ public void RemovingFromParentShouldTriggerBindingChanged() => Invoke(() => panel.DataContextChanged += (sender, e) => parentDataContextChanged++; panel.DataContext = new MyViewModelWithEquals { ID = 10 }; - Assert.AreEqual(1, parentDataContextChanged); + Assert.That(parentDataContextChanged, Is.EqualTo(1)); var child = new Panel(); child.DataContextChanged += (sender, e) => childDataContextChanged++; panel.Content = child; - Assert.AreEqual(1, childDataContextChanged); - Assert.AreSame(child.DataContext, panel.DataContext); + Assert.That(childDataContextChanged, Is.EqualTo(1)); + Assert.That(child.DataContext, Is.SameAs(panel.DataContext)); panel.Content = null; - Assert.AreEqual(2, childDataContextChanged); - Assert.AreEqual(1, parentDataContextChanged); - Assert.IsNull(child.DataContext); + Assert.That(childDataContextChanged, Is.EqualTo(2)); + Assert.That(parentDataContextChanged, Is.EqualTo(1)); + Assert.That(child.DataContext, Is.Null); }); } } diff --git a/test/Eto.Test/UnitTests/Forms/DefaultStyleProviderTests.cs b/test/Eto.Test/UnitTests/Forms/DefaultStyleProviderTests.cs index 6fd352e5da..116816cbf1 100644 --- a/test/Eto.Test/UnitTests/Forms/DefaultStyleProviderTests.cs +++ b/test/Eto.Test/UnitTests/Forms/DefaultStyleProviderTests.cs @@ -40,9 +40,9 @@ public void BaseClassShouldApplyDefault() style.Add(null, c => c.Visible = false); var label = new Label(); - Assert.IsTrue(label.Visible); + Assert.That(label.Visible, Is.True); provider.ApplyDefault(label); - Assert.IsFalse(label.Visible); + Assert.That(label.Visible, Is.False); } [Test, InvokeOnUI] @@ -53,9 +53,9 @@ public void BaseClassWithStyleShouldApply() style.Add("style", c => c.Visible = false); var label = new Label(); - Assert.IsTrue(label.Visible); + Assert.That(label.Visible, Is.True); provider.ApplyStyle(label, "style"); - Assert.IsFalse(label.Visible); + Assert.That(label.Visible, Is.False); } [Test, InvokeOnUI] @@ -66,9 +66,9 @@ public void OtherClassShouldNotApplyDefault() style.Add