Skip to content

Commit 27c56af

Browse files
authored
Tests | Add test to SqlNotificationRequest to address code coverage (#1367)
1 parent 5bf73f1 commit 27c56af

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Compile Include="SqlDataRecordTest.cs" />
4747
<Compile Include="SqlExceptionTest.cs" />
4848
<Compile Include="SqlFacetAttributeTest.cs" />
49+
<Compile Include="SqlNotificationRequestTest.cs" />
4950
<Compile Include="SqlParameterTest.cs" />
5051
<Compile Include="SqlClientFactoryTest.cs" />
5152
<Compile Include="SqlErrorCollectionTest.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using Microsoft.Data.Sql;
3+
using Xunit;
4+
5+
namespace Microsoft.Data.SqlClient.Tests
6+
{
7+
public class SqlNotificationRequestTest
8+
{
9+
[Fact]
10+
public void SetOptions_OutOfRangeValue_Throws()
11+
{
12+
SqlNotificationRequest sqlNotification = new();
13+
string outOfRangeValue = new string('a', ushort.MaxValue + 1);
14+
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.Options = outOfRangeValue);
15+
Assert.Null(ex.InnerException);
16+
Assert.NotNull(ex.ParamName);
17+
Assert.True(ex.ParamName.IndexOf("Options", StringComparison.OrdinalIgnoreCase) != -1);
18+
}
19+
20+
[Fact]
21+
public void SetUserData_OutOfRangeValue_Throws()
22+
{
23+
SqlNotificationRequest sqlNotification = new();
24+
string outOfRangeValue = new string('a', ushort.MaxValue + 1);
25+
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.UserData = outOfRangeValue);
26+
Assert.Null(ex.InnerException);
27+
Assert.NotNull(ex.ParamName);
28+
Assert.True(ex.ParamName.IndexOf("UserData", StringComparison.OrdinalIgnoreCase) != -1);
29+
}
30+
31+
[Fact]
32+
public void SetTimeout_OutOfRangeValue_Throws()
33+
{
34+
SqlNotificationRequest sqlNotification = new();
35+
int outOfRangeValue = -1;
36+
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.Timeout = outOfRangeValue);
37+
Assert.Null(ex.InnerException);
38+
Assert.NotNull(ex.ParamName);
39+
Assert.True(ex.ParamName.IndexOf("Timeout", StringComparison.OrdinalIgnoreCase) != -1);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)