Browse Source

Moving DataGridView ToolTip tests to the Maui test suite (#5639)

pull/5422/head
ArtemTatarinov 4 years ago
committed by GitHub
parent
commit
7cbe0e137a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      Winforms.sln
  2. 68
      src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.cs
  3. 9
      src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.csproj
  4. 1
      src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/System.Windows.Forms.Maui.IntegrationTests.csproj
  5. 37
      src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/WinformsMauiDataGridViewTests.cs
  6. 54
      src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridView.DataGridViewTooltipTests.cs

19
Winforms.sln

@ -182,6 +182,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeHost", "src\System.Wi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeHost.ManagedControl", "src\System.Windows.Forms\tests\IntegrationTests\NativeHost.ManagedControl\NativeHost.ManagedControl.csproj", "{3129970B-A4EB-46AC-B163-18A5557B11BD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiDataGridViewTests", "src\System.Windows.Forms\tests\IntegrationTests\MauiTests\MauiDataGridViewTests\MauiDataGridViewTests.csproj", "{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1058,6 +1060,22 @@ Global
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x64.Build.0 = Release|x64
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x86.ActiveCfg = Release|x86
{3129970B-A4EB-46AC-B163-18A5557B11BD}.Release|x86.Build.0 = Release|x86
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|arm64.ActiveCfg = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|arm64.Build.0 = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|x64.ActiveCfg = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|x64.Build.0 = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|x86.ActiveCfg = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Debug|x86.Build.0 = Debug|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|Any CPU.Build.0 = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|arm64.ActiveCfg = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|arm64.Build.0 = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|x64.ActiveCfg = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|x64.Build.0 = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|x86.ActiveCfg = Release|Any CPU
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1127,6 +1145,7 @@ Global
{714EC82C-D4E0-4E14-9C34-4F270774D384} = {D3AD0BF9-F5E2-4913-9AE3-9C4998F95EA1}
{B68FD1FC-EA37-40F2-BBBD-77577A0A1815} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A}
{3129970B-A4EB-46AC-B163-18A5557B11BD} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A}
{2F9A5C52-52AF-48BE-A544-0ECDD7675F77} = {8F20A905-BD37-4D80-B8DF-FA45276FC23F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}

68
src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.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);
}
}
}

9
src/System.Windows.Forms/tests/IntegrationTests/MauiTests/MauiDataGridViewTests/MauiDataGridViewTests.csproj

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\References.targets"/>
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>

1
src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/System.Windows.Forms.Maui.IntegrationTests.csproj

@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\MauiTests\ImageListTests\MauiImageListTests.csproj" />
<ProjectReference Include="..\MauiTests\MauiButtonTests\MauiButtonTests.csproj" />
<ProjectReference Include="..\MauiTests\MauiDataGridViewTests\MauiDataGridViewTests.csproj" />
<ProjectReference Include="..\MauiTests\MauiComboBoxTests\MauiComboBoxTests.csproj" />
<ProjectReference Include="..\MauiTests\MauiLabelTests\MauiLabelTests.csproj" />
<ProjectReference Include="..\MauiTests\MauiListViewTests\MauiListViewTests.csproj" />

37
src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.Maui.IntegrationTests/WinformsMauiDataGridViewTests.cs

@ -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);
}
}
}

54
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridView.DataGridViewTooltipTests.cs

@ -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");
}
}
}
Loading…
Cancel
Save