Skip to content

Commit

Permalink
Include derived types of ArgumentException in DataStreamTest when rea…
Browse files Browse the repository at this point in the history
…ding past end of stream (#1404)

* Update DataStreamTest.cs

* Update DataStreamTest.cs

* Update src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs

Co-authored-by: DavoudEshtehari <61173489+DavoudEshtehari@users.noreply.github.com>

Co-authored-by: DavoudEshtehari <61173489+DavoudEshtehari@users.noreply.github.com>
  • Loading branch information
Johnny Pham and DavoudEshtehari authored Nov 24, 2021
1 parent 6c6c76c commit 43f7880
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,13 @@ private static void ReadStream(string connectionString)
DataTestUtility.AssertThrowsWrapper<ArgumentNullException>(() => stream.Read(null, 0, 1));
DataTestUtility.AssertThrowsWrapper<ArgumentOutOfRangeException>(() => stream.Read(buffer, -1, 2));
DataTestUtility.AssertThrowsWrapper<ArgumentOutOfRangeException>(() => stream.Read(buffer, 2, -1));
DataTestUtility.AssertThrowsWrapper<ArgumentException>(() => stream.Read(buffer, buffer.Length, buffer.Length));
DataTestUtility.AssertThrowsWrapper<ArgumentException>(() => stream.Read(buffer, int.MaxValue, int.MaxValue));

// ArgumentException is thrown in net5 and earlier. ArgumentOutOfRangeException in net6 and later
Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException),
"Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later.");
ex = Assert.ThrowsAny<ArgumentException>(() => stream.Read(buffer, int.MaxValue, int.MaxValue));
Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException),
"Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later.");
}

// Once Reader is closed
Expand Down

0 comments on commit 43f7880

Please sign in to comment.