Skip to content

About

Extends Verify to allow verification of WinForms UIs.

Resources

Code of conduct

Stars

7 stars

Watchers

1 watching

Forks

Latest commit

 

History

1,549 Commits

Folders and files

Repository files navigation

Verify.WinForms

Discussions Build status NuGet Status

Extends Verify to allow verification of WinForms UIs.

See Milestones for release notes.

Sponsors

Entity Framework Extensions

Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.

Entity Framework Extensions

Developed using JetBrains IDEs

JetBrains logo.

NuGet

Usage

[ModuleInitializer]
public static void Init() =>
    VerifyWinForms.Initialize();

snippet source | anchor

Form

A visual element (Form/Control etc) can be verified as follows:

[Test]
public Task FormUsage() =>
    Verify(new MyForm());

snippet source | anchor

With the state of the element being rendered as a verified file:

TheTests.FormUsage.DotNet.verified.png:

A Form is shown as the top-level window it is, but off screen and without being activated (so it does not take the focus), and messages are pumped once. So it is laid out, scaled and drawn as it appears on screen, and its Load and Shown handlers have run. A form that has already been shown is rendered where it is. Either way it is then disposed, without being closed.

Menus and drop-downs

Any ToolStripDropDown can be verified: a ContextMenuStrip, the DropDown of a ToolStripMenuItem or ToolStripDropDownButton, or a plain ToolStripDropDown. It is shown as the popup window it is, but off screen, so it is laid out and drawn (renderer, margins, border) as it appears on screen. It is then closed and disposed.

ContextMenuStrip

A ContextMenuStrip can be verified as follows:

[Test]
public Task ContextMenuStrip()
{
    var menu = new ContextMenuStrip();
    var items = menu.Items;

    items.Add(new ToolStripMenuItem("About"));
    items.Add(new ToolStripMenuItem("Exit"));
    return Verify(menu);
}

snippet source | anchor

With the state of the element being rendered as a verified file:

TheTests.ContextMenuStrip.DotNet.verified.png:

ToolStripDropDownMenu

The menu of a ToolStripDropDownButton (or of a ToolStripMenuItem) can be verified via its DropDown:

[Test]
public Task ToolStripDropDownMenu()
{
    var button = new ToolStripDropDownButton("File");
    var items = button.DropDownItems;

    items.Add(new ToolStripMenuItem("New"));
    items.Add(
        new ToolStripMenuItem("Word Wrap")
        {
            Checked = true
        });
    items.Add(new ToolStripSeparator());
    items.Add(new ToolStripMenuItem("Exit"));
    return Verify(button.DropDown);
}

snippet source | anchor

With the state of the element being rendered as a verified file:

TheTests.ToolStripDropDownMenu.DotNet.verified.png:

Disposal

Whatever is verified (a Form, a ToolStripDropDown, a UserControl, or any other Control) is disposed once it has been rendered. So there is no need to dispose it in the test, and it cannot be used, or verified, again after the Verify call. A form is disposed without being closed, so its FormClosing and FormClosed events are not raised.

OS specific rendering

The rendering of Form elements can very slightly between different OS versions. This can make verification on different machines (eg CI) problematic. There are several approaches to mitigate this:

Icon

Gem designed by Adnen Kadri from The Noun Project.

About

Extends Verify to allow verification of WinForms UIs.

Resources

Code of conduct

Stars

7 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages