Skip to content

Commit

Permalink
Handle FeedBacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheng-Li01 committed Dec 9, 2024
1 parent 375e3d7 commit 0e283df
Showing 1 changed file with 26 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,32 @@ public DataGridViewComboBoxCell_ObjectCollectionTests()
}

[WinFormsFact]
public void ObjectCollection_Count_Operations()
public void ObjectCollection_Add_Remove_Operations()
{
_collection.Count.Should().Be(0);

_collection.Add("Item1");
_collection.Add("Item2");
int index1 = _collection.Add("Item1");
int index2 = _collection.Add("Item2");
_collection.Count.Should().Be(2);
index1.Should().Be(0);
index2.Should().Be(1);

_collection.Remove("Item1");
_collection.Count.Should().Be(1);
_collection[0].Should().Be("Item2");

_collection.Add("Item1");
_collection.Remove("Item2");
_collection.Count.Should().Be(1);
_collection[0].Should().Be("Item1");

_collection.Clear();
_collection.Count.Should().Be(0);
}

[WinFormsFact]
public void ObjectCollection_IsReadOnly_ReturnsCorrectValue()
{
public void ObjectCollection_IsReadOnly_ReturnsCorrectValue() =>
_collection.IsReadOnly.Should().BeFalse();
}

[WinFormsFact]
public void ObjectCollection_Add_AddsItemCorrectly()
{
var item = "NewItem";

int index = _collection.Add(item);

index.Should().Be(0);
_collection.Count.Should().Be(1);
_collection[0].Should().Be(item);
}

[WinFormsFact]
public void ObjectCollection_Add_AddsItemInSortedOrder()
Expand Down Expand Up @@ -103,16 +97,6 @@ public void ObjectCollection_AddRange_AddsItemsInSortedOrder()
_collection[2].Should().Be("C");
}

[WinFormsFact]
public void ObjectCollection_AddRange_ThrowsException_WhenItemsContainNull()
{
var items = new object[] { "Item1", null!, "Item3" };

Action action = () => _collection.AddRange(items);

action.Should().Throw<InvalidOperationException>();
}

[WinFormsFact]
public void ObjectCollection_AddRange_DoesNotAddItems_WhenExceptionIsThrown()
{
Expand Down Expand Up @@ -168,9 +152,11 @@ public void ObjectCollection_Indexer_Set_ThrowsException_WhenValueIsNull()
action.Should().Throw<ArgumentNullException>();
}

[WinFormsFact]
public void ObjectCollection_Clear_RemovesAllItems()
[WinFormsTheory]
[BoolData]
public void ObjectCollection_Clear_RemovesAllItems(bool sorted)
{
_comboBoxCell.Sorted = sorted;
_collection.Add("Item1");
_collection.Add("Item2");

Expand All @@ -179,9 +165,11 @@ public void ObjectCollection_Clear_RemovesAllItems()
_collection.Count.Should().Be(0);
}

[WinFormsFact]
public void ObjectCollection_Contains_ReturnsCorrectValue()
[WinFormsTheory]
[BoolData]
public void ObjectCollection_Contains_ReturnsCorrectValue(bool sorted)
{
_comboBoxCell.Sorted = sorted;
var item = "Item1";
_collection.Add(item);

Expand Down Expand Up @@ -278,7 +266,7 @@ public void ObjectCollection_IndexOf_ThrowsException_WhenItemIsNull()

[WinFormsTheory]
[InlineData("Item1", "Item2", false)]
[InlineData("B", "A", true)]
[InlineData("Item2", "Item1", true)]
public void ObjectCollection_Insert_InsertsItemCorrectly_OrInSortedOrder(string item1, string item2, bool sorted)
{
_comboBoxCell.Sorted = sorted;
Expand All @@ -297,9 +285,12 @@ public void ObjectCollection_Insert_InsertsItemCorrectly_OrInSortedOrder(string
}
}

[WinFormsFact]
public void ObjectCollection_Insert_ThrowsException_WhenIndexIsInvalidOrItemIsNull()
[WinFormsTheory]
[BoolData]
public void ObjectCollection_Insert_ThrowsException_WhenIndexIsInvalidOrItemIsNull(bool sorted)
{
_comboBoxCell.Sorted = sorted;

Action actionNegativeIndex = () => _collection.Insert(-1, "Item");
Action actionOutOfRangeIndex = () => _collection.Insert(1, "Item");
Action actionNullItem = () => _collection.Insert(0, null!);
Expand All @@ -309,20 +300,6 @@ public void ObjectCollection_Insert_ThrowsException_WhenIndexIsInvalidOrItemIsNu
actionNullItem.Should().Throw<ArgumentNullException>();
}

[WinFormsFact]
public void ObjectCollection_Remove_RemovesItemCorrectly()
{
var item1 = "Item1";
var item2 = "Item2";
_collection.Add(item1);
_collection.Add(item2);

_collection.Remove(item1);

_collection.Count.Should().Be(1);
_collection[0].Should().Be(item2);
}

[WinFormsFact]
public void ObjectCollection_Remove_DoesNothing_WhenItemDoesNotExist()
{
Expand Down

0 comments on commit 0e283df

Please sign in to comment.