Skip to content
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ namespace System.Windows.Forms.Tests;

[Collection("Sequential")]
[CollectionDefinition("Sequential", DisableParallelization = true)]
public partial class ClipboardTests
public class ClipboardTests
{
[WinFormsFact]
public void Clipboard_SetText_InvokeString_GetReturnsExpected()
{
Clipboard.SetText("text");
Clipboard.GetText().Should().Be("text");
Clipboard.ContainsText().Should().BeTrue();
}

[WinFormsFact]
public void Clipboard_Clear_InvokeMultipleTimes_Success()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

namespace System.Windows.Forms.Tests;

public partial class DataGridViewCellTests
{
[Collection("Sequential")]
public class ClipboardTests
{
public static TheoryData<int, bool, bool, bool, bool, string?, object?> GetClipboardContent_TheoryData() => new()
{
{ -2, true, true, true, true, "format", null },
{ -2, true, true, true, true, null, null },
{ -1, true, true, true, true, "format", null },
{ -1, true, true, true, true, null, null },
{ 0, true, true, true, true, "format", null },
{ 0, true, true, true, true, null, null },
};

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_TheoryData))]
public void DataGridViewCell_GetClipboardContent_Invoke_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected)
{
using SubDataGridViewCell cell = new();
cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected);
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_TheoryData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithRow_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected)
{
using DataGridViewRow row = new();
using SubDataGridViewCell cell = new();
row.Cells.Add(cell);
cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected);
}

public static TheoryData<bool, bool, bool, bool, string?, object?> GetClipboardContent_WithColumn_TheoryData() => new()
{
{ true, true, true, true, "format", null },
{ true, true, true, true, null, null }
};

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithColumn_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected)
{
using DataGridViewColumn column = new();
using SubDataGridViewColumnHeaderCell cell = new();
column.HeaderCell = cell;
cell.GetClipboardContent(-1, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected);
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithDataGridView_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0];
cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected);
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))]
public void DataGridViewCell_GetClipboardContent_InvokeShared_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0];
cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected);
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(0)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithColumn_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using DataGridViewColumn column = new();
using SubDataGridViewColumnHeaderCell cell = new();
column.HeaderCell = cell;
Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format");
action.Should().Throw<ArgumentOutOfRangeException>().WithParameterName("rowIndex");
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(-1)]
[InlineData(1)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithDataGridView_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0];
Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format");
action.Should().Throw<ArgumentOutOfRangeException>().WithParameterName("rowIndex");
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(-1)]
[InlineData(1)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexShared_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0];
Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format");
action.Should().Throw<ArgumentOutOfRangeException>().WithParameterName("rowIndex");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace System.Windows.Forms.Tests;

public class DataGridViewCellTests
public partial class DataGridViewCellTests
{
[WinFormsFact]
public void DataGridViewCell_Ctor_Default()
Expand Down Expand Up @@ -3561,125 +3561,6 @@ public void DataGridViewCell_EnterUnsharesRow_Invoke_ReturnsFalse()
Assert.False(cell.EnterUnsharesRow(-1, true));
}

public static IEnumerable<object[]> GetClipboardContent_TestData()
{
yield return new object[] { -2, true, true, true, true, "format", null };
yield return new object[] { -2, true, true, true, true, null, null };
yield return new object[] { -1, true, true, true, true, "format", null };
yield return new object[] { -1, true, true, true, true, null, null };
yield return new object[] { 0, true, true, true, true, "format", null };
yield return new object[] { 0, true, true, true, true, null, null };
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_TestData))]
public void DataGridViewCell_GetClipboardContent_Invoke_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected)
{
using SubDataGridViewCell cell = new();
Assert.Equal(expected, cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format));
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_TestData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithRow_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected)
{
using DataGridViewRow row = new();
using SubDataGridViewCell cell = new();
row.Cells.Add(cell);
Assert.Equal(expected, cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format));
}

public static IEnumerable<object[]> GetClipboardContent_WithColumn_TestData()
{
yield return new object[] { true, true, true, true, "format", null };
yield return new object[] { true, true, true, true, null, null };
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TestData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithColumn_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected)
{
using DataGridViewColumn column = new();
using SubDataGridViewColumnHeaderCell cell = new();
column.HeaderCell = cell;
Assert.Equal(expected, cell.GetClipboardContent(-1, firstCell, lastCell, inFirstRow, inLastRow, format));
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TestData))]
public void DataGridViewCell_GetClipboardContent_InvokeWithDataGridView_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0];
Assert.Equal(expected, cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format));
}

[WinFormsTheory]
[MemberData(nameof(GetClipboardContent_WithColumn_TestData))]
public void DataGridViewCell_GetClipboardContent_InvokeShared_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0];
Assert.Equal(expected, cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format));
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(0)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithColumn_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using DataGridViewColumn column = new();
using SubDataGridViewColumnHeaderCell cell = new();
column.HeaderCell = cell;
Assert.Throws<ArgumentOutOfRangeException>("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"));
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(-1)]
[InlineData(1)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithDataGridView_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0];
Assert.Throws<ArgumentOutOfRangeException>("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"));
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(-1)]
[InlineData(1)]
public void DataGridViewCell_GetClipboardContent_InvalidRowIndexShared_ThrowsArgumentOutOfRangeException(int rowIndex)
{
using SubDataGridViewCell cellTemplate = new();
using DataGridViewColumn column = new()
{
CellTemplate = cellTemplate
};
using DataGridView control = new();
control.Columns.Add(column);
SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0];
Assert.Throws<ArgumentOutOfRangeException>("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"));
}

[WinFormsTheory]
[InlineData(-2)]
[InlineData(-1)]
Expand Down Expand Up @@ -6613,9 +6494,9 @@ public SubDataGridViewCheckBoxCell()

protected override AccessibleObject CreateAccessibilityInstance() => MockAccessibleObject;

public void MouseClick(DataGridViewCellMouseEventArgs e) => base.OnMouseUpInternal(e);
public void MouseClick(DataGridViewCellMouseEventArgs e) => OnMouseUpInternal(e);

public void OnKeyClick(KeyEventArgs e, int rowIndex) => base.OnKeyUp(e, rowIndex);
public void OnKeyClick(KeyEventArgs e, int rowIndex) => OnKeyUp(e, rowIndex);
}

private class SubDataGridViewColumnHeaderCell : DataGridViewColumnHeaderCell
Expand Down
Loading