Skip to content

Commit

Permalink
Tests | Add test to SqlNotificationRequest to address code coverage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcheunglci authored Oct 25, 2021
1 parent 5bf73f1 commit 27c56af
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="SqlDataRecordTest.cs" />
<Compile Include="SqlExceptionTest.cs" />
<Compile Include="SqlFacetAttributeTest.cs" />
<Compile Include="SqlNotificationRequestTest.cs" />
<Compile Include="SqlParameterTest.cs" />
<Compile Include="SqlClientFactoryTest.cs" />
<Compile Include="SqlErrorCollectionTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Microsoft.Data.Sql;
using Xunit;

namespace Microsoft.Data.SqlClient.Tests
{
public class SqlNotificationRequestTest
{
[Fact]
public void SetOptions_OutOfRangeValue_Throws()
{
SqlNotificationRequest sqlNotification = new();
string outOfRangeValue = new string('a', ushort.MaxValue + 1);
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.Options = outOfRangeValue);
Assert.Null(ex.InnerException);
Assert.NotNull(ex.ParamName);
Assert.True(ex.ParamName.IndexOf("Options", StringComparison.OrdinalIgnoreCase) != -1);
}

[Fact]
public void SetUserData_OutOfRangeValue_Throws()
{
SqlNotificationRequest sqlNotification = new();
string outOfRangeValue = new string('a', ushort.MaxValue + 1);
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.UserData = outOfRangeValue);
Assert.Null(ex.InnerException);
Assert.NotNull(ex.ParamName);
Assert.True(ex.ParamName.IndexOf("UserData", StringComparison.OrdinalIgnoreCase) != -1);
}

[Fact]
public void SetTimeout_OutOfRangeValue_Throws()
{
SqlNotificationRequest sqlNotification = new();
int outOfRangeValue = -1;
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(() => sqlNotification.Timeout = outOfRangeValue);
Assert.Null(ex.InnerException);
Assert.NotNull(ex.ParamName);
Assert.True(ex.ParamName.IndexOf("Timeout", StringComparison.OrdinalIgnoreCase) != -1);
}
}
}

0 comments on commit 27c56af

Please sign in to comment.