Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions XAMLTest.Tests/MouseInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ public void CanRetrieveMouseDoubleClickTime()
Assert.IsTrue(MouseInput.GetDoubleClickTime > TimeSpan.Zero);
}

[TestMethod]
public void DoubleClickTimeIsAccessibleWithoutWinForms()
{
// Verify that GetDoubleClickTime works without needing WinForms reference
TimeSpan doubleClickTime = MouseInput.GetDoubleClickTime;
Assert.IsTrue(doubleClickTime.TotalMilliseconds > 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assert.IsTrue(doubleClickTime.TotalMilliseconds > 0);


// Typical double click time should be between 100ms and 1000ms
Assert.IsTrue(doubleClickTime.TotalMilliseconds >= 100);
Assert.IsTrue(doubleClickTime.TotalMilliseconds <= 1000);
}

}
81 changes: 66 additions & 15 deletions XAMLTest.Tests/SendMouseInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,72 @@ await Wait.For(async () =>
recorder.Success();
}

[TestMethod]
public async Task CanDoubleClickOnButton()
{
await using var recorder = new TestRecorder(App);

await using IEventRegistration registration = await Button.RegisterForEvent(nameof(Control.MouseDoubleClick));

await Wait.For(async () =>
{
await Button.LeftDoubleClick();
var invocations = await registration.GetInvocations();
Assert.IsTrue(invocations.Count > 1);
});

recorder.Success();
[TestMethod]
public async Task CanDoubleClickOnButton()
{
await using var recorder = new TestRecorder(App);

await using IEventRegistration registration = await Button.RegisterForEvent(nameof(Control.MouseDoubleClick));

await Wait.For(async () =>
{
await Button.LeftDoubleClick();
var invocations = await registration.GetInvocations();
Assert.IsTrue(invocations.Count > 1);
});

recorder.Success();
}

[TestMethod]
public async Task CanRightDoubleClickOnButton()
{
await using var recorder = new TestRecorder(App);

await using IEventRegistration registration = await Button.RegisterForEvent(nameof(Control.MouseDoubleClick));

await Wait.For(async () =>
{
await Button.RightDoubleClick();
var invocations = await registration.GetInvocations();
Assert.IsTrue(invocations.Count > 1);
});

recorder.Success();
}

[TestMethod]
public async Task CanMiddleClickOnButton()
{
await using var recorder = new TestRecorder(App);

await using IEventRegistration registration = await Button.RegisterForEvent(nameof(Control.MouseUp));

await Wait.For(async () =>
{
await Button.MiddleClick();
var invocations = await registration.GetInvocations();
Assert.IsTrue(invocations.Count > 0);
});

recorder.Success();
}

[TestMethod]
public async Task CanMiddleDoubleClickOnButton()
{
await using var recorder = new TestRecorder(App);

await using IEventRegistration registration = await Button.RegisterForEvent(nameof(Control.MouseDoubleClick));

await Wait.For(async () =>
{
await Button.MiddleDoubleClick();
var invocations = await registration.GetInvocations();
Assert.IsTrue(invocations.Count > 1);
});

recorder.Success();
}

[TestMethod]
Expand Down
66 changes: 54 additions & 12 deletions XAMLTest/VisualElementMixins.Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,60 @@ public static async Task<Point> LeftDoubleClick(this IVisualElement element,
clickTime);
}

public static async Task<Point> RightClick(this IVisualElement element,
Position position = Position.Center,
int xOffset = 0, int yOffset = 0,
TimeSpan? clickTime = null)
{
return await SendClick(element,
MouseInput.RightDown(),
MouseInput.RightUp(),
position,
xOffset,
yOffset,
clickTime);
public static async Task<Point> RightClick(this IVisualElement element,
Position position = Position.Center,
int xOffset = 0, int yOffset = 0,
TimeSpan? clickTime = null)
{
return await SendClick(element,
MouseInput.RightDown(),
MouseInput.RightUp(),
position,
xOffset,
yOffset,
clickTime);
}

public static async Task<Point> RightDoubleClick(this IVisualElement element,
Position position = Position.Center,
int xOffset = 0, int yOffset = 0,
TimeSpan? clickTime = null)
{
return await SendDoubleClick(element,
MouseInput.RightDown(),
MouseInput.RightUp(),
position,
xOffset,
yOffset,
clickTime);
}

public static async Task<Point> MiddleClick(this IVisualElement element,
Position position = Position.Center,
int xOffset = 0, int yOffset = 0,
TimeSpan? clickTime = null)
{
return await SendClick(element,
MouseInput.MiddleDown(),
MouseInput.MiddleUp(),
position,
xOffset,
yOffset,
clickTime);
}

public static async Task<Point> MiddleDoubleClick(this IVisualElement element,
Position position = Position.Center,
int xOffset = 0, int yOffset = 0,
TimeSpan? clickTime = null)
{
return await SendDoubleClick(element,
MouseInput.MiddleDown(),
MouseInput.MiddleUp(),
position,
xOffset,
yOffset,
clickTime);
}

public static async Task<Point> SendClick(IVisualElement element,
Expand Down
Loading