Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ namespace FirebirdSql.Data.FirebirdClient.Tests;
[NoServerCategory]
public class FbParameterCollectionTests
{
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
public void RemoveAtInvalidIndexThrowsArgumentOutOfRangeTest(int index)
{
// IList.RemoveAt: ArgumentOutOfRangeException when "index is not a valid index in the IList".
var command = new FbCommand();
if (index == 1)
{
command.Parameters.Add("@p1", 1);
}

var ex = Assert.Throws<ArgumentOutOfRangeException>(() => command.Parameters.RemoveAt(index));
Assert.AreEqual("index", ex.ParamName);
Assert.AreEqual(index == 1 ? 1 : 0, command.Parameters.Count);
}

[Test]
public void RemoveAtUnknownNameThrowsIndexOutOfRangeTest()
{
var command = new FbCommand();
Assert.Throws<IndexOutOfRangeException>(() => command.Parameters.RemoveAt("@missing"));
}

[Test]
public void AddTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ public override void Remove(object value)

public override void RemoveAt(int index)
{
if (index < 0 || index > Count)
// IList.RemoveAt: ArgumentOutOfRangeException when "index is not a valid index in the IList".
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException("The specified index does not exist.");
throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index does not exist.");
}

var parameter = this[index];
Expand All @@ -266,7 +267,13 @@ public override void RemoveAt(int index)

public override void RemoveAt(string parameterName)
{
RemoveAt(IndexOf(parameterName));
var index = IndexOf(parameterName);
if (index < 0)
{
throw new IndexOutOfRangeException("The specified index does not exist.");
}

RemoveAt(index);
}

public void CopyTo(FbParameter[] array, int index)
Expand Down