Skip to content

Commit fe79b3d

Browse files
lcheunglcicheenamalhotraJohnny Pham
authored
Test - Add tests for code coverage part2 (#1384)
* Add tests for SqlCommandBuilder * Add missing throw for invalid SqlDbType for a SqlMetaData constructor * Add more ctor tests for SqlMetaData * Add tests to SqlMetaData and increase code coverage to 78% * Add tests to SqlMetaData to increase code coverge to 92.8% * Add tests to SqlDependency to increase code coverage to 75% * Update src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.cs Co-authored-by: Cheena Malhotra <[email protected]> * remove unnecessary asserts Co-authored-by: Cheena Malhotra <[email protected]> Co-authored-by: Johnny Pham <[email protected]>
1 parent d1deadd commit fe79b3d

File tree

5 files changed

+1200
-2
lines changed

5 files changed

+1200
-2
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ int sortOrdinal
428428
Construct(name, dbType, userDefinedType, string.Empty, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
429429
break;
430430
default:
431-
SQL.InvalidSqlDbTypeForConstructor(dbType);
432-
break;
431+
throw SQL.InvalidSqlDbTypeForConstructor(dbType);
433432
}
434433
}
435434

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandBuilderTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Data;
78
using System.Data.Common;
9+
using System.Reflection;
10+
using System.Threading;
811
using Xunit;
912

1013
namespace Microsoft.Data.SqlClient.Tests
@@ -64,6 +67,8 @@ public void CatalogSeparator()
6467
{
6568
SqlCommandBuilder cb = new SqlCommandBuilder();
6669
Assert.Equal(".", cb.CatalogSeparator);
70+
cb.CatalogSeparator = ".";
71+
Assert.Equal(".", cb.CatalogSeparator);
6772
}
6873

6974
[Theory]
@@ -124,6 +129,23 @@ public void ConflictOption_Value_Invalid()
124129
Assert.Equal(ConflictOption.CompareRowVersion, cb.ConflictOption);
125130
}
126131

132+
[Fact]
133+
public void DataAdapter()
134+
{
135+
SqlCommandBuilder cb = new SqlCommandBuilder();
136+
Assert.Null(cb.DataAdapter);
137+
138+
cb.DataAdapter = new SqlDataAdapter();
139+
Assert.NotNull(cb.DataAdapter);
140+
}
141+
142+
[Theory]
143+
[MemberData(nameof(SqlTestCommands))]
144+
public void DeriveParameters_Throws(Type ex, SqlCommand command)
145+
{
146+
Assert.Throws(ex, () => SqlCommandBuilder.DeriveParameters(command));
147+
}
148+
127149
[Fact]
128150
public void QuoteIdentifier()
129151
{
@@ -323,5 +345,19 @@ public void SchemaSeparator_Value_Invalid(string separator)
323345
Assert.Null(ex.ParamName);
324346
}
325347
}
348+
349+
#region member data
350+
public static IEnumerable<object[]> SqlTestCommands =>
351+
new List<object[]>
352+
{
353+
new object[] { typeof(ArgumentNullException), null },
354+
/* TODO: may need a MOQ class for DbCommand to override the DeriveParameters to throw these exceptions
355+
new object[] { typeof(OutOfMemoryException), new SqlCommand() },
356+
new object[] { typeof(StackOverflowException), new SqlCommand() },
357+
new object[] { typeof(ThreadAbortException), new SqlCommand() },
358+
new object[] { typeof(Exception), new SqlCommand() }
359+
*/
360+
};
361+
#endregion
326362
}
327363
}

0 commit comments

Comments
 (0)