Skip to content

Commit

Permalink
Merge pull request #2727 from cwensley/curtis/update-nunit
Browse files Browse the repository at this point in the history
Update to NUnit 4.3.2
  • Loading branch information
cwensley authored Jan 24, 2025
2 parents e0a0918 + 45977ae commit 703d55c
Show file tree
Hide file tree
Showing 91 changed files with 1,661 additions and 1,617 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/Eto.WinForms/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
63 changes: 31 additions & 32 deletions src/Eto.Wpf/Forms/Menu/MenuItemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ interface IMenuItemHandler
{
void Validate();
}

public class EtoKeyGesture : swi.InputGesture
{
public EtoKeyGesture(Func<bool> isEnabled, swi.Key key, swi.ModifierKeys modifiers)
{
_isEnabled = isEnabled ?? throw new ArgumentNullException(nameof(isEnabled));
Key = key;
Modifiers = modifiers;
}

Func<bool> _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
{
Expand Down Expand Up @@ -70,37 +100,6 @@ public string ToolTip
set { Control.ToolTip = value; }
}


class EtoKeyGesture : swi.InputGesture
{
public EtoKeyGesture(MenuItemHandler<TControl, TWidget, TCallback> menuItemHandler, swi.Key key, swi.ModifierKeys modifiers)
{
MenuItemHandler = menuItemHandler;
Key = key;
Modifiers = modifiers;
}

public MenuItemHandler<TControl, TWidget, TCallback> 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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/Eto.Test.Gtk/Eto.Test.Gtk2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit" Version="4.3.2" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion test/Eto.Test.Gtk/Eto.Test.Gtk3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit" Version="4.3.2" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions test/Eto.Test.Gtk/UnitTests/NativeParentWindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down Expand Up @@ -88,7 +88,7 @@ public void DialogShouldAllowAttachingToNativeWindow()
nswindow.MakeKeyAndOrderFront(nswindow);
});
ev.WaitOne();
Assert.IsTrue(passed);
Assert.That(passed, Is.True);
}*/
}
}
2 changes: 1 addition & 1 deletion test/Eto.Test.Mac/Eto.Test.Mac64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<ProjectReference Include="..\..\lib\monomac\src\MonoMac.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/Eto.Test.Mac/Eto.Test.macOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<ProjectReference Include="..\..\src\Eto.Mac\Eto.macOS.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit" Version="4.3.2" />
</ItemGroup>
<ItemGroup>
<Content Include="TestIcon.icns" />
Expand Down
24 changes: 12 additions & 12 deletions test/Eto.Test.Mac/UnitTests/ButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand All @@ -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");
});

}
Expand Down
12 changes: 6 additions & 6 deletions test/Eto.Test.Mac/UnitTests/IconTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions test/Eto.Test.Mac/UnitTests/NativeParentWindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public void DialogShouldAllowAttachingToNativeWindow()
nswindow.MakeKeyAndOrderFront(nswindow);
});
ev.WaitOne();
Assert.IsTrue(passed);
Assert.That(passed, Is.True);
}
}
}
8 changes: 4 additions & 4 deletions test/Eto.Test.Mac/UnitTests/ResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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]
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]
Expand All @@ -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");
}
}
}
48 changes: 24 additions & 24 deletions test/Eto.Test.Mac/UnitTests/RichTextAreaHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Eto.Test.WinForms/Eto.Test.WinForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1938.49" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2957.106" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Expand Down
Loading

0 comments on commit 703d55c

Please sign in to comment.