Skip to content

Commit

Permalink
Test - Add tests for code coverage part2 (#1384)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 18, 2021
1 parent d1deadd commit fe79b3d
Show file tree
Hide file tree
Showing 5 changed files with 1,200 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ int sortOrdinal
Construct(name, dbType, userDefinedType, string.Empty, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
break;
default:
SQL.InvalidSqlDbTypeForConstructor(dbType);
break;
throw SQL.InvalidSqlDbTypeForConstructor(dbType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Reflection;
using System.Threading;
using Xunit;

namespace Microsoft.Data.SqlClient.Tests
Expand Down Expand Up @@ -64,6 +67,8 @@ public void CatalogSeparator()
{
SqlCommandBuilder cb = new SqlCommandBuilder();
Assert.Equal(".", cb.CatalogSeparator);
cb.CatalogSeparator = ".";
Assert.Equal(".", cb.CatalogSeparator);
}

[Theory]
Expand Down Expand Up @@ -124,6 +129,23 @@ public void ConflictOption_Value_Invalid()
Assert.Equal(ConflictOption.CompareRowVersion, cb.ConflictOption);
}

[Fact]
public void DataAdapter()
{
SqlCommandBuilder cb = new SqlCommandBuilder();
Assert.Null(cb.DataAdapter);

cb.DataAdapter = new SqlDataAdapter();
Assert.NotNull(cb.DataAdapter);
}

[Theory]
[MemberData(nameof(SqlTestCommands))]
public void DeriveParameters_Throws(Type ex, SqlCommand command)
{
Assert.Throws(ex, () => SqlCommandBuilder.DeriveParameters(command));
}

[Fact]
public void QuoteIdentifier()
{
Expand Down Expand Up @@ -323,5 +345,19 @@ public void SchemaSeparator_Value_Invalid(string separator)
Assert.Null(ex.ParamName);
}
}

#region member data
public static IEnumerable<object[]> SqlTestCommands =>
new List<object[]>
{
new object[] { typeof(ArgumentNullException), null },
/* TODO: may need a MOQ class for DbCommand to override the DeriveParameters to throw these exceptions
new object[] { typeof(OutOfMemoryException), new SqlCommand() },
new object[] { typeof(StackOverflowException), new SqlCommand() },
new object[] { typeof(ThreadAbortException), new SqlCommand() },
new object[] { typeof(Exception), new SqlCommand() }
*/
};
#endregion
}
}
Loading

0 comments on commit fe79b3d

Please sign in to comment.