
committed by
GitHub

No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 134 additions and 54 deletions
-
19Winforms.sln
-
68src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.cs
-
9src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.csproj
-
1src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/System.Windows.Forms.Maui.IntegrationTests.csproj
-
37src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/WinformsMauiDataGridViewTests.cs
-
54src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridView.DataGridViewTooltipTests.cs
@ -0,0 +1,68 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System.Data; |
|||
using System.Windows.Forms.IntegrationTests.Common; |
|||
using ReflectTools; |
|||
using WFCTestLib.Log; |
|||
|
|||
namespace System.Windows.Forms.IntegrationTests.MauiTests |
|||
{ |
|||
public class MauiDataGridViewTests : ReflectBase |
|||
{ |
|||
public MauiDataGridViewTests(string[] args) : base(args) |
|||
{ |
|||
this.BringToForeground(); |
|||
} |
|||
|
|||
public static void Main(string[] args) |
|||
{ |
|||
Thread.CurrentThread.SetCulture("en-US"); |
|||
Application.Run(new MauiDataGridViewTests(args)); |
|||
} |
|||
|
|||
// This test is rather specific: there should be a separate Form to reproduce the issue.
|
|||
// We need to show this Form ourselves, the issue won't reproduce with ReflectBase-inherited Form which is shown automatically while scenarios is being run.
|
|||
[Scenario(true)] |
|||
public ScenarioResult DataGridView_ToolTip_DoesNot_ThrowException(TParams p) |
|||
{ |
|||
using DataTable dataTable = new(); |
|||
dataTable.Columns.Add(columnName: "name"); |
|||
dataTable.Rows.Add(values: "name1"); |
|||
|
|||
// Create DataGridView with DataSource set to dataTable.
|
|||
using DataGridView dataGridView = new(); |
|||
dataGridView.ShowCellToolTips = true; |
|||
dataGridView.DataSource = dataTable; |
|||
|
|||
// Create form and add dataGridView.
|
|||
using Form dialog = new(); |
|||
dialog.Controls.Add(dataGridView); |
|||
|
|||
dialog.Shown += (sender, args) => |
|||
{ |
|||
// Move mouse cursor over any cell of the first row.
|
|||
Cursor.Position = dataGridView.PointToScreen(dataGridView.GetCellDisplayRectangle(columnIndex: 0, rowIndex: 0, cutOverflow: false).Location); |
|||
|
|||
// Close the dialog after a short delay.
|
|||
Task.Delay(millisecondsDelay: 100).ContinueWith((t) => dialog.Close(), TaskScheduler.FromCurrentSynchronizationContext()); |
|||
}; |
|||
|
|||
dialog.ShowDialog(); |
|||
|
|||
var exceptionThrown = false; |
|||
|
|||
try |
|||
{ |
|||
dataTable.AcceptChanges(); |
|||
} |
|||
catch |
|||
{ |
|||
exceptionThrown = true; |
|||
} |
|||
|
|||
return new ScenarioResult(!exceptionThrown); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\References.targets"/> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
</PropertyGroup> |
|||
|
|||
</Project> |
@ -0,0 +1,37 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using Xunit; |
|||
|
|||
namespace System.Windows.Forms.Maui.IntegrationTests |
|||
{ |
|||
/// <summary>
|
|||
/// This class runs a maui executable, which contains one or more scenarios.
|
|||
///
|
|||
/// We want to be able to represent each scenario as a separate xUnit test, but it's not
|
|||
/// possible to run them independently. The workaround is to have a MauiTestRunner execute all
|
|||
/// the scenarios once and store the results, then feed the scenario names in as member data.
|
|||
///
|
|||
/// However, MemberData is resolved before any constructors (even static) are called.
|
|||
/// This means the scenario names will not be available yet.
|
|||
///
|
|||
/// The solution to this is to inherit from MemberDataAttribute and execute custom code
|
|||
/// (running the maui test) before returning the expected data. See MauiMemberDataAttribute.cs for more info.
|
|||
///
|
|||
/// Also [Collection("Maui")] is used put all maui tests in the same collection, which makes them run sequentially
|
|||
/// instead of in parallel. This is to mitigate race conditions when accessing singleton resources such as clipboard or mouse.
|
|||
/// </summary>
|
|||
[Collection("Maui")] |
|||
public class WinformsMauiDataGridViewTests |
|||
{ |
|||
private const string ProjectName = "MauiDataGridViewTests"; |
|||
|
|||
[Theory] |
|||
[MauiData(ProjectName)] |
|||
public void MauiDataGridViewTest(string scenarioName) |
|||
{ |
|||
MauiTestHelper.ValidateScenarioPassed(ProjectName, scenarioName); |
|||
} |
|||
} |
|||
} |
@ -1,54 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System.Data; |
|||
using Xunit; |
|||
|
|||
namespace System.Windows.Forms.Tests |
|||
{ |
|||
public class DataGridView_DataGridViewToolTipTests |
|||
{ |
|||
[WinFormsFact] |
|||
public void DataGridViewToolTip_Get_Not_ThrowsException() |
|||
{ |
|||
DataTable dataTable = new(); |
|||
dataTable.Columns.Add(columnName: "name"); |
|||
dataTable.Rows.Add(values: "name1"); |
|||
|
|||
// create DataGridView with DataSource set to dataTable
|
|||
DataGridView dataGridView = new(); |
|||
dataGridView.ShowCellToolTips = true; |
|||
dataGridView.DataSource = dataTable; |
|||
|
|||
// create form and add dataGridView
|
|||
Form dialog = new(); |
|||
dialog.Controls.Add(dataGridView); |
|||
|
|||
// these two steps can also be done manually after the dialog is shown
|
|||
dialog.Shown += (sender, args) => |
|||
{ |
|||
// 1. move mouse cursor over any cell of the first row
|
|||
Cursor.Position = dataGridView.PointToScreen(dataGridView.GetCellDisplayRectangle(columnIndex: 0, rowIndex: 0, cutOverflow: false).Location); |
|||
|
|||
// 2. close the dialog after a short delay
|
|||
Task.Delay(millisecondsDelay: 100).ContinueWith((t) => dialog.Close(), TaskScheduler.FromCurrentSynchronizationContext()); |
|||
}; |
|||
|
|||
dialog.ShowDialog(); |
|||
|
|||
bool exceptionThrown = false; |
|||
|
|||
try |
|||
{ |
|||
dataTable.AcceptChanges(); |
|||
} |
|||
catch |
|||
{ |
|||
exceptionThrown = true; |
|||
} |
|||
|
|||
Assert.False(exceptionThrown, "Accepting changes on DataTable has thrown an InvalidOperationException because handle of the DataGridView used in Tooltip isn't created"); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue